From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x226QFtnQmIKdOSddMYWuf8ibWFCIAachrNxZ7FKnyFJkPo2t9Hr4QaV8vzazjAm5n+E9fauN ARC-Seal: i=1; a=rsa-sha256; t=1517256573; cv=none; d=google.com; s=arc-20160816; b=Rs4x6pmkwthk1jz6q5KR3Ut8MJkHDGfbjvOSBzJNZHREpkksD4mwVtrey9qh43ptnG 0kglaU3fnJeWXCOJNTsBkrgBMb5XZqm36DB9yi+ia1oEybnQFzEq/0SO3vCVCtA2UCWY a/8tY+0UjigfMmZDmKIAwfJItD/QpCnWNN2SWwzzbv8xnUyeI8xUV5iP87MmjDEFK1Jf N3nNRsle9Oq1Y8Gk9ueHfb/DpPegMBa37RgsIyA39bOgwtAndEbuoK+iQqDJCfspgKwt cOuODV1DWlRUzb9nE0WpqP6ELICAp6qcWlZU7c4AKEYek8tycgrj3egkihVTeSJI/UBH 3xQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=jjIdUR7qYBSEsw6PzJUUA13wOL/dMcvLSSqL/RpxkmI=; b=qpYQly0aWP0hJjjAg3IOqj6Oy0xf0oow8MIbA0tmPtpGK7xZTngDka3NhOMl9lvLiW dPW7LcAl2d+Y3d3HZ/4W3FORTa8kj+tCnPnzV+mzItpHGUGRto4ABBEH6dIF+z7rQWBl DKIg53kyy3vyQEcWJNP2grpdlBDYn6ktUA5p53OGEUEbOrF6wQ/CENT4lDZqAIuLIeUn lSDcl/hbClanOOfvhRdwx4Qpq5U0lYoY2oHSwCIddQAdc0vX2hW9B1MaZbZ74vi7B4ov hQEqz5DNjP4YCl1LoMXTslBnrfrz4clI7/g9G3njJaeaSyE8jcu1qsyasCOKzr9pUPwI FENA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Torvalds , Thomas Gleixner , Andrew Morton , Peter Zijlstra , Mike Galbraith Subject: [PATCH 4.4 13/74] timers: Plug locking race vs. timer migration Date: Mon, 29 Jan 2018 13:56:18 +0100 Message-Id: <20180129123848.167134415@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123847.507563674@linuxfoundation.org> References: <20180129123847.507563674@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-LABELS: =?utf-8?b?IlxcU2VudCI=?= X-GMAIL-THRID: =?utf-8?q?1590958828722614592?= X-GMAIL-MSGID: =?utf-8?q?1590958828722614592?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Gleixner commit b831275a3553c32091222ac619cfddd73a5553fb upstream. Linus noticed that lock_timer_base() lacks a READ_ONCE() for accessing the timer flags. As a consequence the compiler is allowed to reload the flags between the initial check for TIMER_MIGRATION and the following timer base computation and the spin lock of the base. While this has not been observed (yet), we need to make sure that it never happens. Fixes: 0eeda71bc30d ("timer: Replace timer base by a cpu index") Reported-by: Linus Torvalds Signed-off-by: Thomas Gleixner Link: http://lkml.kernel.org/r/alpine.DEB.2.20.1610241711220.4983@nanos Cc: Andrew Morton Cc: Peter Zijlstra Signed-off-by: Mike Galbraith Signed-off-by: Greg Kroah-Hartman --- kernel/time/timer.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -764,8 +764,15 @@ static struct tvec_base *lock_timer_base __acquires(timer->base->lock) { for (;;) { - u32 tf = timer->flags; struct tvec_base *base; + u32 tf; + + /* + * We need to use READ_ONCE() here, otherwise the compiler + * might re-read @tf between the check for TIMER_MIGRATING + * and spin_lock(). + */ + tf = READ_ONCE(timer->flags); if (!(tf & TIMER_MIGRATING)) { base = per_cpu_ptr(&tvec_bases, tf & TIMER_CPUMASK);