Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp651586pxb; Tue, 5 Apr 2022 17:21:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe65l1SPaxxRknqkFFgeYWBGkgogeazNB5CSB93C1J6aqBHb6OfivHM+b4SHsFpJ21cES7 X-Received: by 2002:a17:907:6d23:b0:6d9:ac9d:222 with SMTP id sa35-20020a1709076d2300b006d9ac9d0222mr6054734ejc.595.1649204503255; Tue, 05 Apr 2022 17:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649204503; cv=none; d=google.com; s=arc-20160816; b=KoDW13nJgAYVTnu0efLfgUrD8MQw85rUVyfxuqvTwWn3TsacPnU80pb6WMjy7wfY7R 8AvF23tM0x994sHqYC58LBC2BIFe4AxdBfMwE0ZR3dG3PJPDFsMG5TaUE5ueWMsOP5Sa OZhJai6ghF1Q/UPAivy72PLUhR3PeqewSi2kTONoi1ehjp7OprDyYWMFF+7RfseA81xk caL5Ua4HA71U+Q4MMWuT5ASNxSwqWTWu8VONlTBklxhlu0tIyqMBmohfa9Q4jEKEAjHe Ve9JTGx7lVgtNoaSKRfqzWvOU2N1na9c99O3IPrm/TbpsVfiPnPSDK6m4taahSQVnzw7 d5yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MS41JKQCDbXwxL7e+gy88DIiwJjTXNIfZbnvFaxQp/Y=; b=XNhTrRt1y8YGWFpv0hw37/YMM1QXBH5dNGNjehQM8uCSrU8FBdJfoOPVSb9LtxDDi7 IU5fNvyw0od5rMS53rUPEvP1EzO5bytZnG0I+G9EEM4X6C2kDRfnl5aQYEVYhodtvfmG 5aJbMamDc5yFBYFe9UqqchWAamO6KDgwd9F0DEb7tqEliVgxjtUoDtcLW0oJhx/V4XMN OHEU+z1YWWQk5cW2tqkMt8d4J8pcpBgnfSXYwTKBf11DBJZin2VoDV8JGc/NBIOPC+23 nuF+kRV6VjMevxeVzW5RbbN2mf5izA/NzhpIfq86lL+dj0ilIKGfBkgtWJEBrnpuhqEl 7Jtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TuC24iUr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q1-20020a50cc81000000b0041cd7922195si4655246edi.162.2022.04.05.17.21.11; Tue, 05 Apr 2022 17:21:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TuC24iUr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242899AbiDELHg (ORCPT + 99 others); Tue, 5 Apr 2022 07:07:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237891AbiDEInb (ORCPT ); Tue, 5 Apr 2022 04:43:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FF751D328; Tue, 5 Apr 2022 01:35:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 80FB260B0A; Tue, 5 Apr 2022 08:35:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91E87C385A0; Tue, 5 Apr 2022 08:35:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147752; bh=9oeaOtDRB/SGVsQXC0FYtjORDubOt8V3HM+oZFsGGz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TuC24iUrVtKK6BvNYr5ew7qJgM3fYBFAeYqQMDWX7dfizpWXShjYBHOtbMuFIDxmU +HbZ79DhE0HKsA2a5r+C4TEw6GtXPSNf13kqEZwQpZvXpbEGe5areoj0Dp+/N1l2V2 VfEIGdMUdYjnsO6SA7Qh0O5+iduXv2hrDc/zj5/o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= , Alessandro Zummo , Alexandre Belloni , Thomas Gleixner Subject: [PATCH 5.16 0108/1017] rtc: mc146818-lib: fix locking in mc146818_set_time Date: Tue, 5 Apr 2022 09:17:01 +0200 Message-Id: <20220405070357.402497403@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mateusz Jończyk commit 811f5559270f25c34c338d6eaa2ece2544c3d3bd upstream. In mc146818_set_time(), CMOS_READ(RTC_CONTROL) was performed without the rtc_lock taken, which is required for CMOS accesses. Fix this. Nothing in kernel modifies RTC_DM_BINARY, so a separate critical section is allowed here. Fixes: dcf257e92622 ("rtc: mc146818: Reduce spinlock section in mc146818_set_time()") Signed-off-by: Mateusz Jończyk Cc: Alessandro Zummo Cc: Alexandre Belloni Cc: Thomas Gleixner Cc: stable@vger.kernel.org Signed-off-by: Alexandre Belloni Link: https://lore.kernel.org/r/20220220090403.153928-1-mat.jonczyk@o2.pl Signed-off-by: Greg Kroah-Hartman --- drivers/rtc/rtc-mc146818-lib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/rtc/rtc-mc146818-lib.c +++ b/drivers/rtc/rtc-mc146818-lib.c @@ -176,8 +176,10 @@ int mc146818_set_time(struct rtc_time *t if (yrs >= 100) yrs -= 100; - if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) - || RTC_ALWAYS_BCD) { + spin_lock_irqsave(&rtc_lock, flags); + save_control = CMOS_READ(RTC_CONTROL); + spin_unlock_irqrestore(&rtc_lock, flags); + if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { sec = bin2bcd(sec); min = bin2bcd(min); hrs = bin2bcd(hrs);