linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marco Elver <elver@google.com>
To: elver@google.com
Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk,
	linux-fsdevel@vger.kernel.org,
	syzbot+bd0076c6e839503096b5@syzkaller.appspotmail.com
Subject: [PATCH] fs/select: Fix data races to pwq->triggered
Date: Tue, 17 Dec 2019 21:59:05 +0100	[thread overview]
Message-ID: <20191217205905.205682-1-elver@google.com> (raw)
In-Reply-To: <00000000000031cefb0599ec600b@google.com>

Fix data races to pwq->triggered by using READ_ONCE. These accesses are
expected to race per comment and already provided memory barriers
surrounding the accesses.

Original KCSAN report:

write to 0xffffc90001043c30 of 4 bytes by task 17695 on cpu 0:
 __pollwake fs/select.c:197 [inline]
 pollwake+0xe3/0x140 fs/select.c:217
 __wake_up_common+0x7b/0x180 kernel/sched/wait.c:93
 __wake_up_common_lock+0x77/0xb0 kernel/sched/wait.c:123
 __wake_up+0xe/0x10 kernel/sched/wait.c:142
 signalfd_notify include/linux/signalfd.h:22 [inline]
 signalfd_notify include/linux/signalfd.h:19 [inline]
 __send_signal+0x70e/0x870 kernel/signal.c:1158
 send_signal+0x224/0x2b0 kernel/signal.c:1236
 __group_send_sig_info kernel/signal.c:1275 [inline]
 do_notify_parent+0x55b/0x5e0 kernel/signal.c:1992
 exit_notify kernel/exit.c:670 [inline]
 do_exit+0x16ef/0x18c0 kernel/exit.c:818
 do_group_exit+0xb4/0x1c0 kernel/exit.c:895
 __do_sys_exit_group kernel/exit.c:906 [inline]
 __se_sys_exit_group kernel/exit.c:904 [inline]
 __x64_sys_exit_group+0x2e/0x30 kernel/exit.c:904
 do_syscall_64+0xcc/0x3a0 arch/x86/entry/common.c:294
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

read to 0xffffc90001043c30 of 4 bytes by task 15995 on cpu 1:
 poll_schedule_timeout.constprop.0+0x50/0xc0 fs/select.c:242
 do_poll fs/select.c:951 [inline]
 do_sys_poll+0x66d/0x990 fs/select.c:1001
 __do_sys_poll fs/select.c:1059 [inline]
 __se_sys_poll fs/select.c:1047 [inline]
 __x64_sys_poll+0x10f/0x250 fs/select.c:1047
 do_syscall_64+0xcc/0x3a0 arch/x86/entry/common.c:294
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Reported-by: syzbot+bd0076c6e839503096b5@syzkaller.appspotmail.com
Signed-off-by: Marco Elver <elver@google.com>
---
 fs/select.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/select.c b/fs/select.c
index 11d0285d46b7..152987ddf40e 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -194,7 +194,7 @@ static int __pollwake(wait_queue_entry_t *wait, unsigned mode, int sync, void *k
 	 * and is paired with smp_store_mb() in poll_schedule_timeout.
 	 */
 	smp_wmb();
-	pwq->triggered = 1;
+	WRITE_ONCE(pwq->triggered, 1);
 
 	/*
 	 * Perform the default wake up operation using a dummy
@@ -239,7 +239,7 @@ static int poll_schedule_timeout(struct poll_wqueues *pwq, int state,
 	int rc = -EINTR;
 
 	set_current_state(state);
-	if (!pwq->triggered)
+	if (!READ_ONCE(pwq->triggered))
 		rc = schedule_hrtimeout_range(expires, slack, HRTIMER_MODE_ABS);
 	__set_current_state(TASK_RUNNING);
 
-- 
2.24.1.735.g03f4e72817-goog


      reply	other threads:[~2019-12-17 20:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-17 20:43 KCSAN: data-race in poll_schedule_timeout.constprop.0 / pollwake (3) syzbot
2019-12-17 20:59 ` Marco Elver [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191217205905.205682-1-elver@google.com \
    --to=elver@google.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+bd0076c6e839503096b5@syzkaller.appspotmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).