From: Andrew Morton <akpm@linux-foundation.org>
To: Zhan Xusheng <zhanxusheng1024@gmail.com>
Cc: Joseph Qi <joseph.qi@linux.alibaba.com>,
Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, zhanxusheng@xiaomi.com
Subject: Re: [PATCH] ocfs2: bound-check dir entries in the readdir re-validation scan
Date: Thu, 6 Aug 2026 13:29:11 -0700 [thread overview]
Message-ID: <20260806132911.57ad21a8be14277f298f8a89@linux-foundation.org> (raw)
In-Reply-To: <20260806122133.956847-1-zhanxusheng@xiaomi.com>
On Thu, 6 Aug 2026 20:21:33 +0800 Zhan Xusheng <zhanxusheng1024@gmail.com> wrote:
> When the inode version changed since the last readdir(),
> ocfs2_dir_foreach_blk_el() re-scans the directory block from its start to
> relocate the current position:
>
> for (i = 0; i < sb->s_blocksize && i < offset; ) {
> de = (struct ocfs2_dir_entry *)(bh->b_data + i);
> if (le16_to_cpu(de->rec_len) < OCFS2_DIR_REC_LEN(1))
> break;
> i += le16_to_cpu(de->rec_len);
> }
>
> The loop dereferences de->rec_len (at byte offset 8 within the entry)
> guarded only by i < sb->s_blocksize. `offset` is derived from ctx->pos,
> which userspace controls via lseek() on the directory fd, so i can reach
> the last bytes of the block; reading de->rec_len then reads a few bytes
> past the s_blocksize-sized block buffer (an out-of-bounds read).
>
> The main emit loop below already guards this via ocfs2_check_dir_entry(),
> which rejects entries too close to the buffer end before touching de.
> Apply the same lower bound to the re-validation scan so that a full
> minimal directory entry is known to fit before de is dereferenced. For a
> consistent directory this changes nothing: entries are at least
> OCFS2_DIR_REC_LEN(1) bytes, so no valid entry starts in the excluded tail.
>
> Found by the sashiko review tool; fix approach suggested by Joseph Qi.
Thanks.
When fixing a bug, please always describe the userspace-visible runtime
effects of that bug.
> Suggested-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> Fixes: ccd979bdbce9 ("[PATCH] OCFS2: The Second Oracle Cluster Filesystem")
> Cc: stable@vger.kernel.org
Especially when proposing a backport.
I asked Gemini "what are the userspace-visible effects of this bug"
then pasted in your email. The answer was, basically, "there aren't any".
https://share.gemini.google/FiBJNo4qIz7J
So I don't believe that a cc:stable is justified,
Documentation/process/stable-kernel-rules.rst says "it must fix a real
bug that bothers people".
So if maintainers are agreeable I think I'll remove that cc:stable.
But I think the -stable maintainers will go and backport it anyway
because of the Fixes: (thereby breaking their own rules ;)). We can
stop that happening by removing the Fixes: also.
> Link: https://sashiko.dev/#/patchset/20260806022044.167962-1-zhanxusheng@xiaomi.com
Your patch prompted Sashiko to complain about more pre-existing things:
https://sashiko.dev/#/patchset/20260806122133.956847-1-zhanxusheng@xiaomi.com
Anyway, I'll queue this one and shall await maintainer input.
next prev parent reply other threads:[~2026-08-06 20:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 12:21 Zhan Xusheng
2026-08-06 20:29 ` Andrew Morton [this message]
2026-08-11 1:00 ` Joseph Qi
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=20260806132911.57ad21a8be14277f298f8a89@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=jlbec@evilplan.org \
--cc=joseph.qi@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark@fasheh.com \
--cc=ocfs2-devel@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=zhanxusheng1024@gmail.com \
--cc=zhanxusheng@xiaomi.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®