Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3972281pxb; Tue, 25 Jan 2022 00:19:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJySlbywJ+OfN4X88PqllidpZw38P/+cYqgfF+S2UNLbBTpEvD279pwr1ohayDOxuEO0gpY2 X-Received: by 2002:a17:90a:2c0a:: with SMTP id m10mr2256034pjd.183.1643098798016; Tue, 25 Jan 2022 00:19:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643098798; cv=none; d=google.com; s=arc-20160816; b=ew2jfYG3OIhkbbMZXJiPq0mr3sYDRFrluCGNq2FKH+xl/rP2OK58rt9abrm1F/e5XN W6hiC/+j34tgm2evT8N5h7De54ej7JpFJV/T5xlzpp8hOdhLjI0t+U8iFkZbs7dh0osq YfXqSDunYUBbRWNmz0bzdybLfSIvXjGnGwraK/TuPXTejF+eHkbRTr1pBt2T7MceX45J ahylR0l7K1P2WIscoRQvI3ZMirjkxvnWDy4IVv9E54Xwdigr6m7rJP6y2DOseBJmCXon 5oBJvwBCZT7kqTA/HcGGZMxNejuh7SY4+a+A5t28zqDX+NQrvOB29ZyzPtuWNe0Rw0ZD QZPg== 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=NO8uk+RDiHx2A/mufC9BEt/QO0aSXCSKChCK3KXtzmg=; b=ckc9HWG4Aqmruyst7JKrM1JaD9wdLXR2bztuCrxoEDPGKXWSutPRDPCnE+wMyLT0Gy rOg8gthyQnd02vK6Q4EfCdosmyKNb3WRSCg1keE3a1cemFoBKFKTKHxB0hBpC9PfqiTU 6MJc/aB8RLVa1/M0Ym4AjWAT9OgiZspWZJ+DeyFKyruNWW+77ziOXOPtRDckqAMteiuu dshT+VlvdY3to5VxDjVPAH40GPyQQDB3Zds2nyWcQRi8QRevhOEE4J7eE0wkFl4W/E9m MQoD9TrtHA08PLut+Dw0yRZKGNJx/uBupMFPc+eOfp4n6exPW7iryHDH1C+56AqiGvWm kWtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="yCcOpu//"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k20si13467736pls.312.2022.01.25.00.19.46; Tue, 25 Jan 2022 00:19:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="yCcOpu//"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S3413440AbiAYAjG (ORCPT + 99 others); Mon, 24 Jan 2022 19:39:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2363970AbiAXXq1 (ORCPT ); Mon, 24 Jan 2022 18:46:27 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74898C061375; Mon, 24 Jan 2022 11:13:35 -0800 (PST) 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 EADAE612F5; Mon, 24 Jan 2022 19:13:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2506C36AF6; Mon, 24 Jan 2022 19:13:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051614; bh=mx9rIUd3VouY+JiiGn4HQCd3DlVSRSpLEkOm4VsenVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yCcOpu//QqHej29vCRX3ExLzMIOJV2LJ/Ify47NR/jIoZvQrXEbJ69k2HNcX2RKBG 5IGk0aSMJCcTScnlL4NpVeBQY7VmCXzJQKIzYuBHX6LFjKtqmtpArfDXrIoKAZexDS IEgurjbZ2s+N6Tx/XXUC8jRBQ4oOLQ4idsOppEh8= 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?= , Nobuhiro Iwamatsu , Alessandro Zummo , Alexandre Belloni Subject: [PATCH 4.19 030/239] rtc: cmos: take rtc_lock while reading from CMOS Date: Mon, 24 Jan 2022 19:41:08 +0100 Message-Id: <20220124183944.083120302@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183943.102762895@linuxfoundation.org> References: <20220124183943.102762895@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mateusz Jończyk commit 454f47ff464325223129b9b5b8d0b61946ec704d upstream. Reading from the CMOS involves writing to the index register and then reading from the data register. Therefore access to the CMOS has to be serialized with rtc_lock. This invocation of CMOS_READ was not serialized, which could cause trouble when other code is accessing CMOS at the same time. Use spin_lock_irq() like the rest of the function. Nothing in kernel modifies the RTC_DM_BINARY bit, so there could be a separate pair of spin_lock_irq() / spin_unlock_irq() before doing the math. Signed-off-by: Mateusz Jończyk Reviewed-by: Nobuhiro Iwamatsu Cc: Alessandro Zummo Cc: Alexandre Belloni Cc: stable@vger.kernel.org Signed-off-by: Alexandre Belloni Link: https://lore.kernel.org/r/20211210200131.153887-2-mat.jonczyk@o2.pl Signed-off-by: Greg Kroah-Hartman --- drivers/rtc/rtc-cmos.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -467,7 +467,10 @@ static int cmos_set_alarm(struct device min = t->time.tm_min; sec = t->time.tm_sec; + spin_lock_irq(&rtc_lock); rtc_control = CMOS_READ(RTC_CONTROL); + spin_unlock_irq(&rtc_lock); + if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { /* Writing 0xff means "don't care" or "match all". */ mon = (mon <= 12) ? bin2bcd(mon) : 0xff;