* [PATCH v1 1/1] lib/test_scanf: Handle n_bits == 0 in random tests
@ 2021-07-27 15:01 Andy Shevchenko
2021-07-27 15:27 ` Richard Fitzgerald
2021-07-30 10:45 ` Petr Mladek
0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2021-07-27 15:01 UTC (permalink / raw)
To: Petr Mladek, Richard Fitzgerald, linux-kernel
Cc: Steven Rostedt, Sergey Senozhatsky, Andy Shevchenko,
Rasmus Villemoes, kernel test robot
UBSAN reported (via LKP)
[ 11.021349][ T1] UBSAN: shift-out-of-bounds in lib/test_scanf.c:275:51
[ 11.022782][ T1] shift exponent 32 is too large for 32-bit type 'unsigned int'
When n_bits == 0, the shift is out of range. Switch code to use GENMASK
to handle this case.
Fixes: 50f530e176ea ("lib: test_scanf: Add tests for sscanf number conversion")
Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
lib/test_scanf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/test_scanf.c b/lib/test_scanf.c
index 84fe09eaf55e..abae88848972 100644
--- a/lib/test_scanf.c
+++ b/lib/test_scanf.c
@@ -271,7 +271,7 @@ static u32 __init next_test_random(u32 max_bits)
{
u32 n_bits = hweight32(prandom_u32_state(&rnd_state)) % (max_bits + 1);
- return prandom_u32_state(&rnd_state) & (UINT_MAX >> (32 - n_bits));
+ return prandom_u32_state(&rnd_state) & GENMASK(n_bits, 0);
}
static unsigned long long __init next_test_random_ull(void)
@@ -280,7 +280,7 @@ static unsigned long long __init next_test_random_ull(void)
u32 n_bits = (hweight32(rand1) * 3) % 64;
u64 val = (u64)prandom_u32_state(&rnd_state) * rand1;
- return val & (ULLONG_MAX >> (64 - n_bits));
+ return val & GENMASK_ULL(n_bits, 0);
}
#define random_for_type(T) \
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v1 1/1] lib/test_scanf: Handle n_bits == 0 in random tests
2021-07-27 15:01 [PATCH v1 1/1] lib/test_scanf: Handle n_bits == 0 in random tests Andy Shevchenko
@ 2021-07-27 15:27 ` Richard Fitzgerald
2021-07-30 10:45 ` Petr Mladek
1 sibling, 0 replies; 3+ messages in thread
From: Richard Fitzgerald @ 2021-07-27 15:27 UTC (permalink / raw)
To: Andy Shevchenko, Petr Mladek, linux-kernel
Cc: Steven Rostedt, Sergey Senozhatsky, Rasmus Villemoes, kernel test robot
On 27/07/2021 16:01, Andy Shevchenko wrote:
> UBSAN reported (via LKP)
>
> [ 11.021349][ T1] UBSAN: shift-out-of-bounds in lib/test_scanf.c:275:51
> [ 11.022782][ T1] shift exponent 32 is too large for 32-bit type 'unsigned int'
>
> When n_bits == 0, the shift is out of range. Switch code to use GENMASK
> to handle this case.
>
> Fixes: 50f530e176ea ("lib: test_scanf: Add tests for sscanf number conversion")
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
Reviewed-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Sorry about that. Would have been sensible to use GENMASK anyway.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1 1/1] lib/test_scanf: Handle n_bits == 0 in random tests
2021-07-27 15:01 [PATCH v1 1/1] lib/test_scanf: Handle n_bits == 0 in random tests Andy Shevchenko
2021-07-27 15:27 ` Richard Fitzgerald
@ 2021-07-30 10:45 ` Petr Mladek
1 sibling, 0 replies; 3+ messages in thread
From: Petr Mladek @ 2021-07-30 10:45 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Richard Fitzgerald, linux-kernel, Steven Rostedt,
Sergey Senozhatsky, Rasmus Villemoes, kernel test robot
On Tue 2021-07-27 18:01:32, Andy Shevchenko wrote:
> UBSAN reported (via LKP)
>
> [ 11.021349][ T1] UBSAN: shift-out-of-bounds in lib/test_scanf.c:275:51
> [ 11.022782][ T1] shift exponent 32 is too large for 32-bit type 'unsigned int'
>
> When n_bits == 0, the shift is out of range. Switch code to use GENMASK
> to handle this case.
>
> Fixes: 50f530e176ea ("lib: test_scanf: Add tests for sscanf number conversion")
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
The patch is committed in linux/printk.git, branch for-5.15.
I would send it for 4.14 if there was another urgent fix needed.
But this one does not look important enough to hurry it up alone.
Best Regards,
Petr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-30 10:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-27 15:01 [PATCH v1 1/1] lib/test_scanf: Handle n_bits == 0 in random tests Andy Shevchenko
2021-07-27 15:27 ` Richard Fitzgerald
2021-07-30 10:45 ` Petr Mladek
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.