Skip to content

Commit f418ddd

Browse files
mpeChristian Brauner
authored andcommitted
usercopy: Avoid soft lockups in test_check_nonzero_user()
On a machine with a 64K PAGE_SIZE, the nested for loops in test_check_nonzero_user() can lead to soft lockups, eg: watchdog: BUG: soft lockup - CPU#4 stuck for 22s! [modprobe:611] Modules linked in: test_user_copy(+) vmx_crypto gf128mul crc32c_vpmsum virtio_balloon ip_tables x_tables autofs4 CPU: 4 PID: 611 Comm: modprobe Tainted: G L 5.4.0-rc1-gcc-8.2.0-00001-gf5a1a536fa14-dirty #1151 ... NIP __might_sleep+0x20/0xc0 LR __might_fault+0x40/0x60 Call Trace: check_zeroed_user+0x12c/0x200 test_user_copy_init+0x67c/0x1210 [test_user_copy] do_one_initcall+0x60/0x340 do_init_module+0x7c/0x2f0 load_module+0x2d94/0x30e0 __do_sys_finit_module+0xc8/0x150 system_call+0x5c/0x68 Even with a 4K PAGE_SIZE the test takes multiple seconds. Instead tweak it to only scan a 1024 byte region, but make it cross the page boundary. Fixes: f5a1a53 ("lib: introduce copy_struct_from_user() helper") Suggested-by: Aleksa Sarai <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Reviewed-by: Aleksa Sarai <[email protected]> Acked-by: Christian Brauner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent c90012a commit f418ddd

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

lib/test_user_copy.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,25 @@ static bool is_zeroed(void *from, size_t size)
4747
static int test_check_nonzero_user(char *kmem, char __user *umem, size_t size)
4848
{
4949
int ret = 0;
50-
size_t start, end, i;
51-
size_t zero_start = size / 4;
52-
size_t zero_end = size - zero_start;
50+
size_t start, end, i, zero_start, zero_end;
51+
52+
if (test(size < 2 * PAGE_SIZE, "buffer too small"))
53+
return -EINVAL;
54+
55+
/*
56+
* We want to cross a page boundary to exercise the code more
57+
* effectively. We also don't want to make the size we scan too large,
58+
* otherwise the test can take a long time and cause soft lockups. So
59+
* scan a 1024 byte region across the page boundary.
60+
*/
61+
size = 1024;
62+
start = PAGE_SIZE - (size / 2);
63+
64+
kmem += start;
65+
umem += start;
66+
67+
zero_start = size / 4;
68+
zero_end = size - zero_start;
5369

5470
/*
5571
* We conduct a series of check_nonzero_user() tests on a block of

0 commit comments

Comments
 (0)