Skip to content

Commit 51ff10e

Browse files
keesgregkh
authored andcommitted
usercopy: Adjust tests to deal with SMAP/PAN
commit f5f893c57e37ca730808cb2eee3820abd05e7507 upstream. Under SMAP/PAN/etc, we cannot write directly to userspace memory, so this rearranges the test bytes to get written through copy_to_user(). Additionally drops the bad copy_from_user() test that would trigger a memcpy() against userspace on failure. [arnd: the test module was added in 3.14, and this backported patch should apply cleanly on all version from 3.14 to 4.10. The original patch was in 4.11 on top of a context change I saw the bug triggered with kselftest on a 4.4.y stable kernel] Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 746d489 commit 51ff10e

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

lib/test_user_copy.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ static int __init test_user_copy_init(void)
5858
usermem = (char __user *)user_addr;
5959
bad_usermem = (char *)user_addr;
6060

61-
/* Legitimate usage: none of these should fail. */
61+
/*
62+
* Legitimate usage: none of these copies should fail.
63+
*/
6264
ret |= test(copy_from_user(kmem, usermem, PAGE_SIZE),
6365
"legitimate copy_from_user failed");
6466
ret |= test(copy_to_user(usermem, kmem, PAGE_SIZE),
@@ -68,19 +70,33 @@ static int __init test_user_copy_init(void)
6870
ret |= test(put_user(value, (unsigned long __user *)usermem),
6971
"legitimate put_user failed");
7072

71-
/* Invalid usage: none of these should succeed. */
73+
/*
74+
* Invalid usage: none of these copies should succeed.
75+
*/
76+
77+
/* Reject kernel-to-kernel copies through copy_from_user(). */
7278
ret |= test(!copy_from_user(kmem, (char __user *)(kmem + PAGE_SIZE),
7379
PAGE_SIZE),
7480
"illegal all-kernel copy_from_user passed");
81+
82+
#if 0
83+
/*
84+
* When running with SMAP/PAN/etc, this will Oops the kernel
85+
* due to the zeroing of userspace memory on failure. This needs
86+
* to be tested in LKDTM instead, since this test module does not
87+
* expect to explode.
88+
*/
7589
ret |= test(!copy_from_user(bad_usermem, (char __user *)kmem,
7690
PAGE_SIZE),
7791
"illegal reversed copy_from_user passed");
92+
#endif
7893
ret |= test(!copy_to_user((char __user *)kmem, kmem + PAGE_SIZE,
7994
PAGE_SIZE),
8095
"illegal all-kernel copy_to_user passed");
8196
ret |= test(!copy_to_user((char __user *)kmem, bad_usermem,
8297
PAGE_SIZE),
8398
"illegal reversed copy_to_user passed");
99+
84100
ret |= test(!get_user(value, (unsigned long __user *)kmem),
85101
"illegal get_user passed");
86102
ret |= test(!put_user(value, (unsigned long __user *)kmem),

0 commit comments

Comments
 (0)