Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1487562pxb; Sat, 30 Oct 2021 14:59:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7tmi9Docp9eYhrLT6WG4YfkQlRqqtjPjX7wbVv/0b09KlQjswWePVSiKcyPKLsPyIeYyo X-Received: by 2002:a05:6402:1157:: with SMTP id g23mr28173545edw.379.1635631196113; Sat, 30 Oct 2021 14:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635631196; cv=none; d=google.com; s=arc-20160816; b=H8BLsaidQGV35JuxwdxhVhjTqP27TGasqKcY5P8E6GxVI58lichAkS+kBhBLudmdGw GvfMcQERz3r7qm3U1lalAvzCFRe/yEe4H4f0GLQhkeLAy6bIQsUnluXSGvBcqTa/8O0D ENGangSvD8Hpbeb+0XErJDfvEIoRzg8+X4PkDEzYh0+cp9+6syswOfj4dKHiQmGVn7oe Akb0qQR77kosaviF87VzgzKFMnIkWEXpSK4Ylf7nwyrMiWN4z46E4q7iG3OyhpROMKkK /fAAdlDt3kFn0905Xw714S5xOZg11MurkNw8gV3576i6jWeM8ilIl4RGEPXohTi+E9ll YnNg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UHf1ypbd17Kopy+oZJ9KeBqXEW0Si75CBEqlrPjJ6Rk=; b=EedqU7GufuQIgWWjTVuzC5Cz7jo7rRmKkU0EJhaaIfwWNsf7mUgHkaS5uIEEqTnbtn C/GKYYkMbDNpRhN7yUcEU8i2SCOaiYhc3bACnGfVGuy4pQogqaU5XTEhSqvB0t4bkSsk hQiHI86sQ4Cpi/bpqwpJOlFfQ0bW+UFsQWGLxv1KS5xuIp7OkWHe4wlUybYrXfeu3g9X u+C/iYHImOTu59TYjCS+3Pjv1LI1yhgE0BbCklDHPAF79fdhOZbeBuxU5lOcezYGbtL/ RsjuaqQGlTPVb/uK21wik2ZyczzUGVQTH8leSc3OnDUiaZskrcyz0E5UzHh7sL8jbzKq Hujw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@o2.pl header.s=1024a header.b=a6y0t1C3; 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=o2.pl Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hv12si17017546ejc.244.2021.10.30.14.59.29; Sat, 30 Oct 2021 14:59:56 -0700 (PDT) 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 (test mode) header.i=@o2.pl header.s=1024a header.b=a6y0t1C3; 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=o2.pl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230323AbhJ3Vtw (ORCPT + 99 others); Sat, 30 Oct 2021 17:49:52 -0400 Received: from mx-out.tlen.pl ([193.222.135.142]:19506 "EHLO mx-out.tlen.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231494AbhJ3Vtv (ORCPT ); Sat, 30 Oct 2021 17:49:51 -0400 Received: (wp-smtpd smtp.tlen.pl 18014 invoked from network); 30 Oct 2021 23:47:18 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=o2.pl; s=1024a; t=1635630439; bh=UHf1ypbd17Kopy+oZJ9KeBqXEW0Si75CBEqlrPjJ6Rk=; h=From:To:Cc:Subject; b=a6y0t1C3tsRjCk8AL99mIbGm3R9C7U4wZogvCvyNVG/FIVAg67KFIMrLuQJRk/obq m5nbnINkjAx570jT+RL090Ek+Fkk+q2V5BHdLPAeoA0Nh+Bw5QE/xfgMSRPy4NXriT sQarAOAnJnzNQNdMQ/l1g4IG2ErAjH4Cu7Iv5zrA= Received: from ablz112.neoplus.adsl.tpnet.pl (HELO localhost.localdomain) (mat.jonczyk@o2.pl@[83.7.219.112]) (envelope-sender ) by smtp.tlen.pl (WP-SMTPD) with SMTP for ; 30 Oct 2021 23:47:18 +0200 From: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= To: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= , Nobuhiro Iwamatsu , Alessandro Zummo , Alexandre Belloni , stable@vger.kernel.org Subject: [PATCH v3 1/7] rtc-cmos: take rtc_lock while reading from CMOS Date: Sat, 30 Oct 2021 23:46:29 +0200 Message-Id: <20211030214636.49602-2-mat.jonczyk@o2.pl> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211030214636.49602-1-mat.jonczyk@o2.pl> References: <20211030214636.49602-1-mat.jonczyk@o2.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-WP-MailID: 38f52ece292cce571491b757614f8bd2 X-WP-AV: skaner antywirusowy Poczty o2 X-WP-SPAM: NO 0000000 [oUN0] Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/rtc/rtc-cmos.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c index 4eb53412b808..dc3f8b0dde98 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -457,7 +457,10 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t) 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; -- 2.25.1