From: Kees Cook <kees@kernel.org>
To: Fedor Pchelkin <pchelkin@ispras.ru>
Cc: "Theodore Ts'o" <tytso@mit.edu>, 李龙兴 <coregee2000@gmail.com>,
"Andreas Dilger" <adilger.kernel@dilger.ca>,
"Andy Shevchenko" <andriy.shevchenko@intel.com>,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org, "Jan Kara" <jack@suse.cz>
Subject: Re: [PATCH] ext4: Reject on-disk mount options with missing NUL-terminator
Date: Mon, 9 Feb 2026 12:00:36 -0800 [thread overview]
Message-ID: <202602091148.EDBFECE686@keescook> (raw)
In-Reply-To: <20260209193945-80d9bfc8aa82b0eb1b764c7f-pchelkin@ispras>
On Mon, Feb 09, 2026 at 08:27:50PM +0300, Fedor Pchelkin wrote:
> Kees Cook wrote:
> > ee5a977b4e77 ("ext4: fix string copying in parse_apply_sb_mount_options()")
> > Notices the loud failures of strscpy_pad() introduced by 8ecb790ea8c3,
> > and attempted to silence them by making the destination 64 and rejecting
> > too-long strings from the on-disk copy of s_mount_opts, but didn't
> > actually solve it at all, since the problem was always the over-read
> > of the source seen by strnlen(). (Note that the report quoted in this
> > commit exactly matches the report today.)
> >
>
> [...]
>
> > Reported-by: 李龙兴 <coregee2000@gmail.com>
> > Closes: https://lore.kernel.org/lkml/CAHPqNmzBb2LruMA6jymoHXQRsoiAKMFZ1wVEz8JcYKg4U6TBbw@mail.gmail.com/
> > Fixes: ee5a977b4e77 ("ext4: fix string copying in parse_apply_sb_mount_options()")
>
> Hi there,
>
> [ I'd better be Cc'ed as the author of the commit in Fixes ]
Agreed! Sorry I missed adding you to Cc.
> The mentioned reports are for v6.18.2 kernel while ee5a977b4e77 ("ext4:
> fix string copying in parse_apply_sb_mount_options()") landed in v6.18.3.
> Back at the time I've tested the patch with different bogus s_mount_opts
> values and the fortify warnings should have been gone.
Ah-ha! Okay, thank you for catching this versioning issue. I had been
scratching my head over how it could have been the same warning. This
report is effectively a duplicate of the report you fixed with
ee5a977b4e77.
> I don't think there is an error in ee5a977b4e77 unless these warnings
> actually appear on the latest kernels with ee5a977b4e77 applied.
>
> > @@ -2485,6 +2485,13 @@ static int parse_apply_sb_mount_options(struct super_block *sb,
> > if (!sbi->s_es->s_mount_opts[0])
> > return 0;
> >
> > + if (strnlen(sbi->s_es->s_mount_opts, sizeof(sbi->s_es->s_mount_opts)) ==
> > + sizeof(sbi->s_es->s_mount_opts)) {
> > + ext4_msg(sb, KERN_ERR,
> > + "Mount options in superblock are not NUL-terminated");
> > + return -EINVAL;
> > + }
>
> strscpy_pad() returns -E2BIG if the source string was truncated. This
> happens for the above condition as well - the last byte is truncated and
> replaced with a NUL-terminator.
Yeah, I've double-checked this now. The second half of the overflow
check in the fortified strnlen eluded by eyes when I went through this
originally. Thanks for sanity checking this!
> The check at 3db63d2c2d1d ("ext4: check if mount_opts is NUL-terminated in
> ext4_ioctl_set_tune_sb()") was done in that manner as there is currently
> no way to propagate strscpy_pad() return value up from ext4_sb_setparams().
> So the string is independently checked inside ext4_ioctl_set_tune_sb()
> directly.
>
>
> As for the 64/65 byte length part, now the rationale of the checks works
> as Darrick Wong described at the other part of this thread and corresponds
> to how relevant userspace stuff treats the s_mount_opts field: the buffer
> is at most 63 payload characters long + NUL-terminator. Jan Kara also
> shared similar thoughts during the discussion of ee5a977b4e77 [1].
>
> [1]: https://lore.kernel.org/linux-ext4/yq6rbx54jt4btntsh37urd6u63wwcd3lyhovbrm6w7occaveea@riljfkx5jmhi/
Okay, great. I figure I can do two things:
1) rework this patch with adjusted commit log to reflect the notes
raised so far, so that we reject mounts that lack a NUL-terminated
s_mount_opts (as silent truncation may induce an unintended option
string, e.g. "...,journal_path=/dev/sda2" into "...,journal_path=/dev/sda"
or something weird like that).
2) Leave everything as-is, live with above corner case since it should
be unreachable with userspace tooling as they have always existed.
I'm fine either way! :)
-Kees
--
Kees Cook
next prev parent reply other threads:[~2026-02-09 20:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-06 21:27 [PATCH] ext4: Reject on-disk mount options with missing NUL-terminator Kees Cook
2026-02-06 21:45 ` Darrick J. Wong
2026-02-06 21:56 ` Kees Cook
2026-02-08 13:43 ` Andy Shevchenko
2026-02-09 17:27 ` Fedor Pchelkin
2026-02-09 20:00 ` Kees Cook [this message]
2026-02-10 5:01 ` Darrick J. Wong
2026-02-10 9:03 ` Fedor Pchelkin
2026-02-11 1:50 ` Kees Cook
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=202602091148.EDBFECE686@keescook \
--to=kees@kernel.org \
--cc=adilger.kernel@dilger.ca \
--cc=andriy.shevchenko@intel.com \
--cc=coregee2000@gmail.com \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pchelkin@ispras.ru \
--cc=tytso@mit.edu \
/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