diff mbox series

stdlib: fix arc4random fallback to /dev/urandom (BZ 31612)

Message ID 20240506181906.1798367-1-adhemerval.zanella@linaro.org
State Accepted
Commit 184b9e530e6326e668709826903b6d30dc6cac3f
Headers show
Series stdlib: fix arc4random fallback to /dev/urandom (BZ 31612) | expand

Commit Message

Adhemerval Zanella May 6, 2024, 6:19 p.m. UTC
The __getrandom_nocancel used by __arc4random_buf uses
INLINE_SYSCALL_CALL (which returns -1/errno) and the loop checks for
the return value instead of errno to fallback to /dev/urandom.

The malloc code now uses __getrandom_nocancel_nostatus, which uses
INTERNAL_SYSCALL_CALL, so there is no need to use the variant that does
not set errno (BZ#29624).

Checked on x86_64-linux-gnu.
---
 stdlib/arc4random.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Adhemerval Zanella May 20, 2024, 4:47 p.m. UTC | #1
Ping.

On 06/05/24 15:19, Adhemerval Zanella wrote:
> The __getrandom_nocancel used by __arc4random_buf uses
> INLINE_SYSCALL_CALL (which returns -1/errno) and the loop checks for
> the return value instead of errno to fallback to /dev/urandom.
> 
> The malloc code now uses __getrandom_nocancel_nostatus, which uses
> INTERNAL_SYSCALL_CALL, so there is no need to use the variant that does
> not set errno (BZ#29624).
> 
> Checked on x86_64-linux-gnu.
> ---
>  stdlib/arc4random.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/stdlib/arc4random.c b/stdlib/arc4random.c
> index 3ae8fc1302..7818cb9cf6 100644
> --- a/stdlib/arc4random.c
> +++ b/stdlib/arc4random.c
> @@ -51,7 +51,7 @@ __arc4random_buf (void *p, size_t n)
>  	  n -= l;
>  	  continue; /* Interrupted by a signal; keep going.  */
>  	}
> -      else if (l == -ENOSYS)
> +      else if (l < 0 && errno == ENOSYS)
>  	break; /* No syscall, so fallback to /dev/urandom.  */
>        arc4random_getrandom_failure ();
>      }
Adhemerval Zanella July 8, 2024, 11:40 a.m. UTC | #2
Ping, I really want this small fix on 2.40.

On 06/05/24 15:19, Adhemerval Zanella wrote:
> The __getrandom_nocancel used by __arc4random_buf uses
> INLINE_SYSCALL_CALL (which returns -1/errno) and the loop checks for
> the return value instead of errno to fallback to /dev/urandom.
> 
> The malloc code now uses __getrandom_nocancel_nostatus, which uses
> INTERNAL_SYSCALL_CALL, so there is no need to use the variant that does
> not set errno (BZ#29624).
> 
> Checked on x86_64-linux-gnu.
> ---
>  stdlib/arc4random.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/stdlib/arc4random.c b/stdlib/arc4random.c
> index 3ae8fc1302..7818cb9cf6 100644
> --- a/stdlib/arc4random.c
> +++ b/stdlib/arc4random.c
> @@ -51,7 +51,7 @@ __arc4random_buf (void *p, size_t n)
>  	  n -= l;
>  	  continue; /* Interrupted by a signal; keep going.  */
>  	}
> -      else if (l == -ENOSYS)
> +      else if (l < 0 && errno == ENOSYS)
>  	break; /* No syscall, so fallback to /dev/urandom.  */
>        arc4random_getrandom_failure ();
>      }
Xi Ruoyao July 8, 2024, 11:57 a.m. UTC | #3
On Mon, 2024-07-08 at 08:40 -0300, Adhemerval Zanella Netto wrote:
> Ping, I really want this small fix on 2.40.

Reviewed-by: Xi Ruoyao <xry111@xry111.site> # as the fool who introduced the bug

> On 06/05/24 15:19, Adhemerval Zanella wrote:
> > The __getrandom_nocancel used by __arc4random_buf uses
> > INLINE_SYSCALL_CALL (which returns -1/errno) and the loop checks for
> > the return value instead of errno to fallback to /dev/urandom.
> > 
> > The malloc code now uses __getrandom_nocancel_nostatus, which uses
> > INTERNAL_SYSCALL_CALL, so there is no need to use the variant that
> > does
> > not set errno (BZ#29624).
> > 
> > Checked on x86_64-linux-gnu.
> > ---
> >  stdlib/arc4random.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/stdlib/arc4random.c b/stdlib/arc4random.c
> > index 3ae8fc1302..7818cb9cf6 100644
> > --- a/stdlib/arc4random.c
> > +++ b/stdlib/arc4random.c
> > @@ -51,7 +51,7 @@ __arc4random_buf (void *p, size_t n)
> >  	  n -= l;
> >  	  continue; /* Interrupted by a signal; keep going.  */
> >  	}
> > -      else if (l == -ENOSYS)
> > +      else if (l < 0 && errno == ENOSYS)
> >  	break; /* No syscall, so fallback to /dev/urandom.  */
> >        arc4random_getrandom_failure ();
> >      }
Andreas K. Huettel July 8, 2024, 12:48 p.m. UTC | #4
OK -a

Am Montag, 8. Juli 2024, 13:40:25 CEST schrieb Adhemerval Zanella Netto:
> Ping, I really want this small fix on 2.40.
> 
> On 06/05/24 15:19, Adhemerval Zanella wrote:
> > The __getrandom_nocancel used by __arc4random_buf uses
> > INLINE_SYSCALL_CALL (which returns -1/errno) and the loop checks for
> > the return value instead of errno to fallback to /dev/urandom.
> > 
> > The malloc code now uses __getrandom_nocancel_nostatus, which uses
> > INTERNAL_SYSCALL_CALL, so there is no need to use the variant that does
> > not set errno (BZ#29624).
> > 
> > Checked on x86_64-linux-gnu.
> > ---
> >  stdlib/arc4random.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/stdlib/arc4random.c b/stdlib/arc4random.c
> > index 3ae8fc1302..7818cb9cf6 100644
> > --- a/stdlib/arc4random.c
> > +++ b/stdlib/arc4random.c
> > @@ -51,7 +51,7 @@ __arc4random_buf (void *p, size_t n)
> >  	  n -= l;
> >  	  continue; /* Interrupted by a signal; keep going.  */
> >  	}
> > -      else if (l == -ENOSYS)
> > +      else if (l < 0 && errno == ENOSYS)
> >  	break; /* No syscall, so fallback to /dev/urandom.  */
> >        arc4random_getrandom_failure ();
> >      }
>
diff mbox series

Patch

diff --git a/stdlib/arc4random.c b/stdlib/arc4random.c
index 3ae8fc1302..7818cb9cf6 100644
--- a/stdlib/arc4random.c
+++ b/stdlib/arc4random.c
@@ -51,7 +51,7 @@  __arc4random_buf (void *p, size_t n)
 	  n -= l;
 	  continue; /* Interrupted by a signal; keep going.  */
 	}
-      else if (l == -ENOSYS)
+      else if (l < 0 && errno == ENOSYS)
 	break; /* No syscall, so fallback to /dev/urandom.  */
       arc4random_getrandom_failure ();
     }