Skip to content

Commit 59c8a02

Browse files
ramosian-gliderakpm00
authored andcommitted
x86: asm: make sure __put_user_size() evaluates pointer once
User access macros must ensure their arguments are evaluated only once if they are used more than once in the macro body. Adding instrument_put_user() to __put_user_size() resulted in double evaluation of the `ptr` argument, which led to correctness issues when performing e.g. unsafe_put_user(..., p++, ...). To fix those issues, evaluate the `ptr` argument of __put_user_size() at the beginning of the macro. Link: https://lkml.kernel.org/r/[email protected] Fixes: 888f84a ("x86: asm: instrument usercopy in get_user() and put_user()") Signed-off-by: Alexander Potapenko <[email protected]> Reported-by: youling257 <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 921757b commit 59c8a02

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

arch/x86/include/asm/uaccess.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,24 +254,25 @@ extern void __put_user_nocheck_8(void);
254254
#define __put_user_size(x, ptr, size, label) \
255255
do { \
256256
__typeof__(*(ptr)) __x = (x); /* eval x once */ \
257-
__chk_user_ptr(ptr); \
257+
__typeof__(ptr) __ptr = (ptr); /* eval ptr once */ \
258+
__chk_user_ptr(__ptr); \
258259
switch (size) { \
259260
case 1: \
260-
__put_user_goto(__x, ptr, "b", "iq", label); \
261+
__put_user_goto(__x, __ptr, "b", "iq", label); \
261262
break; \
262263
case 2: \
263-
__put_user_goto(__x, ptr, "w", "ir", label); \
264+
__put_user_goto(__x, __ptr, "w", "ir", label); \
264265
break; \
265266
case 4: \
266-
__put_user_goto(__x, ptr, "l", "ir", label); \
267+
__put_user_goto(__x, __ptr, "l", "ir", label); \
267268
break; \
268269
case 8: \
269-
__put_user_goto_u64(__x, ptr, label); \
270+
__put_user_goto_u64(__x, __ptr, label); \
270271
break; \
271272
default: \
272273
__put_user_bad(); \
273274
} \
274-
instrument_put_user(__x, ptr, size); \
275+
instrument_put_user(__x, __ptr, size); \
275276
} while (0)
276277

277278
#ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT

0 commit comments

Comments
 (0)