Skip to content

Commit ac68b1b

Browse files
mcgroftorvalds
authored andcommitted
lib/test_kmod.c: fix limit check on number of test devices created
As reported by Dan the parentheses is in the wrong place, and since unlikely() call returns either 0 or 1 it's never less than zero. The second issue is that signed integer overflows like "INT_MAX + 1" are undefined behavior. Since num_test_devs represents the number of devices, we want to stop prior to hitting the max, and not rely on the wrap arround at all. So just cap at num_test_devs + 1, prior to assigning a new device. Link: http://lkml.kernel.org/r/20180224030046.24238-1-mcgrof@kernel.org Fixes: d9c6a72 ("kmod: add test driver to stress test the module loader") Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org> Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0627be7 commit ac68b1b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/test_kmod.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ static struct kmod_test_device *register_test_dev_kmod(void)
11411141
mutex_lock(&reg_dev_mutex);
11421142

11431143
/* int should suffice for number of devices, test for wrap */
1144-
if (unlikely(num_test_devs + 1) < 0) {
1144+
if (num_test_devs + 1 == INT_MAX) {
11451145
pr_err("reached limit of number of test devices\n");
11461146
goto out;
11471147
}

0 commit comments

Comments
 (0)