Skip to contentSkip to conversation

x86-asm-make-sure-__put_user_size-evaluates-pointer-once.patch removed from -mm tree

merged mm-hotfixes-stable Andrew Morton 1 participant 1 message Oct 28, 2022

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: x86: asm: make sure __put_user_size() evaluates pointer once
has been removed from the -mm tree. Its filename was
x86-asm-make-sure-__put_user_size-evaluates-pointer-once.patch

This patch was dropped because it was merged into the mm-hotfixes-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Alexander Potapenko <[email protected]>
Subject: x86: asm: make sure __put_user_size() evaluates pointer once
Date: Mon, 24 Oct 2022 23:21:43 +0200

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.

Fixes 888f84a6da4d ("x86: asm: instrument usercopy in get_user() and put_user()")
Cc Borislav Petkov <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>

---

arch/x86/include/asm/uaccess.h renamed from arch/x86/include/asm/uaccess.h~x86-asm-make-sure-__put_user_size-evaluates-pointer-once +7 -6
@@ -254,24 +254,25 @@ extern void __put_user_nocheck_8(void);
 #define __put_user_size(x, ptr, size, label)				\
 do {									\
 	__typeof__(*(ptr)) __x = (x); /* eval x once */			\
-	__chk_user_ptr(ptr);						\
+	__typeof__(ptr) __ptr = (ptr); /* eval ptr once */		\
+	__chk_user_ptr(__ptr);						\
 	switch (size) {							\
 	case 1:								\
-		__put_user_goto(__x, ptr, "b", "iq", label);		\
+		__put_user_goto(__x, __ptr, "b", "iq", label);		\
 		break;							\
 	case 2:								\
-		__put_user_goto(__x, ptr, "w", "ir", label);		\
+		__put_user_goto(__x, __ptr, "w", "ir", label);		\
 		break;							\
 	case 4:								\
-		__put_user_goto(__x, ptr, "l", "ir", label);		\
+		__put_user_goto(__x, __ptr, "l", "ir", label);		\
 		break;							\
 	case 8:								\
-		__put_user_goto_u64(__x, ptr, label);			\
+		__put_user_goto_u64(__x, __ptr, label);			\
 		break;							\
 	default:							\
 		__put_user_bad();					\
 	}								\
-	instrument_put_user(__x, ptr, size);				\
+	instrument_put_user(__x, __ptr, size);				\
 } while (0)
 
 #ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT

_

Patches currently in -mm which might be from [email protected] are