diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2021-03-23 22:38:54 +0000 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2021-03-23 22:40:10 +0000 |
commit | c3b287be74e12bdb15ed36e98d24fd42f8ee9122 (patch) | |
tree | 82a9f85685a35bf5b12e480ee6ed1abc24103dc8 /sysdeps/mach | |
parent | a4ea18ec6cc3f1370efab09bc18c1badbf74aa13 (diff) | |
download | glibc-c3b287be74e12bdb15ed36e98d24fd42f8ee9122.tar.gz glibc-c3b287be74e12bdb15ed36e98d24fd42f8ee9122.tar.xz glibc-c3b287be74e12bdb15ed36e98d24fd42f8ee9122.zip |
hurd: handle EINTR during critical sections
During critical sections, signal handling is deferred and thus RPCs return EINTR, even if SA_RESTART is set. We thus have to restart the whole critical section in that case. This also adds HURD_CRITICAL_UNLOCK in the cases where one wants to break the section in the middle.
Diffstat (limited to 'sysdeps/mach')
-rw-r--r-- | sysdeps/mach/hurd/faccessat.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/fork.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/getegid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/geteuid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/getgid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/getgroups.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/getresgid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/getresuid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/getuid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/group_member.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/setegid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/seteuid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/setgid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/setgroups.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/setitimer.c | 9 | ||||
-rw-r--r-- | sysdeps/mach/hurd/setregid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/setresgid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/setresuid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/setreuid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/setsid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/setuid.c | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/spawni.c | 15 |
22 files changed, 102 insertions, 2 deletions
diff --git a/sysdeps/mach/hurd/faccessat.c b/sysdeps/mach/hurd/faccessat.c index f421a531fe..07702712c5 100644 --- a/sysdeps/mach/hurd/faccessat.c +++ b/sysdeps/mach/hurd/faccessat.c @@ -127,6 +127,7 @@ __faccessat_common (int fd, const char *file, int type, int at_flags, rcrdir = rcwdir = MACH_PORT_NULL; + retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); @@ -172,6 +173,9 @@ __faccessat_common (int fd, const char *file, int type, int at_flags, __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; if (rcrdir != MACH_PORT_NULL) __mach_port_deallocate (__mach_task_self (), rcrdir); diff --git a/sysdeps/mach/hurd/fork.c b/sysdeps/mach/hurd/fork.c index 1c5299e686..92a51693e0 100644 --- a/sysdeps/mach/hurd/fork.c +++ b/sysdeps/mach/hurd/fork.c @@ -70,6 +70,7 @@ __fork (void) __run_fork_handlers (atfork_run_prepare, true); ss = _hurd_self_sigstate (); +retry: __spin_lock (&ss->critical_section_lock); #undef LOSE @@ -718,6 +719,9 @@ __fork (void) } _hurd_critical_section_unlock (ss); + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; if (!err) { diff --git a/sysdeps/mach/hurd/getegid.c b/sysdeps/mach/hurd/getegid.c index 5a3db22746..1929d749a7 100644 --- a/sysdeps/mach/hurd/getegid.c +++ b/sysdeps/mach/hurd/getegid.c @@ -27,6 +27,7 @@ __getegid (void) error_t err; gid_t egid; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); @@ -49,6 +50,9 @@ __getegid (void) __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (egid == -1 && errno == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; return egid; } diff --git a/sysdeps/mach/hurd/geteuid.c b/sysdeps/mach/hurd/geteuid.c index a7af5a9d0d..5312d6bf64 100644 --- a/sysdeps/mach/hurd/geteuid.c +++ b/sysdeps/mach/hurd/geteuid.c @@ -27,6 +27,7 @@ __geteuid (void) error_t err; uid_t euid; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); @@ -49,6 +50,9 @@ __geteuid (void) __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (euid == -1 && errno == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; return euid; } diff --git a/sysdeps/mach/hurd/getgid.c b/sysdeps/mach/hurd/getgid.c index aa13884a8f..c89e7429be 100644 --- a/sysdeps/mach/hurd/getgid.c +++ b/sysdeps/mach/hurd/getgid.c @@ -27,6 +27,7 @@ __getgid (void) error_t err; gid_t gid; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); @@ -46,6 +47,9 @@ __getgid (void) __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (gid == -1 && errno == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; return gid; } diff --git a/sysdeps/mach/hurd/getgroups.c b/sysdeps/mach/hurd/getgroups.c index 5f036f8191..6b59d4a483 100644 --- a/sysdeps/mach/hurd/getgroups.c +++ b/sysdeps/mach/hurd/getgroups.c @@ -31,6 +31,7 @@ __getgroups (int n, gid_t *gidset) if (n < 0) return __hurd_fail (EINVAL); +retry: crit = _hurd_critical_section_lock (); __mutex_lock (&_hurd_id.lock); @@ -38,6 +39,9 @@ __getgroups (int n, gid_t *gidset) { __mutex_unlock (&_hurd_id.lock); _hurd_critical_section_unlock (crit); + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; return __hurd_fail (err); } diff --git a/sysdeps/mach/hurd/getresgid.c b/sysdeps/mach/hurd/getresgid.c index 9cae591f58..52838b8b4c 100644 --- a/sysdeps/mach/hurd/getresgid.c +++ b/sysdeps/mach/hurd/getresgid.c @@ -28,6 +28,7 @@ __getresgid (gid_t *rgid, gid_t *egid, gid_t *sgid) { error_t err; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); @@ -49,6 +50,9 @@ __getresgid (gid_t *rgid, gid_t *egid, gid_t *sgid) __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; return __hurd_fail (err); } diff --git a/sysdeps/mach/hurd/getresuid.c b/sysdeps/mach/hurd/getresuid.c index 02995db6ed..732e416adc 100644 --- a/sysdeps/mach/hurd/getresuid.c +++ b/sysdeps/mach/hurd/getresuid.c @@ -28,6 +28,7 @@ __getresuid (uid_t *ruid, uid_t *euid, uid_t *suid) { error_t err; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); @@ -49,6 +50,9 @@ __getresuid (uid_t *ruid, uid_t *euid, uid_t *suid) __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; return __hurd_fail (err); } diff --git a/sysdeps/mach/hurd/getuid.c b/sysdeps/mach/hurd/getuid.c index fc4a441569..1aadb749e0 100644 --- a/sysdeps/mach/hurd/getuid.c +++ b/sysdeps/mach/hurd/getuid.c @@ -27,6 +27,7 @@ __getuid (void) error_t err; uid_t uid; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); @@ -46,6 +47,9 @@ __getuid (void) __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (uid == -1 && errno == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; return uid; } diff --git a/sysdeps/mach/hurd/group_member.c b/sysdeps/mach/hurd/group_member.c index c5256f12a6..72681a8f3b 100644 --- a/sysdeps/mach/hurd/group_member.c +++ b/sysdeps/mach/hurd/group_member.c @@ -28,6 +28,7 @@ __group_member (gid_t gid) error_t err; void *crit; +retry: crit = _hurd_critical_section_lock (); __mutex_lock (&_hurd_id.lock); @@ -45,6 +46,9 @@ __group_member (gid_t gid) __mutex_unlock (&_hurd_id.lock); _hurd_critical_section_unlock (crit); + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; if (err) __hurd_fail (err); diff --git a/sysdeps/mach/hurd/setegid.c b/sysdeps/mach/hurd/setegid.c index f0258d3af0..1396e193f2 100644 --- a/sysdeps/mach/hurd/setegid.c +++ b/sysdeps/mach/hurd/setegid.c @@ -29,6 +29,7 @@ setegid (gid_t gid) auth_t newauth; error_t err; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); err = _hurd_check_ids (); @@ -55,6 +56,9 @@ setegid (gid_t gid) } __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; if (err) return __hurd_fail (err); diff --git a/sysdeps/mach/hurd/seteuid.c b/sysdeps/mach/hurd/seteuid.c index 637015cc22..97eb22c6b7 100644 --- a/sysdeps/mach/hurd/seteuid.c +++ b/sysdeps/mach/hurd/seteuid.c @@ -29,6 +29,7 @@ seteuid (uid_t uid) auth_t newauth; error_t err; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); err = _hurd_check_ids (); @@ -55,6 +56,9 @@ seteuid (uid_t uid) } __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; if (err) return __hurd_fail (err); diff --git a/sysdeps/mach/hurd/setgid.c b/sysdeps/mach/hurd/setgid.c index 6e0672d5e8..c6a64c9423 100644 --- a/sysdeps/mach/hurd/setgid.c +++ b/sysdeps/mach/hurd/setgid.c @@ -32,6 +32,7 @@ __setgid (gid_t gid) auth_t newauth; error_t err; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); err = _hurd_check_ids (); @@ -81,6 +82,9 @@ __setgid (gid_t gid) } __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; if (err) return __hurd_fail (err); diff --git a/sysdeps/mach/hurd/setgroups.c b/sysdeps/mach/hurd/setgroups.c index fc78de3fa1..cb6b8996b9 100644 --- a/sysdeps/mach/hurd/setgroups.c +++ b/sysdeps/mach/hurd/setgroups.c @@ -34,6 +34,7 @@ setgroups (size_t n, const gid_t *groups) for (i = 0; i < n; ++i) new[i] = groups[i]; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); err = _hurd_check_ids (); @@ -50,6 +51,9 @@ setgroups (size_t n, const gid_t *groups) } __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; if (err) return __hurd_fail (err); diff --git a/sysdeps/mach/hurd/setitimer.c b/sysdeps/mach/hurd/setitimer.c index e23e79a63e..4931644db5 100644 --- a/sysdeps/mach/hurd/setitimer.c +++ b/sysdeps/mach/hurd/setitimer.c @@ -339,6 +339,7 @@ __setitimer (enum __itimer_which which, const struct itimerval *new, struct itimerval *old) { void *crit; + int ret; switch (which) { @@ -353,9 +354,15 @@ __setitimer (enum __itimer_which which, const struct itimerval *new, break; } +retry: crit = _hurd_critical_section_lock (); __spin_lock (&_hurd_itimer_lock); - return setitimer_locked (new, old, crit, 0); + ret = setitimer_locked (new, old, crit, 0); + if (ret == -1 && errno == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; + + return ret; } static void diff --git a/sysdeps/mach/hurd/setregid.c b/sysdeps/mach/hurd/setregid.c index 2fce6cf6cf..aad736e11d 100644 --- a/sysdeps/mach/hurd/setregid.c +++ b/sysdeps/mach/hurd/setregid.c @@ -28,6 +28,7 @@ __setregid (gid_t rgid, gid_t egid) auth_t newauth; error_t err; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); err = _hurd_check_ids (); @@ -82,6 +83,9 @@ __setregid (gid_t rgid, gid_t egid) } __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; if (err) return __hurd_fail (err); diff --git a/sysdeps/mach/hurd/setresgid.c b/sysdeps/mach/hurd/setresgid.c index 8ccfd93c80..64b6840cc8 100644 --- a/sysdeps/mach/hurd/setresgid.c +++ b/sysdeps/mach/hurd/setresgid.c @@ -29,6 +29,7 @@ __setresgid (gid_t rgid, gid_t egid, gid_t sgid) auth_t newauth; error_t err; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); err = _hurd_check_ids (); @@ -110,6 +111,9 @@ __setresgid (gid_t rgid, gid_t egid, gid_t sgid) } __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; if (err) return __hurd_fail (err); diff --git a/sysdeps/mach/hurd/setresuid.c b/sysdeps/mach/hurd/setresuid.c index d16db170c2..53d07cccfb 100644 --- a/sysdeps/mach/hurd/setresuid.c +++ b/sysdeps/mach/hurd/setresuid.c @@ -29,6 +29,7 @@ __setresuid (uid_t ruid, uid_t euid, uid_t suid) auth_t newauth; error_t err; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); err = _hurd_check_ids (); @@ -111,6 +112,9 @@ __setresuid (uid_t ruid, uid_t euid, uid_t suid) __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; if (err) return __hurd_fail (err); diff --git a/sysdeps/mach/hurd/setreuid.c b/sysdeps/mach/hurd/setreuid.c index 97328e1e1a..d093ed946c 100644 --- a/sysdeps/mach/hurd/setreuid.c +++ b/sysdeps/mach/hurd/setreuid.c @@ -28,6 +28,7 @@ __setreuid (uid_t ruid, uid_t euid) auth_t newauth; error_t err; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); err = _hurd_check_ids (); @@ -82,6 +83,9 @@ __setreuid (uid_t ruid, uid_t euid) } __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; if (err) return __hurd_fail (err); diff --git a/sysdeps/mach/hurd/setsid.c b/sysdeps/mach/hurd/setsid.c index 3861f8f850..698fc9cdcf 100644 --- a/sysdeps/mach/hurd/setsid.c +++ b/sysdeps/mach/hurd/setsid.c @@ -32,6 +32,7 @@ __setsid (void) error_t err; unsigned int stamp; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_dtable_lock); @@ -60,6 +61,9 @@ __setsid (void) } HURD_CRITICAL_END; + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; return err ? __hurd_fail (err) : _hurd_pgrp; } diff --git a/sysdeps/mach/hurd/setuid.c b/sysdeps/mach/hurd/setuid.c index ede3f014c4..4818357c62 100644 --- a/sysdeps/mach/hurd/setuid.c +++ b/sysdeps/mach/hurd/setuid.c @@ -32,6 +32,7 @@ __setuid (uid_t uid) auth_t newauth; error_t err; +retry: HURD_CRITICAL_BEGIN; __mutex_lock (&_hurd_id.lock); err = _hurd_check_ids (); @@ -86,6 +87,9 @@ __setuid (uid_t uid) } __mutex_unlock (&_hurd_id.lock); HURD_CRITICAL_END; + if (err == EINTR) + /* Got a signal while inside an RPC of the critical section, retry again */ + goto retry; if (err) return __hurd_fail (err); diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/spawni.c index 9bc1571c29..b5c92365f2 100644 --- a/sysdeps/mach/hurd/spawni.c +++ b/sysdeps/mach/hurd/spawni.c @@ -333,6 +333,7 @@ __spawni (pid_t *pid, const char *file, ss = _hurd_self_sigstate (); +retry: assert (! __spin_lock_locked (&ss->critical_section_lock)); __spin_lock (&ss->critical_section_lock); @@ -437,7 +438,19 @@ __spawni (pid_t *pid, const char *file, MACH_PORT_RIGHT_SEND, +1)); if (err) - goto out; + { + _hurd_critical_section_unlock (ss); + + if (err == EINTR) + { + /* Got a signal while inside an RPC of the critical section, retry again */ + __mach_port_deallocate (__mach_task_self (), auth); + auth = MACH_PORT_NULL; + goto retry; + } + + goto out; + } /* Pack up the descriptor table to give the new program. These descriptors will need to be reauthenticated below |