Skip to content

Commit b47bcab

Browse files
mfoliveiraalexandrebelloni
authored andcommitted
rtc: add data_race() in rtc_dev_poll()
The unlocked read of rtc->irq_data in rtc_dev_poll() can race with the write in rtc_handle_legacy_irq() and also, theoretically, with the write in rtc_dev_read(). These races should be safe (see inline comment), thus annotate the read with data_race() for KCSAN. Reported-by: syzbot+2d4127acca35ed7b31ad@syzkaller.appspotmail.com Closes: https://syzbot.org/bug?extid=2d4127acca35ed7b31ad Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com> Link: https://patch.msgid.link/20260317-irq_data-v1-1-a2741002be60@igalia.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 5827fe5 commit b47bcab

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

drivers/rtc/dev.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,16 @@ static __poll_t rtc_dev_poll(struct file *file, poll_table *wait)
195195

196196
poll_wait(file, &rtc->irq_queue, wait);
197197

198-
data = rtc->irq_data;
198+
/*
199+
* This read can race with the write in rtc_handle_legacy_irq().
200+
*
201+
* - If this check misses a zero to non-zero transition the next check
202+
* will pick it up (rtc_handle_legacy_irq() wakes up rtc->irq_queue).
203+
* - Non-zero to non-zero transition misses do not change return value.
204+
* - And a non-zero to zero transition is unlikely to be missed, since
205+
* it occurs on rtc_dev_read(), during which polling is not expected.
206+
*/
207+
data = data_race(rtc->irq_data);
199208

200209
return (data != 0) ? (EPOLLIN | EPOLLRDNORM) : 0;
201210
}

0 commit comments

Comments
 (0)