* [PATCH] sched: fix sched_setparam() policy=-1 logic
@ 2014-07-23 2:27 Daniel Bristot de Oliveira
2014-07-23 14:36 ` Peter Zijlstra
2014-07-28 8:28 ` [tip:sched/core] sched: Fix sched_setparam() policy == -1 logic tip-bot for Daniel Bristot de Oliveira
0 siblings, 2 replies; 3+ messages in thread
From: Daniel Bristot de Oliveira @ 2014-07-23 2:27 UTC (permalink / raw)
To: linux-kernel; +Cc: peterz, mingo, tglx, stable, rostedt
The scheduler uses policy=-1 to preserve the current policy state to
implement sched_setparam(). But, as (int) -1 is equals to 0xffffffff,
it's matching the if (policy & SCHED_RESET_ON_FORK) on
_sched_setscheduler(). This match changes the policy value to an
invalid value, breaking the sched_setparam() syscall.
This patch checks policy=-1 before check the SCHED_RESET_ON_FORK flag.
The following program shows the bug:
int main(void)
{
struct sched_param param = {
.sched_priority = 5,
};
sched_setscheduler(0, SCHED_FIFO, ¶m);
param.sched_priority = 1;
sched_setparam(0, ¶m);
param.sched_priority = 0;
sched_getparam(0, ¶m);
if (param.sched_priority != 1)
printf("failed priority setting (found %d instead of 1)\n",
param.sched_priority);
else
printf("priority setting fine\n");
}
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org # 3.14+
Fixes: 7479f3c9cf67 "sched: Move SCHED_RESET_ON_FORK into attr::sched_flags"
Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Daniel Bristot de Oliveira <bristot@redhat.com>
---
kernel/sched/core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index bc1638b..0acf96b 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3558,9 +3558,10 @@ static int _sched_setscheduler(struct task_struct *p, int policy,
};
/*
- * Fixup the legacy SCHED_RESET_ON_FORK hack
+ * Fixup the legacy SCHED_RESET_ON_FORK hack, except if
+ * the policy=-1 was passed by sched_setparam().
*/
- if (policy & SCHED_RESET_ON_FORK) {
+ if ((policy != -1) && (policy & SCHED_RESET_ON_FORK)) {
attr.sched_flags |= SCHED_FLAG_RESET_ON_FORK;
policy &= ~SCHED_RESET_ON_FORK;
attr.sched_policy = policy;
--
1.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] sched: fix sched_setparam() policy=-1 logic
2014-07-23 2:27 [PATCH] sched: fix sched_setparam() policy=-1 logic Daniel Bristot de Oliveira
@ 2014-07-23 14:36 ` Peter Zijlstra
2014-07-28 8:28 ` [tip:sched/core] sched: Fix sched_setparam() policy == -1 logic tip-bot for Daniel Bristot de Oliveira
1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2014-07-23 14:36 UTC (permalink / raw)
To: Daniel Bristot de Oliveira; +Cc: linux-kernel, mingo, tglx, stable, rostedt
On Tue, Jul 22, 2014 at 11:27:41PM -0300, Daniel Bristot de Oliveira wrote:
> The scheduler uses policy=-1 to preserve the current policy state to
> implement sched_setparam(). But, as (int) -1 is equals to 0xffffffff,
> it's matching the if (policy & SCHED_RESET_ON_FORK) on
> _sched_setscheduler(). This match changes the policy value to an
> invalid value, breaking the sched_setparam() syscall.
>
> This patch checks policy=-1 before check the SCHED_RESET_ON_FORK flag.
>
> The following program shows the bug:
>
> int main(void)
> {
> struct sched_param param = {
> .sched_priority = 5,
> };
>
> sched_setscheduler(0, SCHED_FIFO, ¶m);
> param.sched_priority = 1;
> sched_setparam(0, ¶m);
> param.sched_priority = 0;
> sched_getparam(0, ¶m);
> if (param.sched_priority != 1)
> printf("failed priority setting (found %d instead of 1)\n",
> param.sched_priority);
> else
> printf("priority setting fine\n");
> }
>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: stable@vger.kernel.org # 3.14+
> Fixes: 7479f3c9cf67 "sched: Move SCHED_RESET_ON_FORK into attr::sched_flags"
> Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
> Signed-off-by: Daniel Bristot de Oliveira <bristot@redhat.com>
Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip:sched/core] sched: Fix sched_setparam() policy == -1 logic
2014-07-23 2:27 [PATCH] sched: fix sched_setparam() policy=-1 logic Daniel Bristot de Oliveira
2014-07-23 14:36 ` Peter Zijlstra
@ 2014-07-28 8:28 ` tip-bot for Daniel Bristot de Oliveira
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Daniel Bristot de Oliveira @ 2014-07-28 8:28 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, hpa, mingo, torvalds, peterz, bristot, rostedt,
tglx
Commit-ID: d8d28c8f00e84a72e8bee39a85835635417bee49
Gitweb: http://git.kernel.org/tip/d8d28c8f00e84a72e8bee39a85835635417bee49
Author: Daniel Bristot de Oliveira <bristot@redhat.com>
AuthorDate: Tue, 22 Jul 2014 23:27:41 -0300
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 28 Jul 2014 10:00:08 +0200
sched: Fix sched_setparam() policy == -1 logic
The scheduler uses policy == -1 to preserve the current policy state to
implement sched_setparam(). But, as (int) -1 is equals to 0xffffffff,
it's matching the if (policy & SCHED_RESET_ON_FORK) on
_sched_setscheduler(). This match changes the policy value to an
invalid value, breaking the sched_setparam() syscall.
This patch checks policy == -1 before check the SCHED_RESET_ON_FORK flag.
The following program shows the bug:
int main(void)
{
struct sched_param param = {
.sched_priority = 5,
};
sched_setscheduler(0, SCHED_FIFO, ¶m);
param.sched_priority = 1;
sched_setparam(0, ¶m);
param.sched_priority = 0;
sched_getparam(0, ¶m);
if (param.sched_priority != 1)
printf("failed priority setting (found %d instead of 1)\n",
param.sched_priority);
else
printf("priority setting fine\n");
}
Signed-off-by: Daniel Bristot de Oliveira <bristot@redhat.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
Cc: <stable@vger.kernel.org> # 3.14+
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Fixes: 7479f3c9cf67 "sched: Move SCHED_RESET_ON_FORK into attr::sched_flags"
Link: http://lkml.kernel.org/r/9ebe0566a08dbbb3999759d3f20d6004bb2dbcfa.1406079891.git.bristot@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/sched/core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index bc1638b..0acf96b 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3558,9 +3558,10 @@ static int _sched_setscheduler(struct task_struct *p, int policy,
};
/*
- * Fixup the legacy SCHED_RESET_ON_FORK hack
+ * Fixup the legacy SCHED_RESET_ON_FORK hack, except if
+ * the policy=-1 was passed by sched_setparam().
*/
- if (policy & SCHED_RESET_ON_FORK) {
+ if ((policy != -1) && (policy & SCHED_RESET_ON_FORK)) {
attr.sched_flags |= SCHED_FLAG_RESET_ON_FORK;
policy &= ~SCHED_RESET_ON_FORK;
attr.sched_policy = policy;
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-07-28 8:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-23 2:27 [PATCH] sched: fix sched_setparam() policy=-1 logic Daniel Bristot de Oliveira
2014-07-23 14:36 ` Peter Zijlstra
2014-07-28 8:28 ` [tip:sched/core] sched: Fix sched_setparam() policy == -1 logic tip-bot for Daniel Bristot de Oliveira
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox