diff options
author | Hoeun Ryu <hoeun.ryu@gmail.com> | 2017-02-12 01:13:33 -0500 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2017-02-16 19:34:59 -0500 |
commit | 4fbfeb8bd684d564bddeff1e3723d3d9f99aa5de (patch) | |
tree | acd71c212dec8ad0f3117b33c5c37ff9e68b1183 /lib/test_user_copy.c | |
parent | 0c744ea4f77d72b3dcebb7a8f2684633ec79be88 (diff) |
usercopy: add testcases to check zeroing on failure
During usercopy the destination buffer will be zeroed if copy_from_user()
or get_user() fails. This patch adds testcases for it. The destination
buffer is set with non-zero value before illegal copy_from_user() or
get_user() is executed and the buffer is compared to zero after usercopy
is done.
Signed-off-by: Hoeun Ryu <hoeun.ryu@gmail.com>
[kees: clarified commit log, dropped second kmalloc]
Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'lib/test_user_copy.c')
-rw-r--r-- | lib/test_user_copy.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/test_user_copy.c b/lib/test_user_copy.c index 0ecef3e4690e..0f86c67d87db 100644 --- a/lib/test_user_copy.c +++ b/lib/test_user_copy.c | |||
@@ -69,20 +69,30 @@ static int __init test_user_copy_init(void) | |||
69 | "legitimate put_user failed"); | 69 | "legitimate put_user failed"); |
70 | 70 | ||
71 | /* Invalid usage: none of these should succeed. */ | 71 | /* Invalid usage: none of these should succeed. */ |
72 | memset(kmem, 0x5a, PAGE_SIZE); | ||
73 | memset(kmem + PAGE_SIZE, 0, PAGE_SIZE); | ||
72 | ret |= test(!copy_from_user(kmem, (char __user *)(kmem + PAGE_SIZE), | 74 | ret |= test(!copy_from_user(kmem, (char __user *)(kmem + PAGE_SIZE), |
73 | PAGE_SIZE), | 75 | PAGE_SIZE), |
74 | "illegal all-kernel copy_from_user passed"); | 76 | "illegal all-kernel copy_from_user passed"); |
77 | ret |= test(memcmp(kmem + PAGE_SIZE, kmem, PAGE_SIZE), | ||
78 | "zeroing failure for illegal all-kernel copy_from_user"); | ||
79 | memset(bad_usermem, 0x5A, PAGE_SIZE); | ||
75 | ret |= test(!copy_from_user(bad_usermem, (char __user *)kmem, | 80 | ret |= test(!copy_from_user(bad_usermem, (char __user *)kmem, |
76 | PAGE_SIZE), | 81 | PAGE_SIZE), |
77 | "illegal reversed copy_from_user passed"); | 82 | "illegal reversed copy_from_user passed"); |
83 | ret |= test(memcmp(kmem + PAGE_SIZE, bad_usermem, PAGE_SIZE), | ||
84 | "zeroing failure for illegal reversed copy_from_user"); | ||
78 | ret |= test(!copy_to_user((char __user *)kmem, kmem + PAGE_SIZE, | 85 | ret |= test(!copy_to_user((char __user *)kmem, kmem + PAGE_SIZE, |
79 | PAGE_SIZE), | 86 | PAGE_SIZE), |
80 | "illegal all-kernel copy_to_user passed"); | 87 | "illegal all-kernel copy_to_user passed"); |
81 | ret |= test(!copy_to_user((char __user *)kmem, bad_usermem, | 88 | ret |= test(!copy_to_user((char __user *)kmem, bad_usermem, |
82 | PAGE_SIZE), | 89 | PAGE_SIZE), |
83 | "illegal reversed copy_to_user passed"); | 90 | "illegal reversed copy_to_user passed"); |
91 | memset(kmem, 0x5a, PAGE_SIZE); | ||
84 | ret |= test(!get_user(value, (unsigned long __user *)kmem), | 92 | ret |= test(!get_user(value, (unsigned long __user *)kmem), |
85 | "illegal get_user passed"); | 93 | "illegal get_user passed"); |
94 | ret |= test(memcmp(kmem + PAGE_SIZE, kmem, sizeof(value)), | ||
95 | "zeroing failure for illegal get_user"); | ||
86 | ret |= test(!put_user(value, (unsigned long __user *)kmem), | 96 | ret |= test(!put_user(value, (unsigned long __user *)kmem), |
87 | "illegal put_user passed"); | 97 | "illegal put_user passed"); |
88 | 98 | ||