From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78B9D358D00 for ; Fri, 8 May 2026 09:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778230812; cv=none; b=GRXh0M2yCb+1S//3RLpxNn0wyGmpgWleuTLOwNPMrFlYILkXY48RjAwJ5N1g3m4XbIZIgfVhV2J9LqErQZvfBKUs9zoLqQiWr9ChCJyo2XCJMlv6moOZkDB7YHVV0pGkzfQGlKJ0m+mmN7vVv/GwcQWEiM5IZU9xIybyML95y6k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778230812; c=relaxed/simple; bh=+3eeuhMFHiZpEQg2KROqb6kAg440DvMXMgb6MfwVrE0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BvU5F2u0T/xLjkzMFelQ4L5ZWjGB+lPnrNHTetg6zHZKaPQnFmiPVhfD02do6C58VJf6hGFbbLH3PKBbDszt5uAOYdIG0OhlHE18gjMIWnf3xkAt7QVvMGc3GIOIuoxDx9qvRjwaVFJLSkShxjCEy7uwWHDNUxnI3RDKol7vkUU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=myL0XPO2; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="myL0XPO2" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-3660daea6a5so869247a91.1 for ; Fri, 08 May 2026 02:00:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778230811; x=1778835611; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hICkrsufTPcAiO+G0L5Bnkf3gB8EUfqghx2E/DerwaM=; b=myL0XPO2ra+NO9LgZYgyOEa8hIFU1wHDWi4/ZeN+Svhr11eYZJTKRcEq5Y0mJQ4lqp G5ViCh6Dwz9h5/PKBDYTOb+qBaR6Fy8UrXPysU6HicA1fZjG/1mOr6+NXZPPJD1BruzC EQ6669RJEdG8hVaSuTCTCdJx9o77PO1spuk/9ijBR+PEEdFSacye9Gl9ebMMtrkDCDdl oVFPUkgpLSK/h80FymXP2wh0tWBd/VSIKJwiDDhEn86o+OPiD5qcROgtoE0a/U1dAcpQ Y88TnI4QAsdIP/+vLcnvibrjWVfGE6zqZY+p7lzaYsFNT2LXqKoY8LnytNhpLCW/31UU mizQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778230811; x=1778835611; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=hICkrsufTPcAiO+G0L5Bnkf3gB8EUfqghx2E/DerwaM=; b=SoTroJgaiwSEJH5XnwjBQVWv8bRYXj4uTHalBsWsDrlBfNIj+HxN2WV3iDXD9YmkUa ZcGkT8ZU9kEPMtQv0fhJTWMSOffcn3WZXmy3xOC3fcNL6nxiTdiefXw9nRzGszpg1xSG nygRNHRqbBoaq9yBn5StHp0lVMiVYW2X5r/D+J02VIg56ZXZsyT1kyhNhK5DS9BKE8nn W7lH6bqib408VcB9zznyNcrWqIxhMOAzCWbKOFOw1eGqeWC4dvSVLS4Gksph+SyL5xh6 zmcnCa3ZvsmpyI0McPVA1VpY54c53R7TIEPBbrrIBJ5zmmb2JDiX+SircIRybFkhGq80 VqHg== X-Forwarded-Encrypted: i=1; AFNElJ/K3annp0WqsChII9JMNsgjvpxVmlkW1rIeCvKE40VA4Ml2TMoNI0KYyqN7Pn4S1v/C8GTDCrnumLqFLGw=@vger.kernel.org X-Gm-Message-State: AOJu0Yyjwp35h3UyAH2PKcin4xtC9VNLUXm+ieaJpGuouBVPRUoEePnh kC673zy/1dUVsi/J74xRT6xDqDdsVOySYRPrVCi1Hnn2xRf47BYseJWf X-Gm-Gg: Acq92OGR9vNS7j7Ujse22cKhCzINFQ8LkMCrDSLbW56/hCR9A74rxmVnKWA+n9tLVbY 0AtHhb5GqCpm68y0OLe+IsCfa9x8C/gz/nXjNugcv/XSUTPcWhnA8e9RqeTJmoYWcmhD6Th5z4P a3RX6AJ4PyfW7fnum+lGou9gRn6xYm48Cw0XzJLm9bEm1ZQf3AbLBO0WiVKnxxCJSHZfSmGnL19 /QDpaIamjGDiBKo0hi4uAHGN8eb/eFOc83TSi0+ghw62hE5osSYdsGO8U3Deqxag/xqshGdZB/x dkmzqMbenYoQyalwENz8mUFSHEHmL+1UcLwR6lc34xBFDmFREKF0TpaRnmuQKZ3o1oJ0SmtXgKm sg8BU/7crRRhDJubgoekku5E9M0bpWHZKZr5J1mapg1v0iP9rD5fmk3QQWK7ki6ACaho+3r8iiE Xk/UAnYKX/Sq7Pwzf+WoHopyXeyKP7LN90T/3PeaAhH4BVzntZ/glL9VlsgwzsgkHd4Q6CkSYgM fonuBC11bWab7Hpk8j/hD4y4g== X-Received: by 2002:a17:903:1a2c:b0:2b4:6470:760d with SMTP id d9443c01a7336-2ba78f473a2mr128246185ad.14.1778230810627; Fri, 08 May 2026 02:00:10 -0700 (PDT) Received: from localhost.localdomain ([111.202.175.43]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1d2709bsm15526795ad.5.2026.05.08.02.00.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 08 May 2026 02:00:10 -0700 (PDT) From: ZhengYuan Huang To: mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com Cc: ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com, r33s3n6@gmail.com, zzzccc427@gmail.com, ZhengYuan Huang Subject: [PATCH 5/5] ocfs2: validate inline xattr header before reflinking inline xattrs Date: Fri, 8 May 2026 16:59:14 +0800 Message-ID: <20260508085914.61647-6-gality369@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260508085914.61647-1-gality369@gmail.com> References: <20260508085914.61647-1-gality369@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit [BUG] A corrupt inline xattr header can make ocfs2_reflink_xattr_inline() lock, copy, and reflink xattr state from an unchecked ibody xattr header. [CAUSE] The inline reflink path still trusted di->i_xattr_inline_size to compute header_off, xh, and new_xh before handing the source header to the reflink allocator and copy logic. [FIX] Validate the source inode's inline xattr header with the shared helper first, then derive the reflink copy offsets from the validated inline size/header. This keeps the reflink path from traversing corrupt ibody xattr geometry. Signed-off-by: ZhengYuan Huang --- fs/ocfs2/xattr.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 4877406a83ce..fcddd3c13acd 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -6511,12 +6511,10 @@ static int ocfs2_reflink_xattr_inline(struct ocfs2_xattr_reflink *args) handle_t *handle; struct ocfs2_super *osb = OCFS2_SB(args->old_inode->i_sb); struct ocfs2_dinode *di = (struct ocfs2_dinode *)args->old_bh->b_data; - int inline_size = le16_to_cpu(di->i_xattr_inline_size); - int header_off = osb->sb->s_blocksize - inline_size; - struct ocfs2_xattr_header *xh = (struct ocfs2_xattr_header *) - (args->old_bh->b_data + header_off); - struct ocfs2_xattr_header *new_xh = (struct ocfs2_xattr_header *) - (args->new_bh->b_data + header_off); + int inline_size; + int header_off; + struct ocfs2_xattr_header *xh; + struct ocfs2_xattr_header *new_xh; struct ocfs2_alloc_context *meta_ac = NULL; struct ocfs2_inode_info *new_oi; struct ocfs2_dinode *new_di; @@ -6525,6 +6523,15 @@ static int ocfs2_reflink_xattr_inline(struct ocfs2_xattr_reflink *args) .vb_access = ocfs2_journal_access_di, }; + ret = ocfs2_xattr_ibody_lookup_header(args->old_inode, di, &xh); + if (ret) + goto out; + + inline_size = le16_to_cpu(di->i_xattr_inline_size); + header_off = osb->sb->s_blocksize - inline_size; + new_xh = (struct ocfs2_xattr_header *) + (args->new_bh->b_data + header_off); + ret = ocfs2_reflink_lock_xattr_allocators(osb, xh, args->ref_root_bh, &credits, &meta_ac); if (ret) { -- 2.43.0