]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - queue-4.4/rtc-cmos-take-rtc_lock-while-reading-from-cmos.patch
4.4-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.4 / rtc-cmos-take-rtc_lock-while-reading-from-cmos.patch
CommitLineData
eeebef1c
GKH
1From 454f47ff464325223129b9b5b8d0b61946ec704d Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= <mat.jonczyk@o2.pl>
3Date: Fri, 10 Dec 2021 21:01:23 +0100
4Subject: rtc: cmos: take rtc_lock while reading from CMOS
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9From: Mateusz Jończyk <mat.jonczyk@o2.pl>
10
11commit 454f47ff464325223129b9b5b8d0b61946ec704d upstream.
12
13Reading from the CMOS involves writing to the index register and then
14reading from the data register. Therefore access to the CMOS has to be
15serialized with rtc_lock. This invocation of CMOS_READ was not
16serialized, which could cause trouble when other code is accessing CMOS
17at the same time.
18
19Use spin_lock_irq() like the rest of the function.
20
21Nothing in kernel modifies the RTC_DM_BINARY bit, so there could be a
22separate pair of spin_lock_irq() / spin_unlock_irq() before doing the
23math.
24
25Signed-off-by: Mateusz Jończyk <mat.jonczyk@o2.pl>
26Reviewed-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
27Cc: Alessandro Zummo <a.zummo@towertech.it>
28Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
29Cc: stable@vger.kernel.org
30Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
31Link: https://lore.kernel.org/r/20211210200131.153887-2-mat.jonczyk@o2.pl
32Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33---
34 drivers/rtc/rtc-cmos.c | 3 +++
35 1 file changed, 3 insertions(+)
36
37--- a/drivers/rtc/rtc-cmos.c
38+++ b/drivers/rtc/rtc-cmos.c
39@@ -343,7 +343,10 @@ static int cmos_set_alarm(struct device
40 min = t->time.tm_min;
41 sec = t->time.tm_sec;
42
43+ spin_lock_irq(&rtc_lock);
44 rtc_control = CMOS_READ(RTC_CONTROL);
45+ spin_unlock_irq(&rtc_lock);
46+
47 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
48 /* Writing 0xff means "don't care" or "match all". */
49 mon = (mon <= 12) ? bin2bcd(mon) : 0xff;