All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] lib/test_kmod: tidy up bounds checking
@ 2017-07-07  8:39 ` Dan Carpenter
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2017-07-07  8:39 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: linux-kernel, kernel-janitors

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 <dan.carpenter@oracle.com>

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);

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

* [PATCH 1/3] lib/test_kmod: tidy up bounds checking
@ 2017-07-07  8:39 ` Dan Carpenter
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2017-07-07  8:39 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: linux-kernel, kernel-janitors

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 <dan.carpenter@oracle.com>

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);

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

* [PATCH 2/3] lib/test_kmod: take the lock in register_test_dev_kmod()
  2017-07-07  8:39 ` Dan Carpenter
@ 2017-07-07  8:40   ` Dan Carpenter
  -1 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2017-07-07  8:40 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: linux-kernel, kernel-janitors

We accidentally just drop the lock twice instead of taking it and then
releasing it.

Fixes: 39258f448d71 ("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 8797400b8bda..093b44771197 100644
--- a/lib/test_kmod.c
+++ b/lib/test_kmod.c
@@ -1146,7 +1146,7 @@ static struct kmod_test_device *register_test_dev_kmod(void)
 	struct kmod_test_device *test_dev = NULL;
 	int ret;
 
-	mutex_unlock(&reg_dev_mutex);
+	mutex_lock(&reg_dev_mutex);
 
 	/* int should suffice for number of devices, test for wrap */
 	if (unlikely(num_test_devs + 1) < 0) {

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

* [PATCH 2/3] lib/test_kmod: take the lock in register_test_dev_kmod()
@ 2017-07-07  8:40   ` Dan Carpenter
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2017-07-07  8:40 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: linux-kernel, kernel-janitors

We accidentally just drop the lock twice instead of taking it and then
releasing it.

Fixes: 39258f448d71 ("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 8797400b8bda..093b44771197 100644
--- a/lib/test_kmod.c
+++ b/lib/test_kmod.c
@@ -1146,7 +1146,7 @@ static struct kmod_test_device *register_test_dev_kmod(void)
 	struct kmod_test_device *test_dev = NULL;
 	int ret;
 
-	mutex_unlock(&reg_dev_mutex);
+	mutex_lock(&reg_dev_mutex);
 
 	/* int should suffice for number of devices, test for wrap */
 	if (unlikely(num_test_devs + 1) < 0) {

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

* [PATCH 3/3] lib/test_kmod: fix fs module tests
  2017-07-07  8:39 ` Dan Carpenter
@ 2017-07-07  8:41   ` Dan Carpenter
  -1 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2017-07-07  8:41 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: linux-kernel, kernel-janitors

The break was in the wrong place so file system tests don't work as
intended.

Fixes: 39258f448d71 ("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 093b44771197..5a402e610237 100644
--- a/lib/test_kmod.c
+++ b/lib/test_kmod.c
@@ -746,11 +746,11 @@ static int trigger_config_run_type(struct kmod_test_device *test_dev,
 						      strlen(test_str));
 		break;
 	case TEST_KMOD_FS_TYPE:
-		break;
 		kfree_const(config->test_fs);
 		config->test_driver = NULL;
 		copied = config_copy_test_fs(config, test_str,
 					     strlen(test_str));
+		break;
 	default:
 		mutex_unlock(&test_dev->config_mutex);
 		return -EINVAL;

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

* [PATCH 3/3] lib/test_kmod: fix fs module tests
@ 2017-07-07  8:41   ` Dan Carpenter
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2017-07-07  8:41 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: linux-kernel, kernel-janitors

The break was in the wrong place so file system tests don't work as
intended.

Fixes: 39258f448d71 ("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 093b44771197..5a402e610237 100644
--- a/lib/test_kmod.c
+++ b/lib/test_kmod.c
@@ -746,11 +746,11 @@ static int trigger_config_run_type(struct kmod_test_device *test_dev,
 						      strlen(test_str));
 		break;
 	case TEST_KMOD_FS_TYPE:
-		break;
 		kfree_const(config->test_fs);
 		config->test_driver = NULL;
 		copied = config_copy_test_fs(config, test_str,
 					     strlen(test_str));
+		break;
 	default:
 		mutex_unlock(&test_dev->config_mutex);
 		return -EINVAL;

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

* Re: [PATCH 1/3] lib/test_kmod: tidy up bounds checking
  2017-07-07  8:39 ` Dan Carpenter
@ 2017-08-01 23:10   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 12+ messages in thread
From: Luis R. Rodriguez @ 2017-08-01 23:10 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Luis R. Rodriguez, linux-kernel, kernel-janitors

On Fri, Jul 07, 2017 at 11:39:33AM +0300, Dan Carpenter wrote:
> 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.

Good catch. I however prefer we instead just replace kstrtol() with
kstrtoul() in both of these cases as an atomic separate patch with
a Fixes tag. I'll do this and roll in your other patches. Below is
what I mean as one atomic fix.

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;
 
> 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.

Makes sense, will roll this in as a separate patch on your part.

> On the third test, I just flipped the tests around so we consistently
> test the lower bound before the upper bound.

And since non-functional I will also split up into another patch.

  Luis

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

* Re: [PATCH 1/3] lib/test_kmod: tidy up bounds checking
@ 2017-08-01 23:10   ` Luis R. Rodriguez
  0 siblings, 0 replies; 12+ messages in thread
From: Luis R. Rodriguez @ 2017-08-01 23:10 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Luis R. Rodriguez, linux-kernel, kernel-janitors

On Fri, Jul 07, 2017 at 11:39:33AM +0300, Dan Carpenter wrote:
> 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.

Good catch. I however prefer we instead just replace kstrtol() with
kstrtoul() in both of these cases as an atomic separate patch with
a Fixes tag. I'll do this and roll in your other patches. Below is
what I mean as one atomic fix.

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;
 
> 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.

Makes sense, will roll this in as a separate patch on your part.

> On the third test, I just flipped the tests around so we consistently
> test the lower bound before the upper bound.

And since non-functional I will also split up into another patch.

  Luis

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

* Re: [PATCH 2/3] lib/test_kmod: take the lock in register_test_dev_kmod()
  2017-07-07  8:40   ` Dan Carpenter
@ 2017-08-01 23:16     ` Luis R. Rodriguez
  -1 siblings, 0 replies; 12+ messages in thread
From: Luis R. Rodriguez @ 2017-08-01 23:16 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Luis R. Rodriguez, linux-kernel, kernel-janitors

On Fri, Jul 07, 2017 at 11:40:36AM +0300, Dan Carpenter wrote:
> We accidentally just drop the lock twice instead of taking it and then
> releasing it.
> 
> Fixes: 39258f448d71 ("kmod: add test driver to stress test the module loader")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks, queued!

  Luis

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

* Re: [PATCH 2/3] lib/test_kmod: take the lock in register_test_dev_kmod()
@ 2017-08-01 23:16     ` Luis R. Rodriguez
  0 siblings, 0 replies; 12+ messages in thread
From: Luis R. Rodriguez @ 2017-08-01 23:16 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Luis R. Rodriguez, linux-kernel, kernel-janitors

On Fri, Jul 07, 2017 at 11:40:36AM +0300, Dan Carpenter wrote:
> We accidentally just drop the lock twice instead of taking it and then
> releasing it.
> 
> Fixes: 39258f448d71 ("kmod: add test driver to stress test the module loader")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks, queued!

  Luis

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

* Re: [PATCH 3/3] lib/test_kmod: fix fs module tests
  2017-07-07  8:41   ` Dan Carpenter
@ 2017-08-01 23:19     ` Luis R. Rodriguez
  -1 siblings, 0 replies; 12+ messages in thread
From: Luis R. Rodriguez @ 2017-08-01 23:19 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Luis R. Rodriguez, linux-kernel, kernel-janitors

On Fri, Jul 07, 2017 at 11:41:17AM +0300, Dan Carpenter wrote:
> The break was in the wrong place so file system tests don't work as
> intended.

More importantly it leaked memory per test switch as well.
> 
> Fixes: 39258f448d71 ("kmod: add test driver to stress test the module loader")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks, queued!

  Luis

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

* Re: [PATCH 3/3] lib/test_kmod: fix fs module tests
@ 2017-08-01 23:19     ` Luis R. Rodriguez
  0 siblings, 0 replies; 12+ messages in thread
From: Luis R. Rodriguez @ 2017-08-01 23:19 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Luis R. Rodriguez, linux-kernel, kernel-janitors

On Fri, Jul 07, 2017 at 11:41:17AM +0300, Dan Carpenter wrote:
> The break was in the wrong place so file system tests don't work as
> intended.

More importantly it leaked memory per test switch as well.
> 
> Fixes: 39258f448d71 ("kmod: add test driver to stress test the module loader")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks, queued!

  Luis

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

end of thread, other threads:[~2017-08-01 23:19 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-07  8:39 [PATCH 1/3] lib/test_kmod: tidy up bounds checking Dan Carpenter
2017-07-07  8:39 ` Dan Carpenter
2017-07-07  8:40 ` [PATCH 2/3] lib/test_kmod: take the lock in register_test_dev_kmod() Dan Carpenter
2017-07-07  8:40   ` Dan Carpenter
2017-08-01 23:16   ` Luis R. Rodriguez
2017-08-01 23:16     ` Luis R. Rodriguez
2017-07-07  8:41 ` [PATCH 3/3] lib/test_kmod: fix fs module tests Dan Carpenter
2017-07-07  8:41   ` Dan Carpenter
2017-08-01 23:19   ` Luis R. Rodriguez
2017-08-01 23:19     ` Luis R. Rodriguez
2017-08-01 23:10 ` [PATCH 1/3] lib/test_kmod: tidy up bounds checking Luis R. Rodriguez
2017-08-01 23:10   ` Luis R. Rodriguez

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.