[PATCH v2 14/18] lib/test_lockup: fix kernel pointer check for separate address spaces
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>, Christoph Hellwig <hch@xxxxxx>, linux-arch@xxxxxxxxxxxxxxx, linux-mm@xxxxxxxxx, linux-api@xxxxxxxxxxxxxxx, arnd@xxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, viro@xxxxxxxxxxxxxxxxxx
- Subject: [PATCH v2 14/18] lib/test_lockup: fix kernel pointer check for separate address spaces
- From: Arnd Bergmann <arnd@xxxxxxxxxx>
- Date: Wed, 16 Feb 2022 14:13:28 +0100
- Cc: linux@xxxxxxxxxxxxxxx, will@xxxxxxxxxx, guoren@xxxxxxxxxx, bcain@xxxxxxxxxxxxxx, geert@xxxxxxxxxxxxxx, monstr@xxxxxxxxx, tsbogend@xxxxxxxxxxxxxxxx, nickhu@xxxxxxxxxxxxx, green.hu@xxxxxxxxx, dinguyen@xxxxxxxxxx, shorne@xxxxxxxxx, deller@xxxxxx, mpe@xxxxxxxxxxxxxx, peterz@xxxxxxxxxxxxx, mingo@xxxxxxxxxx, mark.rutland@xxxxxxx, hca@xxxxxxxxxxxxx, dalias@xxxxxxxx, davem@xxxxxxxxxxxxx, richard@xxxxxx, x86@xxxxxxxxxx, jcmvbkbc@xxxxxxxxx, ebiederm@xxxxxxxxxxxx, akpm@xxxxxxxxxxxxxxxxxxxx, ardb@xxxxxxxxxx, linux-alpha@xxxxxxxxxxxxxxx, linux-snps-arc@xxxxxxxxxxxxxxxxxxx, linux-csky@xxxxxxxxxxxxxxx, linux-hexagon@xxxxxxxxxxxxxxx, linux-ia64@xxxxxxxxxxxxxxx, linux-m68k@xxxxxxxxxxxxxxx, linux-mips@xxxxxxxxxxxxxxx, openrisc@xxxxxxxxxxxxxxxxxxxx, linux-parisc@xxxxxxxxxxxxxxx, linuxppc-dev@xxxxxxxxxxxxxxxx, linux-riscv@xxxxxxxxxxxxxxxxxxx, linux-s390@xxxxxxxxxxxxxxx, linux-sh@xxxxxxxxxxxxxxx, sparclinux@xxxxxxxxxxxxxxx, linux-um@xxxxxxxxxxxxxxxxxxx, linux-xtensa@xxxxxxxxxxxxxxxx
- In-reply-to: <20220216131332.1489939-1-arnd@kernel.org>
- References: <20220216131332.1489939-1-arnd@kernel.org>
From: Arnd Bergmann <arnd@xxxxxxxx>
test_kernel_ptr() uses access_ok() to figure out if a given address
points to user space instead of kernel space. However on architectures
that set CONFIG_ALTERNATE_USER_ADDRESS_SPACE, a pointer can be valid
for both, and the check always fails because access_ok() returns true.
Make the check for user space pointers conditional on the type of
address space layout.
Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
---
lib/test_lockup.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/lib/test_lockup.c b/lib/test_lockup.c
index 6a0f329a794a..c3fd87d6c2dd 100644
--- a/lib/test_lockup.c
+++ b/lib/test_lockup.c
@@ -417,9 +417,14 @@ static bool test_kernel_ptr(unsigned long addr, int size)
return false;
/* should be at least readable kernel address */
- if (access_ok((void __user *)ptr, 1) ||
- access_ok((void __user *)ptr + size - 1, 1) ||
- get_kernel_nofault(buf, ptr) ||
+ if (!IS_ENABLED(CONFIG_ALTERNATE_USER_ADDRESS_SPACE) &&
+ (access_ok((void __user *)ptr, 1) ||
+ access_ok((void __user *)ptr + size - 1, 1))) {
+ pr_err("user space ptr invalid in kernel: %#lx\n", addr);
+ return true;
+ }
+
+ if (get_kernel_nofault(buf, ptr) ||
get_kernel_nofault(buf, ptr + size - 1)) {
pr_err("invalid kernel ptr: %#lx\n", addr);
return true;
--
2.29.2
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]