Skip to content

Commit 9a50dca

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
ubsan, x86: Annotate and allow __ubsan_handle_shift_out_of_bounds() in uaccess regions
The new check_zeroed_user() function uses variable shifts inside of a user_access_begin()/user_access_end() section and that results in GCC emitting __ubsan_handle_shift_out_of_bounds() calls, even though through value range analysis it would be able to see that the UB in question is impossible. Annotate and whitelist this UBSAN function; continued use of user_access_begin()/user_access_end() will undoubtedly result in further uses of function. Reported-by: Randy Dunlap <[email protected]> Tested-by: Randy Dunlap <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Randy Dunlap <[email protected]> Acked-by: Christian Brauner <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephen Rothwell <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Fixes: f5a1a53 ("lib: introduce copy_struct_from_user() helper") Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 0f42c1a commit 9a50dca

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/ubsan.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,10 @@ void __ubsan_handle_shift_out_of_bounds(struct shift_out_of_bounds_data *data,
374374
struct type_descriptor *lhs_type = data->lhs_type;
375375
char rhs_str[VALUE_LENGTH];
376376
char lhs_str[VALUE_LENGTH];
377+
unsigned long ua_flags = user_access_save();
377378

378379
if (suppress_report(&data->location))
379-
return;
380+
goto out;
380381

381382
ubsan_prologue(&data->location, &flags);
382383

@@ -402,6 +403,8 @@ void __ubsan_handle_shift_out_of_bounds(struct shift_out_of_bounds_data *data,
402403
lhs_type->type_name);
403404

404405
ubsan_epilogue(&flags);
406+
out:
407+
user_access_restore(ua_flags);
405408
}
406409
EXPORT_SYMBOL(__ubsan_handle_shift_out_of_bounds);
407410

tools/objtool/check.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ static const char *uaccess_safe_builtin[] = {
481481
"ubsan_type_mismatch_common",
482482
"__ubsan_handle_type_mismatch",
483483
"__ubsan_handle_type_mismatch_v1",
484+
"__ubsan_handle_shift_out_of_bounds",
484485
/* misc */
485486
"csum_partial_copy_generic",
486487
"__memcpy_mcsafe",

0 commit comments

Comments
 (0)