2017-04-19 22:24:55

by Myungho Jung

[permalink] [raw]
Subject: [PATCH] timer: fix timer_migration to accept only 0 and 1

Error is not shown by setting invalid value to timer_migration. Valid
values for timer_migration should be restricted to 0 and 1. Testcase for
this bug is ltp/runpwtests06.

Signed-off-by: Myungho Jung <[email protected]>
---
kernel/sysctl.c | 2 ++
kernel/time/timer.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 8c8714f..21343d1 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1176,6 +1176,8 @@ static struct ctl_table kern_table[] = {
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = timer_migration_handler,
+ .extra1 = &zero,
+ .extra2 = &one,
},
#endif
#ifdef CONFIG_BPF_SYSCALL
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 1dc0256..cc6b6bd 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -241,7 +241,7 @@ int timer_migration_handler(struct ctl_table *table, int write,
int ret;

mutex_lock(&mutex);
- ret = proc_dointvec(table, write, buffer, lenp, ppos);
+ ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
if (!ret && write)
timers_update_migration(false);
mutex_unlock(&mutex);
--
2.7.4


2017-04-20 12:53:31

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH] timer: fix timer_migration to accept only 0 and 1

On Wed, 19 Apr 2017, Myungho Jung wrote:

> Error is not shown by setting invalid value to timer_migration. Valid
> values for timer_migration should be restricted to 0 and 1. Testcase for
> this bug is ltp/runpwtests06.

While I agree with the change, I disagree with the changelog. Where is the bug?

The timer code checks for timer_migration != 0 resp. == 0. So as long as
the value is != 0 it's enabled, if it's 0 it is disabled.

It's a correctness issue that we treat a sysctl which is basically a
boolean as such. Ideally we'd have: proc_doboolvec() for such cases and
convert all similar sysctls over to that.

Thanks,

tglx

Subject: [tip:timers/core] timer/sysclt: Restrict timer migration sysctl values to 0 and 1

Commit-ID: b94bf594cf8ed67cdd0439e70fa939783471597a
Gitweb: http://git.kernel.org/tip/b94bf594cf8ed67cdd0439e70fa939783471597a
Author: Myungho Jung <[email protected]>
AuthorDate: Wed, 19 Apr 2017 15:24:50 -0700
Committer: Thomas Gleixner <[email protected]>
CommitDate: Thu, 20 Apr 2017 14:56:59 +0200

timer/sysclt: Restrict timer migration sysctl values to 0 and 1

timer_migration sysctl acts as a boolean switch, so the allowed values
should be restricted to 0 and 1.

Add the necessary extra fields to the sysctl table entry to enforce that.

[ tglx: Rewrote changelog ]

Signed-off-by: Myungho Jung <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Thomas Gleixner <[email protected]>

---
kernel/sysctl.c | 2 ++
kernel/time/timer.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index acf0a5a..0863769 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1176,6 +1176,8 @@ static struct ctl_table kern_table[] = {
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = timer_migration_handler,
+ .extra1 = &zero,
+ .extra2 = &one,
},
#endif
#ifdef CONFIG_BPF_SYSCALL
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 1dc0256..cc6b6bd 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -241,7 +241,7 @@ int timer_migration_handler(struct ctl_table *table, int write,
int ret;

mutex_lock(&mutex);
- ret = proc_dointvec(table, write, buffer, lenp, ppos);
+ ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
if (!ret && write)
timers_update_migration(false);
mutex_unlock(&mutex);

2017-04-20 17:36:08

by Myungho Jung

[permalink] [raw]
Subject: Re: [PATCH] timer: fix timer_migration to accept only 0 and 1

On Thu, Apr 20, 2017 at 02:53:26PM +0200, Thomas Gleixner wrote:
> On Wed, 19 Apr 2017, Myungho Jung wrote:
>
> > Error is not shown by setting invalid value to timer_migration. Valid
> > values for timer_migration should be restricted to 0 and 1. Testcase for
> > this bug is ltp/runpwtests06.
>
> While I agree with the change, I disagree with the changelog. Where is the bug?
>
> The timer code checks for timer_migration != 0 resp. == 0. So as long as
> the value is != 0 it's enabled, if it's 0 it is disabled.
>
> It's a correctness issue that we treat a sysctl which is basically a
> boolean as such. Ideally we'd have: proc_doboolvec() for such cases and
> convert all similar sysctls over to that.
>
> Thanks,
>
> tglx
I understood. I'll resubmit the patch after fixing log.

Thanks,
Myungho

2017-04-20 17:45:53

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH] timer: fix timer_migration to accept only 0 and 1

On Thu, 20 Apr 2017, Myungho Jung wrote:
> I understood. I'll resubmit the patch after fixing log.

I recommend to check your inbox first.

Thanks,

tglx

2017-04-20 18:08:21

by Myungho Jung

[permalink] [raw]
Subject: Re: [PATCH] timer: fix timer_migration to accept only 0 and 1

On Thu, Apr 20, 2017 at 07:45:49PM +0200, Thomas Gleixner wrote:
> On Thu, 20 Apr 2017, Myungho Jung wrote:
> > I understood. I'll resubmit the patch after fixing log.
>
> I recommend to check your inbox first.
>
> Thanks,
>
> tglx
Yes, I confirmed a message from tip-bot. I'll refer to it.

Thanks,
Myungho