From: Guikun Yang <yangguikun19@qq.com>
To: linux-ext4@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [Bug report] ext4: EXT4_IOC_MOVE_EXT with len == 0 clamps the length to the whole origin file and overwrites the donor
Date: Tue, 01 Dec 2026 00:40:00 +0800 [thread overview]
Message-ID: <tencent_222E4C65A3387C84A3C85205BE2B46649D09@qq.com> (raw)
Hi Ted, Jan,
A regular (non-corrupted) ext4 filesystem lets EXT4_IOC_MOVE_EXT with
me.len == 0 destroy the donor file's data. The ioctl returns 0 with
moved_len == 1; after a remount the donor file is left empty and
e2fsck reports a clean filesystem throughout.
## The clamp turns 0 into the whole file
fs/ext4/move_extent.c, mext_check_adjust_range():
if (orig_eof <= orig_start)
*len = 0;
else if (orig_eof < orig_start + *len - 1)
*len = orig_eof - orig_start;
if (donor_eof <= donor_start)
*len = 0;
else if (donor_eof < donor_start + *len - 1)
*len = donor_eof - donor_start;
if (!*len)
return -EINVAL;
With *len == 0 and orig_start == 0, "orig_start + *len - 1" evaluates
to U64_MAX, the second comparison is true, and *len is assigned
orig_eof - orig_start, i.e. the whole origin file. The subsequent
"!*len" check passes because *len is no longer zero, and the main loop
in ext4_move_extents() moves the clamped length as usual.
f18b2b83a727 ("ext4: fix argument checking in EXT4_IOC_MOVE_EXT")
added the start-beyond-EOF branches to this function, but the
zero-length request still slips through the "len should not be 0"
check, because the underflow above it rewrites *len before the check
runs.
## Reproducer
Two regular files on the same clean ext4 filesystem, origin larger
than donor:
ioctl(orig_fd, EXT4_IOC_MOVE_EXT, &(struct move_extent){
.orig_start = 0, .donor_start = 0, .len = 0,
.donor_fd = donor_fd, .moved_len = 0 });
returns 0, me.moved_len == 1 for the one-block donor; the donor file
is left empty, the change is crossmount-persistent and the original
donor contents are unrecoverable. e2fsck reports no errors before
or after.
The reproducer is the ioctl sequence above on a clean ext4 image with
two regular files; no special image layout is required.
## Fix direction
Reject the zero length before the underflow comparison, e.g. in
ext4_move_extents() right after locking:
if (!len)
return -EINVAL;
The new KUnit suite
(ext4_mext_check_adjust_range_test(), 0940fb9b934c) covers the
"start beyond EOF clamps len to 0" case but has no len == 0 input
case; adding one would keep this from regressing.
The clamp logic is unchanged on mainline as of 2026-11-30
(move_extent.c:557-564) and in v6.19.5.
Thanks,
Guikun
next reply other threads:[~2026-11-30 16:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 16:40 Guikun Yang [this message]
2026-12-01 5:18 ` Theodore Tso
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=tencent_222E4C65A3387C84A3C85205BE2B46649D09@qq.com \
--to=yangguikun19@qq.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@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®