Received: by 10.223.176.5 with SMTP id f5csp3362865wra; Mon, 29 Jan 2018 12:11:29 -0800 (PST) X-Google-Smtp-Source: AH8x226jDASA3AJssHiD8csGFzbR/a9GOk5FpY5eQgQkgM+BqMr0bq0MwLRwtAN1f6yCoaH3MePT X-Received: by 10.98.33.198 with SMTP id o67mr28354307pfj.0.1517256689605; Mon, 29 Jan 2018 12:11:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517256689; cv=none; d=google.com; s=arc-20160816; b=B7ll70ud0Xih+mYH+KfPjDBvq7Aj1JEC3RxDZELEXej8h0z2TS9+zh98TxEgiBLQyy ucw4Q8YlcA/c+gci3/0lfYteiwbTFYlT1qYLCJWXyXAOhgGKeZW1brjC0wbZKHSARNOj A5FO1SgSeMfw4c45LTJZzyphFiC5QYxxTe9bBHf4STL50metuzomeBo7zKlEsDVY/lA5 xdQDpp2Sq1iDPEwf8DEb9UKplm23aex1i/UkXLvpqmTveq7BdbHoUdwIUkb20R2TpcEN npnJQXvL2Tb8G9TOVvkYqEq+N+hq5frFoAKp0z4pOmL1zehyToPBr0AeUQgaKtXuAomF LL4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=jjIdUR7qYBSEsw6PzJUUA13wOL/dMcvLSSqL/RpxkmI=; b=kTmzi8EEV9SEC2zbvx702zDo68ufLtIIg+MBg495NqJRR+fnrPdBIFwocOi5kiAuIp pSqVmIboECF96HvgYL1eOLk8TJkgxUY47kKFLyGNH0KLkfatK3IG7Yxu1E3tOjycf4+k SEZaEg117/2R+4mo/zXlVQaUPcVRb7ZjrCSg/Au9LZxu44dhuwwR7YXd6eAJNmomapey XTyPPS9pFpWjEzeQDzBI0ahJiMg2guHu5+415Qt05aR7RS3aHKgIgUgJZuLetqd/P8PC JdQPWU+TwYNn0T8jJCJ5r8q8Q3hkPukgV/ijZOpD8NGim0cehnjbsuTdSTwxMiZvtZB9 5suw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q1-v6si9370490plb.680.2018.01.29.12.11.15; Mon, 29 Jan 2018 12:11:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753341AbeA2UJn (ORCPT + 99 others); Mon, 29 Jan 2018 15:09:43 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:55214 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753316AbeA2UJc (ORCPT ); Mon, 29 Jan 2018 15:09:32 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 183DE2F2F; Mon, 29 Jan 2018 13:03:05 +0000 (UTC) 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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);