From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382883; b=bGgLd3Sr8IwNFJB+eO0EMeNDSCxQ3sT9mr6+4/W7fjQwvwppmU0+Z/octqCSooq5qjuT ku3B1UHVMvLG+g9SUiA5lCN0v5E72owGdz8hXrJgjO8bi9PnRtZfZNKlvP/ZfUe9NNANj kAuKwYTYqRgTGagv4YYqek3R9qmcWnDNxmlLAf8AOhPBSacD0E1D3gtXDI53Fsb4R53OF FYcKvsrod4sl06Gb4NupFLPBgNDWdobjZYF72COX1d6edbjFq/jL/ydP/qju6orxpDXHm hHQA5Fg3aJK7Rx3BizTAkZrW7mC8SdDnLRgwbj7zVdp1ZQ09hVsTv1kLMclMaEIW8Xw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382883; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=QAkA6yZ7S+9qwZPqRj85pvYs9gFxTkuuzOi1VfmEXPM=; b=taOvdNbt5RcaC+W4WCS6/fC0vnvjrA8iY5wb4pOReajV2P37HpWTjA2OXWNXQy0NtNCt wMorCdaQ+qJwKep8TCYoarCgKT4syMmWw9kNOT2qvgYYu/dld0zLMIFN9RF+YhYcjhnVD /GS+ODk23vU4sOSZO0RgXzD2k0nRWbP19pSNkiof21hb6KRwthpdm9Y8ZyEnxwnF5Aa+l H3NkYTAPqB40c1miCR7q+xVtGz09fVJlP2adVLyCeAoVlIjfb525rI3JzjNx155JnLtBi SyABUHNRz8AIYUUT4bilm+OfItogeQWLvalFbq15cJrokV0Ev4rvyUhCl/n4FxttRsA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=T55Xe6pz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11C84606A33A; Fri, 4 Dec 2026 11:14:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=T55Xe6pz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F3E71F00939; Fri, 4 Dec 2026 11:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382882; bh=QAkA6yZ7S+9qwZPqRj85pvYs9gFxTkuuzOi1VfmEXPM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=T55Xe6pz602goXd2jMoj6DyokQ2OFTxiDQgB0zLUoLMOkF/rA2qMjEs9s/kJPq1jq ClGK57U9L/GZwcM+1sAxTkN1ES/HCJ9TnbYNDdqhwuoBEY9s2NR0wXZmV+tdH1uDVM qB+9tiW70/bw0aZlsxtOkp/+YKEsHYucjAKjT0+g= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhao Gongyi , Theodore Tso Subject: [PATCH 6.18 636/703] ext4: fix OOB memmove in ext4_xattr_set_entry Date: Fri, 4 Dec 2026 19:08:55 +0900 Message-ID: <20261204100644.701581127@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhao Gongyi commit e290c77088e6f829f7d1d88c915f2a2fb22241e6 upstream. A corrupted filesystem can leave an inode marked as having inline data while the system.data xattr is missing. ext4_destroy_inline_data_nolock() then asks ext4_xattr_set_entry() to remove an entry even though ext4_xattr_ibody_find() left the search state at the insertion position. In the syzkaller reproducer, the old xattr value offset is smaller than min_offs. ext4_xattr_set_entry() then computes val - first_val for memmove(), the length wraps to a huge size_t, and memmove() can run out of the xattr buffer. This results in an out-of-bounds memmove and a kernel page fault. A crafted corrupted ext4 image can trigger this while inline data is being converted out of the inode. Treat the inconsistent inline/xattr state as filesystem corruption before updating the xattr entry. The issue was found by syzkaller and reproduced with the generated C reproducer. The crash signature is: BUG: unable to handle page fault for address: ffff8880074cf000 RIP: 0010:memmove+0x28/0x1b0 Call Trace: ext4_xattr_set_entry+0xe2f/0x1e90 fs/ext4/xattr.c:1761 ext4_xattr_ibody_set+0x3d6/0x5d0 fs/ext4/xattr.c:2268 ext4_destroy_inline_data_nolock+0x288/0x5b0 fs/ext4/inline.c:467 ext4_convert_inline_data_nolock+0x178/0xe80 fs/ext4/inline.c:1222 ext4_convert_inline_data+0x52a/0x610 fs/ext4/inline.c:2083 ext4_fallocate+0x1a0/0x3ba0 fs/ext4/extents.c:4752 Reject the missing system.data xattr before destroying inline data, and validate the old value offset before ext4_xattr_set_entry() reaches the memmove(). The crash was reproduced on unpatched 7.3.0-rc3 and 6.6.122 kernels. With this fix applied to both versions, the same syzkaller C reproducer ran for 120 seconds without triggering KASAN, Oops, a memmove fault, or panic. Fixes: 67cf5b09a46f ("ext4: add the basic function for inline data support") Cc: stable@vger.kernel.org # v3.8+ Signed-off-by: Zhao Gongyi Link: https://patch.msgid.link/20260918101249.43643-1-zhaogongyi@bytedance.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/inline.c | 6 ++++++ fs/ext4/xattr.c | 12 ++++++++++++ 2 files changed, 18 insertions(+) --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -462,6 +462,12 @@ static int ext4_destroy_inline_data_nolo error = ext4_xattr_ibody_find(inode, &i, &is); if (error) goto out; + if (is.s.not_found) { + EXT4_ERROR_INODE(inode, + "corrupted inline data without system.data xattr"); + error = -EFSCORRUPTED; + goto out; + } BUFFER_TRACE(is.iloc.bh, "get_write_access"); error = ext4_journal_get_write_access(handle, inode->i_sb, is.iloc.bh, --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -1708,6 +1708,18 @@ static int ext4_xattr_set_entry(struct e } } + if (!s->not_found && here->e_value_size && !here->e_value_inum) { + size_t offs = le16_to_cpu(here->e_value_offs); + + if (offs < min_offs) { + EXT4_ERROR_INODE(inode, + "corrupted xattr: value offset %zu < min_offs %zu", + offs, min_offs); + ret = -EFSCORRUPTED; + goto out; + } + } + /* * Getting access to old and new ea inodes is subject to failures. * Finish that work before doing any modifications to the xattr data.