[PATCH 2/3] inotify: zero-pad event names after an embedded NUL

From: Junyoung Jang

Date: Sun Nov 15 2026 - 16:10:19 EST


inotify_handle_inode_event() allocates the variable-length event with
kmalloc() without zeroing the name buffer, sets event->name_len to
name->len, and copies name->name with strscpy().

If a dentry qstr contains an embedded NUL byte (for example, via a
crafted FUSE READDIRPLUS entry aliasing an open directory), strscpy()
stops at the first NUL while event->name_len still covers the trailing
bytes. copy_event_to_user() then copies event->name_len bytes to
userspace, leaking uninitialized slab memory from the tail of the
event allocation.

This mismatch dates back to
commit ce163918cd33 ("inotify_handle_event(): don't bother with strlen()"),
which replaced strlen(file_name->name) with file_name->len, and remained
in commit b8f2688258f8 ("inotify: Use strscpy() for event->name copies").

Switch to strscpy_pad() so any trailing bytes up to event->name_len + 1
are zeroed.

Fixes: ce163918cd33 ("inotify_handle_event(): don't bother with strlen()")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Gwanhyun Lee <gwanhyunlee@xxxxxxxxx>
Signed-off-by: Gwanhyun Lee <gwanhyunlee@xxxxxxxxx>
Signed-off-by: Junyoung Jang <graypanda.inzag@xxxxxxxxx>
---
fs/notify/inotify/inotify_fsnotify.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
index 6e3af6452dcc..78eb1e92a14c 100644
--- a/fs/notify/inotify/inotify_fsnotify.c
+++ b/fs/notify/inotify/inotify_fsnotify.c
@@ -121,7 +121,7 @@ int inotify_handle_inode_event(struct fsnotify_mark *inode_mark, u32 mask,
event->sync_cookie = cookie;
event->name_len = len;
if (len)
- strscpy(event->name, name->name, event->name_len + 1);
+ strscpy_pad(event->name, name->name, event->name_len + 1);

ret = fsnotify_add_event(group, fsn_event, inotify_merge);
if (ret) {
--
2.43.0