From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=43.163.128.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796056601; b=a1usLzus862ND4VH0+N0kNc7hhYE8UPBPwgmG4Jv352+0+Kb8ZUAizyyMEfXU3JdLuHj ky8y24qaeW6kJ3VDvbwlwQ5R196e+0MXIw0GYHcZ5wr4r0zqFb3R65ddacP3i6+jLwECu 9GRW614lVBV39J5BAm5C/2kba3jia7u2exNqI9yJlEXqYeL4KWuDkSIV2QjM/xeJFjmvX BDg/UHPsaMIMD29iYM1XbPIe9vBQyyRhFYzABnAYLDXn+XtCVWb8P1KouE2COUdjGIB6q B/lUhPxlOMM38SYbaIL1838cSLwnUKdAtRYNC/Q0aHJETIsVWN2BtRIusf6SHcxZrKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796056601; h=DMARC-Filter:DKIM-Signature:Received:X-QQ-mid:Message-ID: X-QQ-XMAILINFO:X-QQ-XMRINFO:From:To:Cc:Subject:Date:X-OQ-MSGID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=ja9dpTy3frFFCCxWQHEI0oOrzZcy6I+eYnr9o5I2Ps4=; b=iZfiLtK7OWzsKx5e4GcwvyI119MXGb6FK1GqBk8mg8T/Yt5DT8GBx9Ulk/KJQy3FPUxQ yh790Xfk/dLrhL/MWFnf7vEnAqTg4s903c6GhBPv5kKrAkH+Jpw9E/whDP6Iv/hQ2Ppbw nLGhaEAoTggEN+etwuP4ZbJU25ih65/yQl7ESP1uWuugwALrDCAF2qIufycKVCixSil0r ftI7+82mxVA8c4c9VIAvTE5Ui+wbfj1TgK3DDxkLbD34shDQV4G7V7jiDjolAAHpBo3qO i9E+VjRU/Wi3eS4vwiQj00mgzJAMVykaN/UKTe7dcCtL5wD+PllZ3nbh0vIo91IZKew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=HQd20sG6; arc=none smtp.remote-ip=43.163.128.53 Received: from xmbghk7.mail.qq.com (xmbghk7.mail.qq.com [43.163.128.53]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FB77606A31C; Mon, 30 Nov 2026 16:36:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9FB77606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=HQd20sG6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1796056589; bh=ja9dpTy3frFFCCxWQHEI0oOrzZcy6I+eYnr9o5I2Ps4=; h=From:To:Cc:Subject:Date; b=HQd20sG6/pXLVqOO5w/uPijFnqCvWG3uZENvcEGH3Zn5IkXYUpIEjitvprpwn+0Mf olkde4iwCpZ164FzM1bnD+FAek/CoVAm7xlw5/dKnaWpSnFiNWwexzhc/UnzppzeCu fB09+BQ1Yw6rZ6i/qQU2D1bHws9692rxRiYdCmMo= Received: from [172.18.4.77] ([202.113.185.209]) by newxmesmtplogicsvrsza53-0.qq.com (NewEsmtp) with SMTP id 91B998B3; Tue, 01 Dec 2026 00:36:27 +0800 X-QQ-mid: xmsmtpt1796056587tosoclm4a Message-ID: X-QQ-XMAILINFO: OYKM/pSuXZktsklcyXykPRBTIfkZF3/v4r2vuQLLsN4DvDwz87iRSY+psvMe/u BTXrZ0qGtvVx+dTXudtK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alws3A== From: Guikun Yang 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 X-OQ-MSGID: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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