Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2623383pxb; Sun, 17 Oct 2021 20:48:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1s0GK3L5U/0wGv83PYTAVGL19XN+73FZsHp+s0qDcJK7UGGCZ9IwbQr8jh4QBd8si/Z4g X-Received: by 2002:a63:8f49:: with SMTP id r9mr12981842pgn.208.1634528913563; Sun, 17 Oct 2021 20:48:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634528913; cv=none; d=google.com; s=arc-20160816; b=WEnN2h/XKD7KknCB5YGiymiisyjf2eqkz3V2/8yMrvdWuHQzCtFZtEYrSCp01K4IsT PqlYdZMnxmzNaVkxWlOSZjLr42MCTlQYPxARckSglCxS7Tkjh6VSD72pXWctDvq8Vu21 GiXuHlJ6LfbUmNLbjMXO3e7BVnv1bfxIeak+9aY0LJWqWGNYeNSxysc9Stl1ZXv5zBps dFj3G+kBJ7efovymI86G4LjMYPJ9wpSTDSzLbxqTKPTYi/mTCm2bh1hcZzjx71IW6TMb fI4e1qna0se2qIiBmRfIZLqAyT8a4nCxeNgHWQQvR2kH1D+L2DkxvZ6WiVjrMuY+B7g1 ZrFA== 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=3iFUs763VvbcDRyYycNRDJTBVEc1OeQSyLJg/GJi6vs=; b=Y8zSMciGDD+fwGyCir+lUJRBXu9R9+9s80y27omx/Da//XDEuAdUIoDE1f+08EF7Dg 6gmLy33V3u2mjp06+lZzCi+GP6I8/Z8IpD0KfO/xmCpqd/lXFssbrYtLRQWfXYx6bqgd n3IF4Vg3SncpbgGomSix1cbLnkVnDiNvnfyBmdSbVdxWRmuQQ9Mbb+PD3VPyspBYps/r p4S+R51HbFeqGaSKSXOpFrYKIJrUvvyg8ncYXcbamXBXhWBkCEqNnxUON+y6BWQ6yPCZ 0VsLYIV2xQxbQOTnnoGc9KZ6C9AvnQzSiWur86mXXY3xurYGld83JlmzEVSSyuG4+/Nj oH+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@o2.pl header.s=1024a header.b=ZqboXY2g; 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 y11si16638015pfa.8.2021.10.17.20.48.21; Sun, 17 Oct 2021 20:48:33 -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=ZqboXY2g; 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 S1344545AbhJQTly (ORCPT + 98 others); Sun, 17 Oct 2021 15:41:54 -0400 Received: from mx-out.tlen.pl ([193.222.135.142]:47740 "EHLO mx-out.tlen.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344544AbhJQTlx (ORCPT ); Sun, 17 Oct 2021 15:41:53 -0400 Received: (wp-smtpd smtp.tlen.pl 362 invoked from network); 17 Oct 2021 21:39:41 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=o2.pl; s=1024a; t=1634499581; bh=3iFUs763VvbcDRyYycNRDJTBVEc1OeQSyLJg/GJi6vs=; h=From:To:Cc:Subject; b=ZqboXY2gAB8Mf4ePIdLWaCrIsnW7Mocd6hJ6ILWghQ7nMZ+6ioJKXAE8VhSPZatlu 6AvUfqzTbdFMWW6cletUYtPLEmGDl3wZayUl1oqHOLVpK4lBKDMaDJMbXycpSSLSKs /RyMTH8TKlcAJR8T5n3+Sx3p9M02aiIJ6DxaAdSk= Received: from aaet142.neoplus.adsl.tpnet.pl (HELO localhost.localdomain) (mat.jonczyk@o2.pl@[83.4.123.142]) (envelope-sender ) by smtp.tlen.pl (WP-SMTPD) with SMTP for ; 17 Oct 2021 21:39:41 +0200 From: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= To: linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org Cc: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= , Nobuhiro Iwamatsu , Alessandro Zummo , Alexandre Belloni , stable@vger.kernel.org Subject: [PATCH RESEND 1/6] rtc-cmos: take rtc_lock while reading from CMOS Date: Sun, 17 Oct 2021 21:39:22 +0200 Message-Id: <20211017193927.277409-2-mat.jonczyk@o2.pl> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211017193927.277409-1-mat.jonczyk@o2.pl> References: <20211017193927.277409-1-mat.jonczyk@o2.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-WP-MailID: 5dd1c99ea2136e35086f290411fed404 X-WP-AV: skaner antywirusowy Poczty o2 X-WP-SPAM: NO 0000000 [gQO0] 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 the 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 670fd8a2970e..2cd0fe728ab2 100644 --- a/drivers/rtc/rtc-cmos.c +++ b/drivers/rtc/rtc-cmos.c @@ -463,7 +463,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