Skip to content

Commit 8c860ed

Browse files
keeshansendc
authored andcommitted
x86/uaccess: Fix missed zeroing of ia32 u64 get_user() range checking
When reworking the range checking for get_user(), the get_user_8() case on 32-bit wasn't zeroing the high register. (The jump to bad_get_user_8 was accidentally dropped.) Restore the correct error handling destination (and rename the jump to using the expected ".L" prefix). While here, switch to using a named argument ("size") for the call template ("%c4" to "%c[size]") as already used in the other call templates in this file. Found after moving the usercopy selftests to KUnit: # usercopy_test_invalid: EXPECTATION FAILED at lib/usercopy_kunit.c:278 Expected val_u64 == 0, but val_u64 == -60129542144 (0xfffffff200000000) Closes: https://lore.kernel.org/all/CABVgOSn=tb=Lj9SxHuT4_9MTjjKVxsq-ikdXC4kGHO4CfKVmGQ@mail.gmail.com Fixes: b19b74b ("x86/mm: Rework address range check in get_user() and put_user()") Reported-by: David Gow <[email protected]> Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Kirill A. Shutemov <[email protected]> Reviewed-by: Qiuxu Zhuo <[email protected]> Tested-by: David Gow <[email protected]> Link: https://lore.kernel.org/all/20240610210213.work.143-kees%40kernel.org
1 parent c625dab commit 8c860ed

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

arch/x86/include/asm/uaccess.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ extern int __get_user_bad(void);
7878
int __ret_gu; \
7979
register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
8080
__chk_user_ptr(ptr); \
81-
asm volatile("call __" #fn "_%c4" \
81+
asm volatile("call __" #fn "_%c[size]" \
8282
: "=a" (__ret_gu), "=r" (__val_gu), \
8383
ASM_CALL_CONSTRAINT \
84-
: "0" (ptr), "i" (sizeof(*(ptr)))); \
84+
: "0" (ptr), [size] "i" (sizeof(*(ptr)))); \
8585
instrument_get_user(__val_gu); \
8686
(x) = (__force __typeof__(*(ptr))) __val_gu; \
8787
__builtin_expect(__ret_gu, 0); \

arch/x86/lib/getuser.S

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@
4444
or %rdx, %rax
4545
.else
4646
cmp $TASK_SIZE_MAX-\size+1, %eax
47+
.if \size != 8
4748
jae .Lbad_get_user
49+
.else
50+
jae .Lbad_get_user_8
51+
.endif
4852
sbb %edx, %edx /* array_index_mask_nospec() */
4953
and %edx, %eax
5054
.endif
@@ -154,7 +158,7 @@ SYM_CODE_END(__get_user_handle_exception)
154158
#ifdef CONFIG_X86_32
155159
SYM_CODE_START_LOCAL(__get_user_8_handle_exception)
156160
ASM_CLAC
157-
bad_get_user_8:
161+
.Lbad_get_user_8:
158162
xor %edx,%edx
159163
xor %ecx,%ecx
160164
mov $(-EFAULT),%_ASM_AX

0 commit comments

Comments
 (0)