hurd: fix restarting reauth_dtable on signal

While inside the critical section, RPCs would not be restarted, so we
have to handle EINTR errors.
This commit is contained in:
Samuel Thibault 2023-11-21 00:55:54 +01:00
parent 49b308a26e
commit dd858522bf

View file

@ -289,6 +289,7 @@ reauth_dtable (void)
{ {
int i; int i;
retry:
HURD_CRITICAL_BEGIN; HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_dtable_lock); __mutex_lock (&_hurd_dtable_lock);
@ -296,6 +297,7 @@ reauth_dtable (void)
{ {
struct hurd_fd *const d = _hurd_dtable[i]; struct hurd_fd *const d = _hurd_dtable[i];
mach_port_t new, newctty, ref; mach_port_t new, newctty, ref;
error_t err = 0;
if (d == NULL) if (d == NULL)
/* Nothing to do for an unused descriptor cell. */ /* Nothing to do for an unused descriptor cell. */
@ -308,23 +310,23 @@ reauth_dtable (void)
/* Reauthenticate the descriptor's port. */ /* Reauthenticate the descriptor's port. */
if (d->port.port != MACH_PORT_NULL if (d->port.port != MACH_PORT_NULL
&& ! __io_reauthenticate (d->port.port, && ! (err = __io_reauthenticate (d->port.port,
ref, MACH_MSG_TYPE_MAKE_SEND) ref, MACH_MSG_TYPE_MAKE_SEND))
&& ! __USEPORT (AUTH, __auth_user_authenticate && ! (err = __USEPORT (AUTH, __auth_user_authenticate
(port, (port,
ref, MACH_MSG_TYPE_MAKE_SEND, ref, MACH_MSG_TYPE_MAKE_SEND,
&new))) &new))))
{ {
/* Replace the port in the descriptor cell /* Replace the port in the descriptor cell
with the newly reauthenticated port. */ with the newly reauthenticated port. */
if (d->ctty.port != MACH_PORT_NULL if (d->ctty.port != MACH_PORT_NULL
&& ! __io_reauthenticate (d->ctty.port, && ! (err = __io_reauthenticate (d->ctty.port,
ref, MACH_MSG_TYPE_MAKE_SEND) ref, MACH_MSG_TYPE_MAKE_SEND))
&& ! __USEPORT (AUTH, __auth_user_authenticate && ! (err = __USEPORT (AUTH, __auth_user_authenticate
(port, (port,
ref, MACH_MSG_TYPE_MAKE_SEND, ref, MACH_MSG_TYPE_MAKE_SEND,
&newctty))) &newctty))))
_hurd_port_set (&d->ctty, newctty); _hurd_port_set (&d->ctty, newctty);
_hurd_port_locked_set (&d->port, new); _hurd_port_locked_set (&d->port, new);
@ -334,6 +336,15 @@ reauth_dtable (void)
__spin_unlock (&d->port.lock); __spin_unlock (&d->port.lock);
__mach_port_destroy (__mach_task_self (), ref); __mach_port_destroy (__mach_task_self (), ref);
if (err == EINTR)
{
/* Got a signal while inside an RPC of the critical section,
retry again */
__mutex_unlock (&_hurd_dtable_lock);
HURD_CRITICAL_UNLOCK;
goto retry;
}
} }
__mutex_unlock (&_hurd_dtable_lock); __mutex_unlock (&_hurd_dtable_lock);