All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: "Luis R. Rodriguez" <mcgrof@kernel.org>
Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH] lib/test_kmod: Fix an integer overflow test
Date: Mon, 22 Jan 2018 10:27:54 +0000	[thread overview]
Message-ID: <20180122102754.GD23912@mwanda> (raw)

The main problem is that the parentheses are in the wrong place and the
unlikely() call returns either 0 or 1 so it's never less than zero.  The
other problem is that signed integer overflows like "INT_MAX + 1" are
undefined behavior.

Fixes: d9c6a72d6fa2 ("kmod: add test driver to stress test the module loader")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/lib/test_kmod.c b/lib/test_kmod.c
index e372b97eee13..30fd6d9e5361 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 = INT_MAX) {
 		pr_err("reached limit of number of test devices\n");
 		goto out;
 	}

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: "Luis R. Rodriguez" <mcgrof@kernel.org>
Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH] lib/test_kmod: Fix an integer overflow test
Date: Mon, 22 Jan 2018 13:27:54 +0300	[thread overview]
Message-ID: <20180122102754.GD23912@mwanda> (raw)

The main problem is that the parentheses are in the wrong place and the
unlikely() call returns either 0 or 1 so it's never less than zero.  The
other problem is that signed integer overflows like "INT_MAX + 1" are
undefined behavior.

Fixes: d9c6a72d6fa2 ("kmod: add test driver to stress test the module loader")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/lib/test_kmod.c b/lib/test_kmod.c
index e372b97eee13..30fd6d9e5361 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 == INT_MAX) {
 		pr_err("reached limit of number of test devices\n");
 		goto out;
 	}

             reply	other threads:[~2018-01-22 10:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-22 10:27 Dan Carpenter [this message]
2018-01-22 10:27 ` [PATCH] lib/test_kmod: Fix an integer overflow test Dan Carpenter
2018-02-24  2:59 ` [Cocci] " Luis R. Rodriguez
2018-02-24  2:59   ` Luis R. Rodriguez
2018-02-24  2:59   ` Luis R. Rodriguez
2018-02-24  8:45   ` [Cocci] " Dan Carpenter
2018-02-24  8:45     ` Dan Carpenter
2018-02-24  8:45     ` Dan Carpenter
2018-02-24 22:06     ` [Cocci] " Luis R. Rodriguez
2018-02-24 22:06       ` Luis R. Rodriguez
2018-02-24 22:06       ` Luis R. Rodriguez
2018-02-24 23:34       ` [Cocci] " Dan Carpenter
2018-02-24 23:34         ` Dan Carpenter
2018-02-24 23:34         ` Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180122102754.GD23912@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.