From: Junyoung Jang <graypanda.inzag@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>, Jan Kara <jack@suse.cz>
Cc: Junyoung Jang <graypanda.inzag@gmail.com>,
Amir Goldstein <amir73il@gmail.com>,
Matt Bobrowski <matt@bobrowski.net>,
Gwanhyun Lee <gwanhyunlee@gmail.com>,
fuse-devel@lists.linux.dev, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH v2 3/3] fanotify: copy full qstr length for copied event names
Date: Tue, 17 Nov 2026 22:51:37 +0900 [thread overview]
Message-ID: <20261117135146.3174252-4-graypanda.inzag@gmail.com> (raw)
In-Reply-To: <20261117135146.3174252-1-graypanda.inzag@gmail.com>
fanotify_alloc_name_event() reserves name->len + 1 bytes for each
copied name in a kvmalloc() event. fanotify_info_copy_name() and
fanotify_info_copy_name2() use strscpy(), which stops at an embedded NUL
and leaves the remaining name bytes uninitialized. With the original
length stored in info->name_len or info->name2_len,
copy_fid_info_to_user() copies name_len + 1 bytes to userspace, leaking
uninitialized kernel heap memory.
Use memcpy() for the full qstr length and write the terminator
separately, consistent with __d_alloc() and d_path().
Fixes: 929943b38daf ("fanotify: add support for FAN_REPORT_NAME")
Cc: stable@vger.kernel.org
Co-developed-by: Gwanhyun Lee <gwanhyunlee@gmail.com>
Signed-off-by: Gwanhyun Lee <gwanhyunlee@gmail.com>
Signed-off-by: Junyoung Jang <graypanda.inzag@gmail.com>
---
Changes in v2:
- Use memcpy() for both copied names, as suggested by Amir Goldstein.
- Write each terminator explicitly without reading past the source qstr.
FUSE fanotify mark setup on a zero-fsid mount returned -ENODEV; the
normal-name FAN_REPORT_DFID_NAME and FAN_RENAME paths were tested on tmpfs.
fs/notify/fanotify/fanotify.h | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h
index c25cf5c1fc70..2d6b5c2c6f25 100644
--- a/fs/notify/fanotify/fanotify.h
+++ b/fs/notify/fanotify/fanotify.h
@@ -221,18 +221,26 @@ static inline void fanotify_info_set_file_fh(struct fanotify_info *info,
static inline void fanotify_info_copy_name(struct fanotify_info *info,
const struct qstr *name)
{
+ char *dst;
+
if (WARN_ON_ONCE(info->name2_len > 0))
return;
info->name_len = name->len;
- strscpy(fanotify_info_name(info), name->name, name->len + 1);
+ dst = fanotify_info_name(info);
+ memcpy(dst, name->name, name->len);
+ dst[name->len] = '\0';
}
static inline void fanotify_info_copy_name2(struct fanotify_info *info,
const struct qstr *name)
{
+ char *dst;
+
info->name2_len = name->len;
- strscpy(fanotify_info_name2(info), name->name, name->len + 1);
+ dst = fanotify_info_name2(info);
+ memcpy(dst, name->name, name->len);
+ dst[name->len] = '\0';
}
/*
next prev parent reply other threads:[~2026-11-17 13:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 13:51 [PATCH v2 0/3] fuse, fsnotify: handle embedded NUL names safely Junyoung Jang
2026-11-17 13:51 ` [PATCH v2 1/3] fuse: skip dcache instantiation for readdirplus names with embedded NUL Junyoung Jang
2026-11-17 14:35 ` Amir Goldstein
2026-11-17 13:51 ` [PATCH v2 2/3] inotify: copy full qstr length for event names Junyoung Jang
2026-11-17 14:31 ` Amir Goldstein
2026-11-17 13:51 ` Junyoung Jang [this message]
2026-11-17 14:33 ` [PATCH v2 3/3] fanotify: copy full qstr length for copied " Amir Goldstein
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=20261117135146.3174252-4-graypanda.inzag@gmail.com \
--to=graypanda.inzag@gmail.com \
--cc=amir73il@gmail.com \
--cc=fuse-devel@lists.linux.dev \
--cc=gwanhyunlee@gmail.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matt@bobrowski.net \
--cc=miklos@szeredi.hu \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®