hurd: '_hurd_raise_signal' checks signal number is valid

Message ID 20201013211657.1869-1-ludo@gnu.org
State Superseded, archived
Headers
Series hurd: '_hurd_raise_signal' checks signal number is valid |

Commit Message

Ludovic Courtès Oct. 13, 2020, 9:16 p.m. UTC
  Previously, 'pthread_kill (pthread_self (), -1)' would wrongfully
succeed:

  https://lists.gnu.org/archive/html/guix-devel/2020-10/msg00152.html

Reported-by: Jan Nieuwenhuizen <janneke@gnu.org>
---
 hurd/hurd-raise.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Jessica Clarke Oct. 13, 2020, 9:20 p.m. UTC | #1
On 13 Oct 2020, at 22:16, Ludovic Courtès <ludo@gnu.org> wrote:
> 
> Previously, 'pthread_kill (pthread_self (), -1)' would wrongfully
> succeed:
> 
>  https://lists.gnu.org/archive/html/guix-devel/2020-10/msg00152.html
> 
> Reported-by: Jan Nieuwenhuizen <janneke@gnu.org>
> ---
> hurd/hurd-raise.c | 3 +++
> 1 file changed, 3 insertions(+)
> 
> diff --git a/hurd/hurd-raise.c b/hurd/hurd-raise.c
> index d53fd417d2..58b4ffcc83 100644
> --- a/hurd/hurd-raise.c
> +++ b/hurd/hurd-raise.c
> @@ -28,6 +28,9 @@ int
> _hurd_raise_signal (struct hurd_sigstate *ss,
> 		    int signo, const struct hurd_signal_detail *detail)
> {
> +  if (signo < 1 || signo >= _NSIG)
> +    return EINVAL;
> +

From pthread_kill(3):

    If sig is 0, then no signal is sent, but error checking is still performed.

I interpret that as meaning it validates thread but ignores sig.

Jess
  
Samuel Thibault Oct. 14, 2020, 10:43 a.m. UTC | #2
Hello,

Jessica Clarke, le mar. 13 oct. 2020 22:20:15 +0100, a ecrit:
> On 13 Oct 2020, at 22:16, Ludovic Courtès <ludo@gnu.org> wrote:
> > Previously, 'pthread_kill (pthread_self (), -1)' would wrongfully
> > succeed:
> > 
> >  https://lists.gnu.org/archive/html/guix-devel/2020-10/msg00152.html

> > --- a/hurd/hurd-raise.c
> > +++ b/hurd/hurd-raise.c
> > @@ -28,6 +28,9 @@ int
> > _hurd_raise_signal (struct hurd_sigstate *ss,
> > 		    int signo, const struct hurd_signal_detail *detail)
> > {
> > +  if (signo < 1 || signo >= _NSIG)
> > +    return EINVAL;
> > +
> 
> From pthread_kill(3):
> 
>     If sig is 0, then no signal is sent, but error checking is still performed.
> 
> I interpret that as meaning it validates thread but ignores sig.

__pthread_kill actually already check for sig == 0, _hurd_raise_signal
is really not supposed to be called with sig == 0.

But thanks for making sure we don't miss that case :)

Samuel
  
Andreas Schwab Oct. 14, 2020, 10:54 a.m. UTC | #3
https://sourceware.org/git/?p=glibc.git;a=commit;h=785ec62dbd

Andreas.
  
Ludovic Courtès Oct. 14, 2020, 4:55 p.m. UTC | #4
Andreas Schwab <schwab@linux-m68k.org> skribis:

> https://sourceware.org/git/?p=glibc.git;a=commit;h=785ec62dbd

Thanks, I guess I was looking at a stale checkout, apologies!

Ludo’.
  

Patch

diff --git a/hurd/hurd-raise.c b/hurd/hurd-raise.c
index d53fd417d2..58b4ffcc83 100644
--- a/hurd/hurd-raise.c
+++ b/hurd/hurd-raise.c
@@ -28,6 +28,9 @@  int
 _hurd_raise_signal (struct hurd_sigstate *ss,
 		    int signo, const struct hurd_signal_detail *detail)
 {
+  if (signo < 1 || signo >= _NSIG)
+    return EINVAL;
+
   if (ss == NULL)
     {
       ss = _hurd_self_sigstate ();