diff options
| author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-10-27 19:33:13 +0100 | 
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-10-27 19:33:13 +0100 | 
| commit | c2a552197106b45d0d801d5b8a6be47563a700df (patch) | |
| tree | 61d42c1887b843170874bfec3cacc45211ed916a /lib/test_user_copy.c | |
| parent | 9905f32aefbe3d9cb2d24c3bd9c882397eaf3842 (diff) | |
| parent | d6d5df1db6e9d7f8f76d2911707f7d5877251b02 (diff) | |
Merge 5.4-rc5 into tty-next
We want the tty/serial fix in here as well.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'lib/test_user_copy.c')
| -rw-r--r-- | lib/test_user_copy.c | 37 | 
1 files changed, 28 insertions, 9 deletions
diff --git a/lib/test_user_copy.c b/lib/test_user_copy.c index e365ace06538..5ff04d8fe971 100644 --- a/lib/test_user_copy.c +++ b/lib/test_user_copy.c @@ -47,18 +47,35 @@ static bool is_zeroed(void *from, size_t size)  static int test_check_nonzero_user(char *kmem, char __user *umem, size_t size)  {  	int ret = 0; -	size_t start, end, i; -	size_t zero_start = size / 4; -	size_t zero_end = size - zero_start; +	size_t start, end, i, zero_start, zero_end; + +	if (test(size < 2 * PAGE_SIZE, "buffer too small")) +		return -EINVAL; + +	/* +	 * We want to cross a page boundary to exercise the code more +	 * effectively. We also don't want to make the size we scan too large, +	 * otherwise the test can take a long time and cause soft lockups. So +	 * scan a 1024 byte region across the page boundary. +	 */ +	size = 1024; +	start = PAGE_SIZE - (size / 2); + +	kmem += start; +	umem += start; + +	zero_start = size / 4; +	zero_end = size - zero_start;  	/* -	 * We conduct a series of check_nonzero_user() tests on a block of memory -	 * with the following byte-pattern (trying every possible [start,end] -	 * pair): +	 * We conduct a series of check_nonzero_user() tests on a block of +	 * memory with the following byte-pattern (trying every possible +	 * [start,end] pair):  	 *  	 *   [ 00 ff 00 ff ... 00 00 00 00 ... ff 00 ff 00 ]  	 * -	 * And we verify that check_nonzero_user() acts identically to memchr_inv(). +	 * And we verify that check_nonzero_user() acts identically to +	 * memchr_inv().  	 */  	memset(kmem, 0x0, size); @@ -93,11 +110,13 @@ static int test_copy_struct_from_user(char *kmem, char __user *umem,  	size_t ksize, usize;  	umem_src = kmalloc(size, GFP_KERNEL); -	if ((ret |= test(umem_src == NULL, "kmalloc failed"))) +	ret = test(umem_src == NULL, "kmalloc failed"); +	if (ret)  		goto out_free;  	expected = kmalloc(size, GFP_KERNEL); -	if ((ret |= test(expected == NULL, "kmalloc failed"))) +	ret = test(expected == NULL, "kmalloc failed"); +	if (ret)  		goto out_free;  	/* Fill umem with a fixed byte pattern. */  | 
