Skip to content

Commit 2515dd6

Browse files
nickdesaulniersKAGA-KOKO
authored andcommitted
stack: Replace "o" output with "r" input constraint
"o" isn't a common asm() constraint to use; it triggers an assertion in assert-enabled builds of LLVM that it's not recognized when targeting aarch64 (though it appears to fall back to "m"). It's fixed in LLVM 13 now, but there isn't really a good reason to use "o" in particular here. To avoid causing build issues for those using assert-enabled builds of earlier LLVM versions, the constraint needs changing. Instead, if the point is to retain the __builtin_alloca(), make ptr appear to "escape" via being an input to an empty inline asm block. This is preferable anyways, since otherwise this looks like a dead store. While the use of "r" was considered in https://lore.kernel.org/lkml/202104011447.2E7F543@keescook/ it was only tested as an output (which looks like a dead store, and wasn't sufficient). Use "r" as an input constraint instead, which behaves correctly across compilers and architectures. Fixes: 39218ff ("stack: Optionally randomize kernel stack offset each syscall") Signed-off-by: Nick Desaulniers <[email protected]> Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Kees Cook <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Link: https://reviews.llvm.org/D100412 Link: https://bugs.llvm.org/show_bug.cgi?id=49956 Link: https://lore.kernel.org/r/[email protected]
1 parent 6efb943 commit 2515dd6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/linux/randomize_kstack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void *__builtin_alloca(size_t size);
3838
u32 offset = raw_cpu_read(kstack_offset); \
3939
u8 *ptr = __builtin_alloca(KSTACK_OFFSET_MAX(offset)); \
4040
/* Keep allocation even after "ptr" loses scope. */ \
41-
asm volatile("" : "=o"(*ptr) :: "memory"); \
41+
asm volatile("" :: "r"(ptr) : "memory"); \
4242
} \
4343
} while (0)
4444

0 commit comments

Comments
 (0)