From: Namjae Jeon <linkinjeon@kernel.org>
To: Piyus Kedia <piyus@iiitd.ac.in>
Cc: linux-cifs@vger.kernel.org,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Tom Talpey <tom@talpey.com>,
ChenXiaoSong <chenxiaosong@chenxiaosong.com>,
linux-kernel@vger.kernel.org,
Kapil Vaswani <kapil@presceralabs.ai>
Subject: Re: [PATCH v2] ksmbd: do not read past a directory entry name in __query_dir()
Date: Sun, 6 Dec 2026 16:04:33 +0900 [thread overview]
Message-ID: <CAKYAXd9GQDecLjuzH2v+fDUijDp6FSBj2_99hOhHY8ryPDDTvw@mail.gmail.com> (raw)
In-Reply-To: <20261205195745.508424-1-piyus@iiitd.ac.in>
On Sun, Dec 6, 2026 at 4:57 AM Piyus Kedia <piyus@iiitd.ac.in> wrote:
>
> __query_dir(), the iterate_dir() actor of SMB2 QUERY_DIRECTORY, gets
> each entry as a name and a length, and the name need not be
> NUL-terminated: ext2, ext4 without dir_index, xfs, btrfs, f2fs and fuse
> pass a pointer into their own directory buffers. Three of its checks
> read it as a C string:
>
> - strcmp() against "." and "..";
>
> - ksmbd_share_veto_filename(), whose match_wildcard() walks the name
> up to a NUL;
>
> - match_pattern(), which is given the length but walks
> while (*s && len), and decrements len only when a character is
> consumed by a match. A mismatch after a '*' restarts the comparison
> one character further on (str++; s = str;) and leaves len alone, so
> after a mismatch at the first character of an attempt len
> overstates what is left, and the walk goes on to a NUL; after a
> partial match of two or more characters it understates it, and the
> walk stops early.
>
> On ext4 without dir_index, an inline directory's names are emitted
> from a kmalloc()ed copy of the inline data, and a 48-byte name ends at
> the end of that 60-byte buffer. A search pattern of "*Z" then reads
> past it in match_pattern(), and on a share with a veto list such as
> "*.tmp" any QUERY_DIRECTORY reads past it in match_wildcard():
>
> BUG: KASAN: slab-out-of-bounds in match_pattern (fs/smb/server/misc.c:36)
> Read of size 1 at addr ffff88801bbff8bc by task kworker/0:2/55
> Workqueue: ksmbd-io handle_ksmbd_work
> match_pattern (fs/smb/server/misc.c:36)
> __query_dir (fs/smb/server/smb2pdu.c:6841)
> ext4_read_inline_dir (fs/ext4/inline.c:1539)
> ext4_readdir (fs/ext4/dir.c:165)
> iterate_dir (fs/readdir.c:114)
> smb2_query_dir (fs/smb/server/smb2pdu.c:7034)
>
> BUG: KASAN: slab-out-of-bounds in match_wildcard (lib/parser.c:290)
> Read of size 1 at addr ffff888048c3823c by task kworker/1:1/53
> Workqueue: ksmbd-io handle_ksmbd_work
> match_wildcard (lib/parser.c:290)
> ksmbd_share_veto_filename (fs/smb/server/mgmt/share_config.c:370)
> __query_dir (fs/smb/server/smb2pdu.c:6839)
> ext4_read_inline_dir (fs/ext4/inline.c:1539)
>
> (both: 0 bytes to the right of a 60-byte region in kmalloc-64,
> allocated by ext4_read_inline_dir() at fs/ext4/inline.c:1439)
>
> What lies past the name also decides the answer: in an ext4 directory
> without dir_index, "file.txt" followed by another entry is not listed
> for "*.txt", because the walk takes in the next entry's inode number.
> And the miscount gets terminated names wrong as well: "aaab" does not
> match "*aab", and "aaaaab" matches "aa*aa".
>
> Make all three checks go by the length. Use name_is_dot_dotdot() for
> "." and "..". Add ksmbd_share_veto_filename_len(), which matches the
> veto patterns with a copy of match_wildcard() bounded by the length, so
> the veto rules themselves do not change; the open and rename paths,
> whose names are NUL-terminated, keep ksmbd_share_veto_filename(). And
> bound match_pattern() by a pointer to the end of the name instead of a
> count, so that restarting the comparison needs no bookkeeping.
>
> We found this with a syzkaller-based fuzzing harness driven by an AI tool.
>
> Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
> Closes: https://lore.kernel.org/linux-cifs/ksmbd-match-pattern-overread.20261205@iiitd.ac.in/
> Cc: stable@vger.kernel.org
> Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
> Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
Applied it to #ksmbd-for-next.
Thanks.
prev parent reply other threads:[~2026-12-06 7:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 10:17 [BUG] ksmbd: slab-out-of-bounds reads " Piyus Kedia
2026-12-05 10:17 ` [PATCH] ksmbd: do not read " Piyus Kedia
2026-12-05 12:41 ` Namjae Jeon
2026-12-05 20:23 ` Piyus Kedia
2026-12-05 19:57 ` [PATCH v2] " Piyus Kedia
2026-12-06 7:04 ` Namjae Jeon [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=CAKYAXd9GQDecLjuzH2v+fDUijDp6FSBj2_99hOhHY8ryPDDTvw@mail.gmail.com \
--to=linkinjeon@kernel.org \
--cc=chenxiaosong@chenxiaosong.com \
--cc=kapil@presceralabs.ai \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=piyus@iiitd.ac.in \
--cc=senozhatsky@chromium.org \
--cc=tom@talpey.com \
/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®