From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.229.7 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796234278; b=ZvAVvI7q09CgljV5Sd6go6XrI7+OF4sH+4NHqAI8K2ZEkzYfCGsBsTb6LZ44jVeRRF2P gM+ao+Nh3CCkK5nwaTNfwtrMpJMN2C4P6oVPP9r/7dvIzirelZKhBp6qqbA/HSm/4uVnt GvahRJrI4QXMyEbEY8k1ODelBWGbf4/PVQ7aZZIhGmzb1/XnpGsHGY7vXgVQfNdP9H8/Q DR0XMriosG2RSU/MwRoT0Dj8CEpDD17F/vlteAvxdEGcwysrmsoQykVjq+5b2+L5Sabu4 jDeo1qvaKfYjgHb89G3nADsTOBqzRR6prM6cmKTcTaP92T2z9vfmAHkyg8xaKcF78ug== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796234278; 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=1FokG0aEO3J4fDuc3i1p0ka/T+nTSAgxePHJWmI2xL0=; b=h4fChEfk+8w8y5KY1xZaGqAfGffmYhuoYRtJp76IaRkmd8tSzOl/ctIX/KNmiOcGHMEB mocMldku5Sk2OD47mKz2cyEzROY9/X6sjl0Hnkveiq0hHK/rt9ofNuXRD48oCgDfKpfN2 VKzRtEeinTIkFOhmqVRZo9MmQDekQzKMKMgN2XPbxKkjhJZ6mjpZlOife8gfPdG4Z1lTK H31JNKSNtHbTy338qy8HABzV3eYod8PbptNOZFd9zPgDZ/5JBtyikEfel8xVxYYFUoj9w b8lt/zVZg6IMVJAOnC1//V397aCbEnS2pYHVWbC6ZMCjFcn7GtaM/e0AXTElVV4ixTw== 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=aYWajq+o; arc=none smtp.remote-ip=74.125.229.7 Received: from mail-dy2-f7.google.com (mail-dy2-f7.google.com [74.125.229.7]) (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 95130606A322 for ; Wed, 2 Dec 2026 17:57:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 95130606A322 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=aYWajq+o Received: by mail-dy2-f7.google.com with SMTP id 5a478bee46e88-386e226acaaso2071332eec.0 for ; Wed, 02 Dec 2026 09:57:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796234277; x=1796839077; 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=1FokG0aEO3J4fDuc3i1p0ka/T+nTSAgxePHJWmI2xL0=; b=aYWajq+oC8MEmyHBCub5/SekOSOx0eX/GoOzRAMtOWPXP0U4ZmInUlVxkIlEv2/61B inXpXPTGSj/OtwDM1HKbNa8h+IRJ6xGez8IMZwrzJNa/fMFKtjA/qq8D0+lRQBh8Tx3F 2DdirBvo3vGFu0vPhjPQzMEwdzO/ZEtypRs/Zni5GNeXNGnWG/zFcTjESzOOFOnoO91j FYKEnwKTXMh4qkoHhM67m2SvFJQ+QMVioSKxRAXidrlE61H35oS8YX/LROvcfpcpxjWx oITEkOyHM8LFQWRi2ehQZzYAh3YqQjbYBpdu3OLPyMgN0VDllOgYUQb0X01tSBgzWNRv VYMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796234277; x=1796839077; 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=1FokG0aEO3J4fDuc3i1p0ka/T+nTSAgxePHJWmI2xL0=; b=MYssFyyfzalu86mwtBAs3OYIYEqqerE0QG3w0/ywxVfGCZbHL0JlavduOhsVxwfDuL qNpg6HVfhqYulS7uqYQkvhiJURmTeZZn4dH0g42XO9tgftPjiyVOH8X+6XNZpk+mKrmV PvMPZ/SVhBFZW7FTDuMXrPRJgWOexn1117Umi0H+M/6wGOQwGWdw/3qEJv8EACxhHnEQ B6KL4RJuaTQ05x1RPvYmQ0yg9OLKVTYoFR4OtVJcab6sNmzoYbYWZdR9SWEUlW3HKRBm rhFVuC2hIXdDU6T4Sa4bNyPMAeju98kn/z+rUA1DzLuPDqu+XpO79WzMtmuXn0RgbXy+ yTkA== X-Forwarded-Encrypted: i=1; AL+hErGT6SpuM67S3CSDgo0bFRoNmRAlkMgaxM01PJDROxNwM6Ki4lWR0Q8Q754kcM4crskroDqa/GPHLAl82wk=@vger.kernel.org X-Gm-Message-State: APuU4Z9mdbO4fqO6bhJRw6jXXBO3L6lMhvN2bjWr0XkBcQEJpkn4Fb99 RJU2FLi0CPU5oHox6r/uFI2Obhqf/jDQbDb+TbkWFSQiFtFPkaDxlfOy X-Gm-Gg: AZFdTZd0SEyjYhzJFrQj5vYQt9rClwfASH0WXctcVV04tIcfxwoXF/+P4yRnKEG/EhK 02QlO5dUI9qzHCZUcMjVSHOzJPSzSIVrK0ZBQS/oa4Ma/nDP8pDLMmPx7PN55pQyMj01QRv+Cq/ fOp0iEUnc1KnTSgnKk9UHCg5EUK87sTbE9/OmNj96Jq02zDkFWEblq3OCuh8EFLyUjncXiK7Ppd LGRO5SLK73Weu/EfA5HyZ5heLfz1/fLdbjUe+BMq0a610Hr4rCZHa+3g23obi1WC7mII7isO7B5 OJmqVlpbsk8ZTPDZRf2X8/CY7ZeVrq+iEl2bOQHmEGWg5emeYXZjgVr4niWlka7xrT3AWyZUbgW kD4D7vQzFAbXXu9Q+cOLwgM6z+rGAhvfdNKPAYZm0s8pSYfWpi8BS0gx7miZK9yGnmobR/ufW8r SjCoMwuXwiwknZ5VCjApImgVGIJI6+0dvUTSaoxbtB56oFNkPepAMg7c+0gg0zWJ+5MjkT+l58h yXaWqDtDfRWut/lYaXlngGeSJvafCdRRJatMMYepKeMz+zbLVYFsNqLFVMkzjhD3v7K61P4/VlD MVPZYHg1HWryCE3IWbw/Xcz/g132GSEjA9s37QGVd1lY1YGVH4WO0qAn X-Received: by 2002:a05:693c:83cf:10b0:386:b526:24d1 with SMTP id 5a478bee46e88-386b52638e1mr33013079eec.9.1796234276369; Wed, 02 Dec 2026 09:57:56 -0800 (PST) Received: from jiayi-vm-sprl-server17.local ([155.69.195.24]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385666e99fdsm138280510eec.5.2026.12.02.09.57.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 09:57:56 -0800 (PST) From: Jiayi Zhang To: Jan Kara , Amir Goldstein Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+f2d61c1b2357c03fb539@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com Subject: [PATCH] fsnotify: use WRITE_ONCE() when clearing the object mask on detach Date: Wed, 2 Dec 2026 17:57:45 +0000 Message-ID: <20261202175745.4134238-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_detach_connector_from_object() clears the fsnotify mask of the inode, mount, superblock or mount namespace with a plain store. The mask is read without locks: __fsnotify_parent() and fsnotify() read it with READ_ONCE(), and __fsnotify_recalc_mask() writes it with WRITE_ONCE() for that reason. KCSAN reports the plain store: BUG: KCSAN: data-race in __fsnotify_parent / fsnotify_detach_connector_from_object write to 0xffff888101690808 of 4 bytes by task 3372 on cpu 1: fsnotify_detach_connector_from_object+0x1e3/0x370 fs/notify/mark.c:409 fsnotify_put_mark+0x1d8/0x590 fs/notify/mark.c:476 __do_sys_inotify_rm_watch fs/notify/inotify/inotify_user.c:796 [inline] read (marked) to 0xffff888101690808 of 4 bytes by task 3017 on cpu 0: fsnotify_object_watched fs/notify/fsnotify.c:152 [inline] __fsnotify_parent+0xfd/0x3a0 fs/notify/fsnotify.c:202 The race has no functional effect: the store writes a constant zero to an aligned u32, and a reader that still sees the old mask goes on to look up the marks as before. Commit 35ceae44742e ("fsnotify: Avoid data race between fsnotify_recalc_mask() and fsnotify_object_watched()") marked the readers and the store in __fsnotify_recalc_mask() but not these four stores. Use WRITE_ONCE() for them too. KCSAN reports the plain store only with CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC=n, as on syzbot. Fixes: 35ceae44742e ("fsnotify: Avoid data race between fsnotify_recalc_mask() and fsnotify_object_watched()") Reported-by: syzbot+f2d61c1b2357c03fb539@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=f2d61c1b2357c03fb539 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. The syzbot reproducer only mounts an image; the race comes from inotify users running on the syzbot machines. Tested in QEMU instead with a small program that runs open() and inotify_add_watch()/ inotify_rm_watch() on one file in parallel threads, with KCSAN on and unrelated races filtered: without the patch 1 of 5 instances reported this race first; with the patch none of 10 did. Both runs also report other races in fsnotify (for example fsnotify_free_mark() against fsnotify_handle_inode_event(), and the plain read of the connector pointer in fsnotify()), which this patch does not address. AI tools assisted with the analysis, the code and the changelog. fs/notify/mark.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/notify/mark.c b/fs/notify/mark.c index cb07f42..d24941b 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -406,18 +406,18 @@ static void *fsnotify_detach_connector_from_object( if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) { inode = fsnotify_conn_inode(conn); - inode->i_fsnotify_mask = 0; + WRITE_ONCE(inode->i_fsnotify_mask, 0); fsnotify_untrack_connector(conn); /* Unpin inode when detaching from connector */ if (!(conn->flags & FSNOTIFY_CONN_FLAG_HAS_IREF)) inode = NULL; } else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) { - fsnotify_conn_mount(conn)->mnt_fsnotify_mask = 0; + WRITE_ONCE(fsnotify_conn_mount(conn)->mnt_fsnotify_mask, 0); } else if (conn->type == FSNOTIFY_OBJ_TYPE_SB) { - fsnotify_conn_sb(conn)->s_fsnotify_mask = 0; + WRITE_ONCE(fsnotify_conn_sb(conn)->s_fsnotify_mask, 0); } else if (conn->type == FSNOTIFY_OBJ_TYPE_MNTNS) { - fsnotify_conn_mntns(conn)->n_fsnotify_mask = 0; + WRITE_ONCE(fsnotify_conn_mntns(conn)->n_fsnotify_mask, 0); } rcu_assign_pointer(*connp, NULL); -- 2.53.0