From: Florian Weimer <fweimer@redhat.com>
To: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH] nptl: Use SA_RESTART for SIGCANCEL handler
Date: Fri, 18 Jun 2021 13:38:26 +0200 [thread overview]
Message-ID: <878s37qu6l.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20210617125241.1415287-1-adhemerval.zanella@linaro.org> (Adhemerval Zanella via Libc-alpha's message of "Thu, 17 Jun 2021 09:52:41 -0300")
* Adhemerval Zanella via Libc-alpha:
> The usage of signals to implementation pthread cancellation is an
> implementation detail and should not be visible through cancellation
> entrypoints.
>
> However now that pthread_cancel always send the SIGCANCEL, some
> entrypoint might be interruptable and return EINTR to the caller
> (for instance on sem_wait).
>
> Using SA_RESTART hides this, since the cancellation handler should
> either act uppon cancellation (if asynchronous cancellation is enable)
> or ignore the cancellation internal signal.
I think this still needs a NEWS entry because there have been kernel
bugs in this area (e.g. in CIFS).
> Checked on x86_64-linux-gnu and i686-linux-gnu.
> ---
> nptl/pthread_cancel.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c
> index 0698cd2046..cc25ff21f3 100644
> --- a/nptl/pthread_cancel.c
> +++ b/nptl/pthread_cancel.c
> @@ -72,7 +72,11 @@ __pthread_cancel (pthread_t th)
> {
> struct sigaction sa;
> sa.sa_sigaction = sigcancel_handler;
> - sa.sa_flags = SA_SIGINFO;
> + /* The signal handle should be non-interruptible to avoid the risk of
> + spurious EINTR caused by SIGCANCEL sent to process or if
> + pthread_cancel() is called while cancellation is disabled in the
> + target thread. */
> + sa.sa_flags = SA_SIGINFO | SA_RESTART;
> __sigemptyset (&sa.sa_mask);
> __libc_sigaction (SIGCANCEL, &sa, NULL);
> atomic_store_relaxed (&init_sigcancel, 1);
I really don't feel comfortable reviewing this. However I think it is
still consistent with the (buggy) SYSCALL_CANCEL implementation:
int sc_cancel_oldtype = LIBC_CANCEL_ASYNC (); \
sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__); \
LIBC_CANCEL_RESET (sc_cancel_oldtype); \
We temporary enable async cancellation, in which case we unwind through
the signal handler if canceled. We do not rely on a EINTR error return
from the system call and a cancellation check outside of the signal
handler. So adding SA_RESTART should really be okay.
Thanks,
Florian
next prev parent reply other threads:[~2021-06-18 11:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-17 12:52 Adhemerval Zanella
2021-06-17 13:03 ` Andreas Schwab
2021-06-17 13:04 ` Adhemerval Zanella
2021-06-18 11:38 ` Florian Weimer [this message]
2021-06-22 18:30 ` Adhemerval Zanella
2021-06-22 18:33 ` Florian Weimer
2021-06-22 18:50 ` Adhemerval Zanella
2021-06-22 18:52 ` Florian Weimer
2021-06-22 19:50 ` Adhemerval Zanella
2021-06-22 19:51 ` Florian Weimer
2021-06-22 19:58 ` Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878s37qu6l.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).