From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751968AbdHBVPZ (ORCPT ); Wed, 2 Aug 2017 17:15:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:39284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750937AbdHBVOz (ORCPT ); Wed, 2 Aug 2017 17:14:55 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D170822C95 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=mcgrof@kernel.org From: "Luis R. Rodriguez" To: akpm@linux-foundation.org Cc: dmitry.torokhov@gmail.com, keescook@chromium.org, jeyu@redhat.com, rusty@rustcorp.com.au, mmarek@suse.com, pmladek@suse.com, mbenes@suse.cz, jpoimboe@redhat.com, ebiederm@xmission.com, shuah@kernel.org, dan.carpenter@oracle.com, colin.king@canonical.com, dcb314@hotmail.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, "Luis R. Rodriguez" Subject: [PATCH 3/5] test_kmod: fix bug which allows negative values on two config options Date: Wed, 2 Aug 2017 14:14:48 -0700 Message-Id: <20170802211450.27928-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170802211450.27928-1-mcgrof@kernel.org> References: <20170802211450.27928-1-mcgrof@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(). Reported-by: Dan Carpenter Fixes: 39258f448d71 ("kmod: add test driver to stress test the module loader") Signed-off-by: Luis R. Rodriguez --- lib/test_kmod.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/test_kmod.c b/lib/test_kmod.c index 90c91541fc16..8fc0a7a19c83 100644 --- a/lib/test_kmod.c +++ b/lib/test_kmod.c @@ -880,10 +880,10 @@ static int test_dev_config_update_uint_sync(struct kmod_test_device *test_dev, 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_range(struct kmod_test_device *test_dev, unsigned int max) { int ret; - long new; + unsigned long new; - ret = kstrtol(buf, 10, &new); + ret = kstrtoul(buf, 10, &new); if (ret) return ret; -- 2.11.0