Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
glibc
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GNU Libc Maintainers
glibc
Commits
e42ad945
Commit
e42ad945
authored
2 years ago
by
Samuel Thibault
Browse files
Options
Downloads
Patches
Plain Diff
hurd-i386/git-readlink-fifo.diff: Fix atomicity
parent
1f659a70
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
debian/patches/hurd-i386/git-readlink-fifo.diff
+105
-30
105 additions, 30 deletions
debian/patches/hurd-i386/git-readlink-fifo.diff
with
105 additions
and
30 deletions
debian/patches/hurd-i386/git-readlink-fifo.diff
+
105
−
30
View file @
e42ad945
commit 9e5c991106cb04b489272de0ef6a7a6bcef50477
commit 9e5c991106cb04b489272de0ef6a7a6bcef50477
(origin/master, origin/HEAD)
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date: Wed Sep 14 18:52:52 2022 +0200
hurd: Fix readlink() hanging on fifo
readlink() opens the target with O_READ to be able to read the symlink
content. When the target is actually a fifo, that would hang waiting for a
writer (caught in the coreutils testsuite). We thus have to first lookup the
target without O_READ to perform io_stat and lookout for fifos, and only
after checking the symlink type, we can re-lookup with O_READ.
diff --git a/sysdeps/mach/hurd/readlink.c b/sysdeps/mach/hurd/readlink.c
index 770462714f..2d75ef7725 100644
--- a/sysdeps/mach/hurd/readlink.c
+++ b/sysdeps/mach/hurd/readlink.c
@@ -31,7 +31,7 @@
__readlink (const char *file_name, char *buf, size_t len)
file_t file;
commit 5652e12cce80825297c3e0666991deb10310343c (HEAD -> master, origin-rw/master)
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date: Thu Sep 15 21:53:57 2022 +0200
hurd: Make readlink* just reopen the file used for stat
9e5c991106cb ("hurd: Fix readlink() hanging on fifo") separated opening
the file for the stat call from opening the file for the read call. That
however opened a small window for the file to change. Better make this
atomic by reopening the file with O_READ.
Index: glibc-2.36/sysdeps/mach/hurd/readlink.c
===================================================================
--- glibc-2.36.orig/sysdeps/mach/hurd/readlink.c
+++ glibc-2.36/sysdeps/mach/hurd/readlink.c
@@ -28,30 +28,41 @@
ssize_t
__readlink (const char *file_name, char *buf, size_t len)
{
error_t err;
- file_t file;
+ file_t file_stat;
struct stat64 st;
- file = __file_name_lookup (file_name, O_READ | O_NOLINK, 0);
+ file = __file_name_lookup (file_name, O_NOLINK, 0);
if (file == MACH_PORT_NULL)
- if (file == MACH_PORT_NULL)
+ file_stat = __file_name_lookup (file_name, O_NOLINK, 0);
+ if (file_stat == MACH_PORT_NULL)
return -1;
@@ -41,6 +41,9 @@
__readlink (const char *file_name, char *buf, size_t len)
- err = __io_stat (file, &st);
+ err = __io_stat (file_stat, &st);
if (! err)
if (S_ISLNK (st.st_mode))
{
+ enum retry_type doretry;
+ char retryname[1024];
+ file_t file;
char *rbuf = buf;
+ __mach_port_deallocate (__mach_task_self (), file);
+ file = __file_name_lookup (file_name, O_READ | O_NOLINK, 0);
+
err = __io_read (file, &rbuf, &len, 0, len);
if (!err && rbuf != buf)
- err = __io_read (file, &rbuf, &len, 0, len);
- if (!err && rbuf != buf)
+ err = __dir_lookup (file_stat, "", O_READ | O_NOLINK, 0, &doretry, retryname, &file);
+ if (! err && (doretry != FS_RETRY_NORMAL || retryname[0] != '\0'))
+ err = EGRATUITOUS;
+ if (! err)
{
diff --git a/sysdeps/mach/hurd/readlinkat.c b/sysdeps/mach/hurd/readlinkat.c
index 059aad9f58..113b92b732 100644
--- a/sysdeps/mach/hurd/readlinkat.c
+++ b/sysdeps/mach/hurd/readlinkat.c
@@ -32,7 +32,7 @@
readlinkat (int fd, const char *file_name, char *buf, size_t len)
file_t file;
- memcpy (buf, rbuf, len);
- __vm_deallocate (__mach_task_self (), (vm_address_t)rbuf, len);
+ err = __io_read (file, &rbuf, &len, 0, len);
+ if (!err && rbuf != buf)
+ {
+ memcpy (buf, rbuf, len);
+ __vm_deallocate (__mach_task_self (), (vm_address_t)rbuf, len);
+ }
+
+ __mach_port_deallocate (__mach_task_self (), file);
}
}
else
err = EINVAL;
- __mach_port_deallocate (__mach_task_self (), file);
+ __mach_port_deallocate (__mach_task_self (), file_stat);
if (err)
return __hurd_fail (err);
Index: glibc-2.36/sysdeps/mach/hurd/readlinkat.c
===================================================================
--- glibc-2.36.orig/sysdeps/mach/hurd/readlinkat.c
+++ glibc-2.36/sysdeps/mach/hurd/readlinkat.c
@@ -29,30 +29,41 @@
ssize_t
readlinkat (int fd, const char *file_name, char *buf, size_t len)
{
error_t err;
- file_t file;
+ file_t file_stat;
struct stat64 st;
- file = __file_name_lookup_at (fd, 0, file_name, O_READ | O_NOLINK, 0);
+ file = __file_name_lookup_at (fd, 0, file_name, O_NOLINK, 0);
if (file == MACH_PORT_NULL)
- if (file == MACH_PORT_NULL)
+ file_stat = __file_name_lookup_at (fd, 0, file_name, O_NOLINK, 0);
+ if (file_stat == MACH_PORT_NULL)
return -1;
@@ -42,6 +42,9 @@
readlinkat (int fd, const char *file_name, char *buf, size_t len)
- err = __io_stat (file, &st);
+ err = __io_stat (file_stat, &st);
if (! err)
if (S_ISLNK (st.st_mode))
{
+ enum retry_type doretry;
+ char retryname[1024];
+ file_t file;
char *rbuf = buf;
+ __mach_port_deallocate (__mach_task_self (), file);
+ file = __file_name_lookup_at (fd, 0, file_name, O_READ | O_NOLINK, 0);
+
err = __io_read (file, &rbuf, &len, 0, len);
if (!err && rbuf != buf)
- err = __io_read (file, &rbuf, &len, 0, len);
- if (!err && rbuf != buf)
+ err = __dir_lookup (file_stat, "", O_READ | O_NOLINK, 0, &doretry, retryname, &file);
+ if (! err && (doretry != FS_RETRY_NORMAL || retryname[0] != '\0'))
+ err = EGRATUITOUS;
+ if (! err)
{
- memcpy (buf, rbuf, len);
- __vm_deallocate (__mach_task_self (), (vm_address_t)rbuf, len);
+ err = __io_read (file, &rbuf, &len, 0, len);
+ if (!err && rbuf != buf)
+ {
+ memcpy (buf, rbuf, len);
+ __vm_deallocate (__mach_task_self (), (vm_address_t)rbuf, len);
+ }
+
+ __mach_port_deallocate (__mach_task_self (), file);
}
}
else
err = EINVAL;
- __mach_port_deallocate (__mach_task_self (), file);
+ __mach_port_deallocate (__mach_task_self (), file_stat);
return err ? __hurd_fail (err) : len;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment