From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C3E347CA8E; Tue, 25 Aug 2026 13:59:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787666374; cv=none; b=ow32DGUaAD1vBNuacXZTYelkTmwnwuLvIiqOaNrY8GPoJ8lW427v2bpxKgqQWR4MXVdfgsi0eURGzJKs5obIA11FVAA+vWOio67G2vAVN8/Etk6Fh2y8526jLFdSVWvE+OJ+Kqy+Ia+trzK77y1D8hDLH3Nw/a6zCiuvEHvKF/0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787666374; c=relaxed/simple; bh=qIs4gP8vqmZJjTbHizawTyqkBt5HB0lf1X6OG4NK6BU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qz0X/SMIB6rfQIR25mQEp9Opn1pYoxwMtlbLC8Y1Od4wsyI/vAE5G727xTV4h0zfDNRGwTX79VJNnK4EkyBkGESzmMJiX708/WWEFtRSDjFlPR0ifNtsLNT4i7Iha4TpEDonuDqqSJdrjKQfGXiH6GKt7fdrUjawIWcTvB55nCE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Pwtjvpzn; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Pwtjvpzn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 761F21F000E9; Tue, 25 Aug 2026 13:59:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1787666373; bh=0yt70bBLuyqIq4u2shP31kbH6mLYT/UpzhtZxN8jD+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PwtjvpznsKQWfv7YQ1+sdoqQt+gNE2r+HYgrm/8v7YT4um+SA1aIeWGEJjfrLZtPW GbG2HNPyIFoWg1S8eHHRCIz4wXB2eILcVHVA9ByMTDsbv7OAlb7bGyCdYIic8dAyyg cE7pSj3mD4Q9O/PSGIZ7MMlbsr5jSTS5WOs1IfyY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ian Bridges , syzbot+e538032956b1157914a3@syzkaller.appspotmail.com, Joseph Qi , Mark Fasheh , Joel Becker , Junxiao Bi , Changwei Ge , Jun Piao , Heming Zhao , Andrew Morton Subject: [PATCH 5.10 03/57] ocfs2: fix missing metadata reservation for large xattrs Date: Tue, 25 Aug 2026 15:26:25 +0200 Message-ID: <20260825132541.463328641@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260825132541.342390421@linuxfoundation.org> References: <20260825132541.342390421@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ian Bridges commit 0cdc7dde00ec63ac714271fa8b2918d630b8da1a upstream. [BUG] lsetxattr() panics the kernel when setting a large xattr value on a fragmented filesystem where the file already has an external xattr block. [CAUSE] ocfs2_calc_xattr_set_need() never reserves metadata blocks for a new xattr value's extent tree when the file already has an external xattr block. The not_found path leaves meta_add at zero, so meta_ac is NULL when ocfs2_xattr_extend_allocation() runs. A new value root has room for a single extent record. On a fragmented filesystem, the allocator cannot satisfy the xattr value in one contiguous run, so each non-contiguous run requires its own extent record. When the value root's extent list is full and meta_ac is NULL, ocfs2_add_clusters_in_btree() returns RESTART_META, and ocfs2_xattr_extend_allocation() hits BUG_ON(why == RESTART_META). [FIX] The case where no xattr block exists yet already calls ocfs2_extend_meta_needed(&def_xv.xv.xr_list) to reserve value tree metadata. Add the same reservation to the case where an xattr block already exists, making the two cases consistent. Replace the BUG_ON with a -ENOSPC return so that if RESTART_META is returned despite the reservation, the error propagates to userspace instead of panicking the kernel. Link: https://lore.kernel.org/amLwn3i9tET8yhG7@dev Fixes: a78f9f466894 ("ocfs2: make xattr extension work with new local alloc reservation.") Signed-off-by: Ian Bridges Reported-by: syzbot+e538032956b1157914a3@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=e538032956b1157914a3 Reviewed-by: Joseph Qi Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Changwei Ge Cc: Jun Piao Cc: Heming Zhao Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- fs/ocfs2/xattr.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -742,12 +742,10 @@ static int ocfs2_xattr_extend_allocation prev_clusters; if (why != RESTART_NONE && clusters_to_add) { - /* - * We can only fail in case the alloc file doesn't give - * up enough clusters. - */ - BUG_ON(why == RESTART_META); - + if (why == RESTART_META) { + status = -ENOSPC; + break; + } credits = ocfs2_calc_extend_credits(inode->i_sb, &vb->vb_xv->xr_list); status = ocfs2_extend_trans(handle, credits); @@ -3217,6 +3215,14 @@ meta_guess: credits += OCFS2_SUBALLOC_ALLOC + 1; /* + * Reserve metadata for the new xattr's value extent tree. + * The not_found path above adds credits for this tree but + * omits meta_add, leaving meta_ac NULL for large values. + */ + if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) + meta_add += ocfs2_extend_meta_needed(&def_xv.xv.xr_list); + + /* * This cluster will be used either for new bucket or for * new xattr block. * If the cluster size is the same as the bucket size, one