linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] test_kmod: fix limit check on number of test devices created
@ 2018-02-24  3:00 Luis R. Rodriguez
  2018-02-27 23:24 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Luis R. Rodriguez @ 2018-02-24  3:00 UTC (permalink / raw)
  To: akpm
  Cc: keescook, dmitry.torokhov, jeyu, rusty, mmarek, pmladek, mbenes,
	jpoimboe, linux, ebiederm, matt.redfearn, dan.carpenter,
	colin.king, danielmentz, dcb314, gregkh, torvalds, linux-kernel,
	Luis R. Rodriguez

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.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: d9c6a72d6fa2 ("kmod: add test driver to stress test the module loader")
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 lib/test_kmod.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/test_kmod.c b/lib/test_kmod.c
index e372b97eee13..0e5b7a61460b 100644
--- a/lib/test_kmod.c
+++ b/lib/test_kmod.c
@@ -1141,7 +1141,7 @@ static struct kmod_test_device *register_test_dev_kmod(void)
 	mutex_lock(&reg_dev_mutex);
 
 	/* int should suffice for number of devices, test for wrap */
-	if (unlikely(num_test_devs + 1) < 0) {
+	if (num_test_devs + 1 == INT_MAX) {
 		pr_err("reached limit of number of test devices\n");
 		goto out;
 	}
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-27 23:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-24  3:00 [PATCH] test_kmod: fix limit check on number of test devices created Luis R. Rodriguez
2018-02-27 23:24 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).