* [PATCH] time: POSIX CPU timers: Ensure that variable is initialized
@ 2018-01-08 19:01 Max R. P. Grossmann
2018-01-14 19:37 ` Thomas Gleixner
2018-01-14 19:55 ` [tip:timers/core] posix-cpu-timers: Make set_process_cpu_timer() more robust tip-bot for Max R. P. Grossmann
0 siblings, 2 replies; 3+ messages in thread
From: Max R. P. Grossmann @ 2018-01-08 19:01 UTC (permalink / raw)
To: linux-kernel; +Cc: tglx, john.stultz, Max R. P. Grossmann
If cpu_timer_sample_group returns -EINVAL, it will not have written into
*sample. Checking for cpu_timer_sample_group's return value precludes the
potential use of an uninitialized value of now in the following block.
Given an invalid clock_idx, the previous code could otherwise overwrite
*oldval in an undefined manner. This is now prevented. We also exploit
short-circuiting of && to sample the timer only if the result will
actually be used to update *oldval.
Signed-off-by: Max R. P. Grossmann <m@max.pm>
---
kernel/time/posix-cpu-timers.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 1f27887aa194..e54638be6e19 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -1189,9 +1189,8 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
u64 now;
WARN_ON_ONCE(clock_idx == CPUCLOCK_SCHED);
- cpu_timer_sample_group(clock_idx, tsk, &now);
- if (oldval) {
+ if (oldval && cpu_timer_sample_group(clock_idx, tsk, &now) != -EINVAL) {
/*
* We are setting itimer. The *oldval is absolute and we update
* it to be relative, *newval argument is relative and we update
--
2.15.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] time: POSIX CPU timers: Ensure that variable is initialized
2018-01-08 19:01 [PATCH] time: POSIX CPU timers: Ensure that variable is initialized Max R. P. Grossmann
@ 2018-01-14 19:37 ` Thomas Gleixner
2018-01-14 19:55 ` [tip:timers/core] posix-cpu-timers: Make set_process_cpu_timer() more robust tip-bot for Max R. P. Grossmann
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Gleixner @ 2018-01-14 19:37 UTC (permalink / raw)
To: Max R. P. Grossmann; +Cc: linux-kernel, john.stultz
On Mon, 8 Jan 2018, Max R. P. Grossmann wrote:
> If cpu_timer_sample_group returns -EINVAL, it will not have written into
> *sample. Checking for cpu_timer_sample_group's return value precludes the
> potential use of an uninitialized value of now in the following block.
> Given an invalid clock_idx, the previous code could otherwise overwrite
> *oldval in an undefined manner. This is now prevented. We also exploit
> short-circuiting of && to sample the timer only if the result will
> actually be used to update *oldval.
Sure the explanation makes sense, though you should have mentioned that
_ALL_ current users call this function with a valid clockid.
I'll amend the changelog.
> Signed-off-by: Max R. P. Grossmann <m@max.pm>
> ---
> kernel/time/posix-cpu-timers.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
> index 1f27887aa194..e54638be6e19 100644
> --- a/kernel/time/posix-cpu-timers.c
> +++ b/kernel/time/posix-cpu-timers.c
> @@ -1189,9 +1189,8 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
> u64 now;
>
> WARN_ON_ONCE(clock_idx == CPUCLOCK_SCHED);
> - cpu_timer_sample_group(clock_idx, tsk, &now);
>
> - if (oldval) {
> + if (oldval && cpu_timer_sample_group(clock_idx, tsk, &now) != -EINVAL) {
> /*
> * We are setting itimer. The *oldval is absolute and we update
> * it to be relative, *newval argument is relative and we update
> --
> 2.15.1
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread* [tip:timers/core] posix-cpu-timers: Make set_process_cpu_timer() more robust
2018-01-08 19:01 [PATCH] time: POSIX CPU timers: Ensure that variable is initialized Max R. P. Grossmann
2018-01-14 19:37 ` Thomas Gleixner
@ 2018-01-14 19:55 ` tip-bot for Max R. P. Grossmann
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Max R. P. Grossmann @ 2018-01-14 19:55 UTC (permalink / raw)
To: linux-tip-commits; +Cc: mingo, m, hpa, tglx, linux-kernel
Commit-ID: a9445e47d897054876b8f43e46dc5a3eca2b844d
Gitweb: https://git.kernel.org/tip/a9445e47d897054876b8f43e46dc5a3eca2b844d
Author: Max R. P. Grossmann <m@max.pm>
AuthorDate: Mon, 8 Jan 2018 20:01:57 +0100
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sun, 14 Jan 2018 20:50:59 +0100
posix-cpu-timers: Make set_process_cpu_timer() more robust
Because the return value of cpu_timer_sample_group() is not checked,
compilers and static checkers can legitimately warn about a potential use
of the uninitialized variable 'now'. This is not a runtime issue as all call
sites hand in valid clock ids.
Also cpu_timer_sample_group() is invoked unconditionally even when the
result is not used because *oldval is NULL.
Make the invocation conditional and check the return value.
[ tglx: Massage changelog ]
Signed-off-by: Max R. P. Grossmann <m@max.pm>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: john.stultz@linaro.org
Link: https://lkml.kernel.org/r/20180108190157.10048-1-m@max.pm
---
kernel/time/posix-cpu-timers.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index cef79ca..ec9f5da 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -1189,9 +1189,8 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
u64 now;
WARN_ON_ONCE(clock_idx == CPUCLOCK_SCHED);
- cpu_timer_sample_group(clock_idx, tsk, &now);
- if (oldval) {
+ if (oldval && cpu_timer_sample_group(clock_idx, tsk, &now) != -EINVAL) {
/*
* We are setting itimer. The *oldval is absolute and we update
* it to be relative, *newval argument is relative and we update
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-01-14 19:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-08 19:01 [PATCH] time: POSIX CPU timers: Ensure that variable is initialized Max R. P. Grossmann
2018-01-14 19:37 ` Thomas Gleixner
2018-01-14 19:55 ` [tip:timers/core] posix-cpu-timers: Make set_process_cpu_timer() more robust tip-bot for Max R. P. Grossmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox