From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752518AbdGGIjt (ORCPT ); Fri, 7 Jul 2017 04:39:49 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:18963 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751707AbdGGIjr (ORCPT ); Fri, 7 Jul 2017 04:39:47 -0400 Date: Fri, 7 Jul 2017 11:39:33 +0300 From: Dan Carpenter To: "Luis R. Rodriguez" Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH 1/3] lib/test_kmod: tidy up bounds checking Message-ID: <20170707083933.2mgnpqafhspbwu7h@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: NeoMutt/20170113 (1.7.2) X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is technically a bug where we don't test for negatives in test_dev_config_update_uint_sync(). "new" is long and UINT_MAX is unsigned int so on 64 bit systems negatives are allowed. In the next test I removed the UINT_MAX comparison because "max" is already an unsigned int so we already know that "new" can't be larger than UINT_MAX. On the third test, I just flipped the tests around so we consistently test the lower bound before the upper bound. Signed-off-by: Dan Carpenter diff --git a/lib/test_kmod.c b/lib/test_kmod.c index 6c1d678bcf8b..8797400b8bda 100644 --- a/lib/test_kmod.c +++ b/lib/test_kmod.c @@ -887,7 +887,7 @@ static int test_dev_config_update_uint_sync(struct kmod_test_device *test_dev, if (ret) return ret; - if (new > UINT_MAX) + if (new < 0 || new > UINT_MAX) return -EINVAL; mutex_lock(&test_dev->config_mutex); @@ -924,7 +924,7 @@ static int test_dev_config_update_uint_range(struct kmod_test_device *test_dev, if (ret) return ret; - if (new < min || new > max || new > UINT_MAX) + if (new < min || new > max) return -EINVAL; mutex_lock(&test_dev->config_mutex); @@ -946,7 +946,7 @@ static int test_dev_config_update_int(struct kmod_test_device *test_dev, if (ret) return ret; - if (new > INT_MAX || new < INT_MIN) + if (new < INT_MIN || new > INT_MAX) return -EINVAL; mutex_lock(&test_dev->config_mutex);