From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752026AbeANThR (ORCPT + 1 other); Sun, 14 Jan 2018 14:37:17 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:38298 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751759AbeANThQ (ORCPT ); Sun, 14 Jan 2018 14:37:16 -0500 Date: Sun, 14 Jan 2018 20:37:14 +0100 (CET) From: Thomas Gleixner To: "Max R. P. Grossmann" cc: linux-kernel@vger.kernel.org, john.stultz@linaro.org Subject: Re: [PATCH] time: POSIX CPU timers: Ensure that variable is initialized In-Reply-To: <20180108190157.10048-1-m@max.pm> Message-ID: References: <20180108190157.10048-1-m@max.pm> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: 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 > --- > 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 > >