All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/fair: Null terminate buffer when updating tunable_scaling
@ 2021-09-27 11:46 Mel Gorman
  2021-09-27 16:50 ` Vincent Guittot
  2021-10-01 12:10 ` [tip: sched/urgent] " tip-bot2 for Mel Gorman
  0 siblings, 2 replies; 3+ messages in thread
From: Mel Gorman @ 2021-09-27 11:46 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Mike Galbraith, Ingo Molnar, Valentin Schneider, Vincent Guittot, LKML

This patch null-terminates the temporary buffer in sched_scaling_write()
so kstrtouint() does not return failure and checks the value is valid.

Before
$ cat /sys/kernel/debug/sched/tunable_scaling
1
$ echo 0 > /sys/kernel/debug/sched/tunable_scaling
-bash: echo: write error: Invalid argument
$ cat /sys/kernel/debug/sched/tunable_scaling
1

After
$ cat /sys/kernel/debug/sched/tunable_scaling
1
$ echo 0 > /sys/kernel/debug/sched/tunable_scaling
$ cat /sys/kernel/debug/sched/tunable_scaling
0
$ echo 3 > /sys/kernel/debug/sched/tunable_scaling
-bash: echo: write error: Invalid argument

Fixes: 8a99b6833c88 ("sched: Move SCHED_DEBUG sysctl to debugfs")
Signed-off-by: Mel Gorman <mgorman@techsingularity.net>
---
 kernel/sched/debug.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 49716228efb4..17a653b67006 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -173,16 +173,22 @@ static ssize_t sched_scaling_write(struct file *filp, const char __user *ubuf,
 				   size_t cnt, loff_t *ppos)
 {
 	char buf[16];
+	unsigned int scaling;
 
 	if (cnt > 15)
 		cnt = 15;
 
 	if (copy_from_user(&buf, ubuf, cnt))
 		return -EFAULT;
+	buf[cnt] = '\0';
 
-	if (kstrtouint(buf, 10, &sysctl_sched_tunable_scaling))
+	if (kstrtouint(buf, 10, &scaling))
 		return -EINVAL;
 
+	if (scaling >= SCHED_TUNABLESCALING_END)
+		return -EINVAL;
+
+	sysctl_sched_tunable_scaling = scaling;
 	if (sched_update_scaling())
 		return -EINVAL;
 

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

* Re: [PATCH] sched/fair: Null terminate buffer when updating tunable_scaling
  2021-09-27 11:46 [PATCH] sched/fair: Null terminate buffer when updating tunable_scaling Mel Gorman
@ 2021-09-27 16:50 ` Vincent Guittot
  2021-10-01 12:10 ` [tip: sched/urgent] " tip-bot2 for Mel Gorman
  1 sibling, 0 replies; 3+ messages in thread
From: Vincent Guittot @ 2021-09-27 16:50 UTC (permalink / raw)
  To: Mel Gorman
  Cc: Peter Zijlstra, Mike Galbraith, Ingo Molnar, Valentin Schneider, LKML

On Mon, 27 Sept 2021 at 13:46, Mel Gorman <mgorman@techsingularity.net> wrote:
>
> This patch null-terminates the temporary buffer in sched_scaling_write()
> so kstrtouint() does not return failure and checks the value is valid.
>
> Before
> $ cat /sys/kernel/debug/sched/tunable_scaling
> 1
> $ echo 0 > /sys/kernel/debug/sched/tunable_scaling
> -bash: echo: write error: Invalid argument
> $ cat /sys/kernel/debug/sched/tunable_scaling
> 1
>
> After
> $ cat /sys/kernel/debug/sched/tunable_scaling
> 1
> $ echo 0 > /sys/kernel/debug/sched/tunable_scaling
> $ cat /sys/kernel/debug/sched/tunable_scaling
> 0
> $ echo 3 > /sys/kernel/debug/sched/tunable_scaling
> -bash: echo: write error: Invalid argument
>
> Fixes: 8a99b6833c88 ("sched: Move SCHED_DEBUG sysctl to debugfs")
> Signed-off-by: Mel Gorman <mgorman@techsingularity.net>

Acked-by: Vincent Guittot <vincent.guittot@linaro.org>

> ---
>  kernel/sched/debug.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
> index 49716228efb4..17a653b67006 100644
> --- a/kernel/sched/debug.c
> +++ b/kernel/sched/debug.c
> @@ -173,16 +173,22 @@ static ssize_t sched_scaling_write(struct file *filp, const char __user *ubuf,
>                                    size_t cnt, loff_t *ppos)
>  {
>         char buf[16];
> +       unsigned int scaling;
>
>         if (cnt > 15)
>                 cnt = 15;
>
>         if (copy_from_user(&buf, ubuf, cnt))
>                 return -EFAULT;
> +       buf[cnt] = '\0';
>
> -       if (kstrtouint(buf, 10, &sysctl_sched_tunable_scaling))
> +       if (kstrtouint(buf, 10, &scaling))
>                 return -EINVAL;
>
> +       if (scaling >= SCHED_TUNABLESCALING_END)
> +               return -EINVAL;
> +
> +       sysctl_sched_tunable_scaling = scaling;
>         if (sched_update_scaling())
>                 return -EINVAL;
>

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

* [tip: sched/urgent] sched/fair: Null terminate buffer when updating tunable_scaling
  2021-09-27 11:46 [PATCH] sched/fair: Null terminate buffer when updating tunable_scaling Mel Gorman
  2021-09-27 16:50 ` Vincent Guittot
@ 2021-10-01 12:10 ` tip-bot2 for Mel Gorman
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Mel Gorman @ 2021-10-01 12:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Mel Gorman, Peter Zijlstra (Intel), Vincent Guittot, x86, linux-kernel

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     703066188f63d66cc6b9d678e5b5ef1213c5938e
Gitweb:        https://git.kernel.org/tip/703066188f63d66cc6b9d678e5b5ef1213c5938e
Author:        Mel Gorman <mgorman@techsingularity.net>
AuthorDate:    Mon, 27 Sep 2021 12:46:35 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 01 Oct 2021 13:57:57 +02:00

sched/fair: Null terminate buffer when updating tunable_scaling

This patch null-terminates the temporary buffer in sched_scaling_write()
so kstrtouint() does not return failure and checks the value is valid.

Before:
  $ cat /sys/kernel/debug/sched/tunable_scaling
  1
  $ echo 0 > /sys/kernel/debug/sched/tunable_scaling
  -bash: echo: write error: Invalid argument
  $ cat /sys/kernel/debug/sched/tunable_scaling
  1

After:
  $ cat /sys/kernel/debug/sched/tunable_scaling
  1
  $ echo 0 > /sys/kernel/debug/sched/tunable_scaling
  $ cat /sys/kernel/debug/sched/tunable_scaling
  0
  $ echo 3 > /sys/kernel/debug/sched/tunable_scaling
  -bash: echo: write error: Invalid argument

Fixes: 8a99b6833c88 ("sched: Move SCHED_DEBUG sysctl to debugfs")
Signed-off-by: Mel Gorman <mgorman@techsingularity.net>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Vincent Guittot <vincent.guittot@linaro.org>
Link: https://lore.kernel.org/r/20210927114635.GH3959@techsingularity.net
---
 kernel/sched/debug.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 4971622..17a653b 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -173,16 +173,22 @@ static ssize_t sched_scaling_write(struct file *filp, const char __user *ubuf,
 				   size_t cnt, loff_t *ppos)
 {
 	char buf[16];
+	unsigned int scaling;
 
 	if (cnt > 15)
 		cnt = 15;
 
 	if (copy_from_user(&buf, ubuf, cnt))
 		return -EFAULT;
+	buf[cnt] = '\0';
 
-	if (kstrtouint(buf, 10, &sysctl_sched_tunable_scaling))
+	if (kstrtouint(buf, 10, &scaling))
 		return -EINVAL;
 
+	if (scaling >= SCHED_TUNABLESCALING_END)
+		return -EINVAL;
+
+	sysctl_sched_tunable_scaling = scaling;
 	if (sched_update_scaling())
 		return -EINVAL;
 

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

end of thread, other threads:[~2021-10-01 12:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27 11:46 [PATCH] sched/fair: Null terminate buffer when updating tunable_scaling Mel Gorman
2021-09-27 16:50 ` Vincent Guittot
2021-10-01 12:10 ` [tip: sched/urgent] " tip-bot2 for Mel Gorman

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.