From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.227.132 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796235227; b=bjwFR1jhnvhp9sHx1+bOQPfk7ouIF8BhUxEHnb32jWhOFwz4GThaIdcKZxjEDvqQmt2T bzMme2RFhnR+o/OrpPYSd4IuRXJKVHKsMNcypmcewHE07QRB/gmFXtrKbw8ijvqlR7iU6 giqOq7ogp+eCpLnPVDXQUdBoyBPHXydp7N3+NIuikgmwCLdf+MBvIkLUPuFYZVabXe7Aw Gw9GzA2SZP6ZSS+cEMzMTVIfyfGQ+RA9/SocHE6vGayUgH4ARigmL2d4UgA8cyxxcq536 +cQ8G9Q6yx8rpLo6zfTV/5M0wFbopMkmBIkIHSwxlMSeJo2F/Y4jREFujPPUBhn80zA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796235227; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=rGwbqlQFcIODTKNdAGhUUfr38r9MhDRgGv7BnAx2q9w=; b=la5qmmJlgGcTGLhlETBFlIm3maC9S78x77FaR6ZeSDu3cOs2WotekCr0SoMWmAQjuYHC 3vfsmvYqKwGHIxfoFhezvqfH8aA1EfL8OMugKJJnPM9SdeNZyje99xSCrugjmZ18/7ykA Vm+OJ3dsa23A+8g6/ueQoPAOCD5rZyIdan+rDb2xJjRFKQkn9+uDmjyzZbR/qMDAhrMeE 7IBWjm4BuL+1V2Twgl3cTxitA9iUGSgNeKWmRGfVgLIVFcoXRgcvdj2VV5YmeDbeMPLAy /wl7zDhK20OCFwcp1S+kVIO2DkMRViDUYfCZ0eYsP6vMkUwSi7ckK57QD0OhoMCgqaA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=b8b435AR; arc=none smtp.remote-ip=74.125.227.132 Received: from mail-pj2-f4.google.com (mail-pj2-f4.google.com [74.125.227.132]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63726606A322 for ; Wed, 2 Dec 2026 18:13:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 63726606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=b8b435AR Received: by mail-pj2-f4.google.com with SMTP id d9443c01a7336-2f042b6ef3aso98112275ad.1 for ; Wed, 02 Dec 2026 10:13:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796235227; x=1796840027; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=rGwbqlQFcIODTKNdAGhUUfr38r9MhDRgGv7BnAx2q9w=; b=b8b435AR4jFqNFX9Pd3+LKjzkQ3rwULqhithxstbH98+Y+sBuYo+tJR3cOthWLrerw x5gAzsCSJfdSmSVEIYC9P6CJZBMIWWe8mBZ1e/hSIvd1Vxe8Ei2Tza0a0To8OAAINY4j o23Fsxo3T0jls63HpXxhOFcjNJO5HRbJk7MvpeS2ccJdbeZbPRvSbA8c5hfoTA9K8083 2KfAgwJ6YqpLwdWBc05Q4doUyk8Vc/jRe+T1IK5/bCzGqJXU9jf6Tc9eD5+x/lx767no OwHEFEZbjwz1MO03T6Z4tjE1Ksp5PwTPvZ7tpnfD3IGWvIMho16DpSM8woNEk4cR775M yU8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796235227; x=1796840027; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=rGwbqlQFcIODTKNdAGhUUfr38r9MhDRgGv7BnAx2q9w=; b=cpalL/MlfEYzRRax5Y9g2A6FRRT8yf2Pt+J8hKGGOBAyOv2X0tzo2DrqK9p5iyGCl1 BZUNAY+f/cTpQfze9Yk+0GPA89/awQDPYTEqp/vNmrIv5eTtTuSlYTTrWcjKkrYD43G9 wEs1kdF8VU5djqmO9xd7RGHDugkE0SI7NgUS/E7IZzRwuFOnTIth1ifOhoUH21coln3O rVRY3P8PLDHlvdpIZolVCw7xMt2685lm7EC/tpONrwS+s4RiGIeCZlL3lZTIvWEsPSAV Qth+jg8haX7h3WMJIfMXSSFfJBovdGeOhhvna3wqXMMbOSehJym8LGcbDfRoHN/CZHMR Cw1g== X-Forwarded-Encrypted: i=1; AL+hErFdL+XiyKXOa1N+GXVeYXj4Zd2FQmNqlqLVIxhju61Iu94Z6tD/aFf4QqlBe+5ruRYWzRfnUn9ChCZ6v3c=@vger.kernel.org X-Gm-Message-State: APuU4Z9e6mU5UmWApgdQrpsZpqEz/ABKUt7d6ZGLn0VPd8KGU+GrVeGT 1C2WoxIwusYLwT2UQtx7xO6WPvW1TULL5pbxcvpp8A1cFkv0AbRZy8yf X-Gm-Gg: AZFdTZduaM76oi4LiLtorq0qLF3qnabIi0/vU7R/m4HnioTsg8qvAauOwRvSU3U7j5z KCaRqTny34UoODIFKpLjIJiaPl2Ts5q/rlBgd/TA4x86Q+Io3v9GHLSiePQV+AFeWRDJISzFDDz 0GvjJQmk+wPeScr0SADul2wBXin2ENEhA8SMk1uOvWjdV5X0OVcTEDbbS1izovZ44XgXjhMtkWI vEZJPXJwAXEDfc8V1qgOmv1l8WQaCLHa98tt89W92NCFTeBZVAxXxzBbYAIBhYM9yVeWf/50bmT JABG7RdLzXqD9wkdg1sX6E1Q4DBKDthdBBmQsSR9kTgXJdJeixoT0H6CnV9AzTXw+rd2khHjvG6 lNlYV0ZmqB2pcsZ4+3O3ubm4LSrwpjhVXANgpW+L0ByDvdYs+zerjCOeIwV9rAwyRKLZ1ka0oMu qmlQNPYdojZaJcnxeclJj52TFHctuwwBfNOJCWc69xrYBNiJMVSCR5d/bfRljo9izEEdF6lAiOH YAuO5hbM3ZB6BwjPg65OFbj+qKxYFUuG8mZUYvellONxSdMVvnaYqbOjIJ0uDUROa6bFFc9NtXL KtsId85NK9ml+G45+FxujplhcqnDcVyU/USYmJLe2tuBZEolHnJ7IH2amJeLHlLq8l30ZhG7oaa klQ== X-Received: by 2002:a17:902:ec8b:b0:2ea:33eb:7375 with SMTP id d9443c01a7336-2f03f16ac73mr427896055ad.45.1796235226703; Wed, 02 Dec 2026 10:13:46 -0800 (PST) Received: from jiayi-vm-sprl-server17.local ([155.69.195.24]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f11770df61sm92801755ad.53.2026.12.02.10.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 10:13:46 -0800 (PST) From: Jiayi Zhang To: Jan Kara , Amir Goldstein Cc: Christian Brauner , Alexander Viro , Miklos Szeredi , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+f968afcac117a84b7f14@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com Subject: [PATCH] fsnotify: use rcu_access_pointer() to test the mark connector pointers Date: Wed, 2 Dec 2026 18:13:38 +0000 Message-ID: <20261202181338.4162502-1-zhangjiayi1014@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit fsnotify() skips objects without marks by testing sb_marks, mnt_fsnotify_marks, i_fsnotify_marks and n_fsnotify_marks for NULL before it takes SRCU, and fsnotify_mnt() and mnt_notify_add() do the same for n_fsnotify_marks. These are __rcu pointers that fsnotify_detach_connector_from_object() clears with rcu_assign_pointer() when the last mark goes away, but the tests read them with plain loads. KCSAN reports: BUG: KCSAN: data-race in fsnotify / fsnotify_detach_connector_from_object write (marked) to 0xffff88810024bbb8 of 8 bytes by task 4110 on cpu 1: fsnotify_detach_connector_from_object+0x319/0x370 fs/notify/mark.c:423 fsnotify_put_mark+0x1d8/0x590 fs/notify/mark.c:476 __do_sys_inotify_rm_watch fs/notify/inotify/inotify_user.c:796 [inline] ... read to 0xffff88810024bbb8 of 8 bytes by task 11515 on cpu 0: fsnotify+0x339/0x18b0 fs/notify/fsnotify.c:542 __fsnotify_parent+0x2f8/0x3a0 fs/notify/fsnotify.c:241 fsnotify_parent include/linux/fsnotify.h:96 [inline] ... The race has no functional effect: the tests only compare the pointers with NULL to skip the SRCU section, and a stale value only means one event is or is not delivered to a mark that is being added or removed at that moment. The plain loads still let the compiler tear or reload them, and KCSAN reports them. Use rcu_access_pointer(), the accessor for testing an __rcu pointer without dereferencing it, for these tests. Fixes: 08991e83b728 ("fsnotify: Free fsnotify_mark_connector when there is no mark attached") Reported-by: syzbot+f968afcac117a84b7f14@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=f968afcac117a84b7f14 Signed-off-by: Jiayi Zhang --- The syzbot report is in syzbot's moderation queue and was not sent to the lists; the Closes: link shows it. kernel/auditsc.c has the same plain test of i_fsnotify_marks in two places; that change is sent to the audit maintainers separately. syzbot has no reproducer. Tested in QEMU (2 CPUs, the syzbot config, kernel 8d7fe9885c62) with a test program in which threads open() and close() one file while other threads add and remove an inotify watch on it, with KCSAN switched on at run time and a report filter for the functions on both sides. Without the patch all 5 instances reported a race under this title within about 90 seconds, 4 of them this pair (fsnotify.c:542 against mark.c:423). The same title also covers the i_fsnotify_mask stores in fsnotify_detach_connector_from_object(), which "fsnotify: use WRITE_ONCE() when clearing the object mask on detach" (sent the same day) fixes; with this patch alone the instances stopped at that pair after 98 to 159 seconds. With both patches none of 5 instances reported anything in 10 minutes each. AI tools assisted with the analysis, the code and the changelog. fs/mount.h | 4 ++-- fs/notify/fsnotify.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/mount.h b/fs/mount.h index 4d23cad..b4a019f 100644 --- a/fs/mount.h +++ b/fs/mount.h @@ -244,8 +244,8 @@ static inline void mnt_notify_add(struct mount *m) if (!list_empty(&m->to_notify)) return; /* Optimize the case where there are no watches */ - if ((m->mnt_ns && m->mnt_ns->n_fsnotify_marks) || - (m->prev_ns && m->prev_ns->n_fsnotify_marks)) + if ((m->mnt_ns && rcu_access_pointer(m->mnt_ns->n_fsnotify_marks)) || + (m->prev_ns && rcu_access_pointer(m->prev_ns->n_fsnotify_marks))) list_add_tail(&m->to_notify, ¬ify_list); else m->prev_ns = m->mnt_ns; diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 8657bb9..a496220 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -537,11 +537,11 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir, * SRCU because we have no references to any objects and do not * need SRCU to keep them "alive". */ - if ((!sbinfo || !sbinfo->sb_marks) && - (!mnt || !mnt->mnt_fsnotify_marks) && - (!inode || !inode->i_fsnotify_marks) && - (!inode2 || !inode2->i_fsnotify_marks) && - (!mnt_data || !mnt_data->ns->n_fsnotify_marks)) + if ((!sbinfo || !rcu_access_pointer(sbinfo->sb_marks)) && + (!mnt || !rcu_access_pointer(mnt->mnt_fsnotify_marks)) && + (!inode || !rcu_access_pointer(inode->i_fsnotify_marks)) && + (!inode2 || !rcu_access_pointer(inode2->i_fsnotify_marks)) && + (!mnt_data || !rcu_access_pointer(mnt_data->ns->n_fsnotify_marks))) return 0; if (sb) @@ -710,7 +710,7 @@ void fsnotify_mnt(__u32 mask, struct mnt_namespace *ns, struct vfsmount *mnt) * This is an optimization as well as making sure fsnotify_init() has * been called. */ - if (!ns->n_fsnotify_marks) + if (!rcu_access_pointer(ns->n_fsnotify_marks)) return; fsnotify(mask, &data, FSNOTIFY_EVENT_MNT, NULL, NULL, NULL, 0); -- 2.53.0