Skip to contentSkip to conversation

test_kmod: fix bug which allows negative values on two config options

PATCH New [email protected] 1 participant 1 message Aug 10, 2017

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 5/21 test_kmod: fix bug which allows negative values on two config options

From: "Luis R. Rodriguez" <[email protected]>
Subject: test_kmod: fix bug which allows negative values on two config options

Parsing with kstrtol() enables values to be negative, and we failed to check for negative values when parsing with either test_dev_config_update_uint_sync() or test_dev_config_update_uint_range().

test_dev_config_update_uint_range() has a minimum check though so an issue is not present there. test_dev_config_update_uint_sync() is only used for the number of threads to use (config_num_threads_store()), and indeed this would fail with an attempt for a large allocation.

Although the issue is only present in practice with the first fix both by using kstrtoul() instead of kstrtol().

Fixes 39258f448d71 ("kmod: add test driver to stress test the module loader")
Cc Colin Ian King <[email protected]>
Cc David Binderman <[email protected]>
Cc Dmitry Torokhov <[email protected]>
Cc Eric W. Biederman <[email protected]>
Cc Jessica Yu <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Kees Cook <[email protected]>
Cc Michal Marek <[email protected]>
Cc Miroslav Benes <[email protected]>
Cc Petr Mladek <[email protected]>
Cc Rusty Russell <[email protected]>
Cc Shuah Khan <[email protected]>

---

 lib/test_kmod.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
lib/test_kmod.c renamed from lib/test_kmod.c~test_kmod-fix-bug-which-allows-negative-values-on-two-config-options +4 -4
diff -puN lib/test_kmod.c~test_kmod-fix-bug-which-allows-negative-values-on-two-config-options lib/test_kmod.c
@@ -880,10 +880,10 @@ static int test_dev_config_update_uint_s
 					    int (*test_sync)(struct kmod_test_device *test_dev))
 {
 	int ret;
-	long new;
+	unsigned long new;
 	unsigned int old_val;
 
-	ret = kstrtol(buf, 10, &new);
+	ret = kstrtoul(buf, 10, &new);
 	if (ret)
 		return ret;
 
@@ -918,9 +918,9 @@ static int test_dev_config_update_uint_r
 					     unsigned int max)
 {
 	int ret;
-	long new;
+	unsigned long new;
 
-	ret = kstrtol(buf, 10, &new);
+	ret = kstrtoul(buf, 10, &new);
 	if (ret)
 		return ret;
 

_