mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-02 07:04:24 +00:00
lib/test_lockup: fix kernel pointer check for separate address spaces
[ Upstream commit 5a06fcb15b
]
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@arndb.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
ce93c7a9ea
commit
72df12d11e
1 changed files with 8 additions and 3 deletions
|
@ -417,9 +417,14 @@ static bool test_kernel_ptr(unsigned long addr, int size)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* should be at least readable kernel address */
|
/* should be at least readable kernel address */
|
||||||
if (access_ok((void __user *)ptr, 1) ||
|
if (!IS_ENABLED(CONFIG_ALTERNATE_USER_ADDRESS_SPACE) &&
|
||||||
access_ok((void __user *)ptr + size - 1, 1) ||
|
(access_ok((void __user *)ptr, 1) ||
|
||||||
get_kernel_nofault(buf, ptr) ||
|
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)) {
|
get_kernel_nofault(buf, ptr + size - 1)) {
|
||||||
pr_err("invalid kernel ptr: %#lx\n", addr);
|
pr_err("invalid kernel ptr: %#lx\n", addr);
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue