From nobody Sat Jun 13 09:16:15 2026 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 7AA69378D64 for ; Fri, 8 May 2026 08:59:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778230784; cv=none; b=WJxpv2egyh7HhhIc84ygcCBoiLb8yPqR+r0XslUSnfyJgUN+qp5w2ajW3JUO82WJpEhc1IX8cLQC4ULeeSZscdUu0GFrTqPeuPHTOVzsug0JQhBkMysw7Z8Bh6DVBYz2XzvpHUNC8CcSYb/gNN7CQjtcG6r7Nm6TWabSMH38cqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778230784; c=relaxed/simple; bh=D6IA2R9w6FO3pMYFRfXfz3ryYo0/dfTfvU1usz5XE9U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HSPHkkR7n/obEvnNCJ3c4gUX+wp5PZURtGbrs6w9IvC6vQMgTQkof+9Fzmbxep6vMh4sFRwCrAcklLFPEwXoPu8xwTYkkLvJbpMPzGqJr90bXJnYe+oljdlYT7nQ7CnPC0vJ3/k1gyHFuJlthie35xL/bd4tC73g3IDReHbfHJY= 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=JXUDhv5x; arc=none smtp.client-ip=209.85.214.178 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="JXUDhv5x" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2bab82d75fdso9997425ad.2 for ; Fri, 08 May 2026 01:59:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778230783; x=1778835583; 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=AjVbr/NOmM7hKB0cr1i4CxCGjBAPx4CaOHs0zMtPvmM=; b=JXUDhv5xZgTpFeh7E6sy14VY+dARzfzdvcV4LJ3Q93EgXpUtk95dMDS0Ukw/lNnkpF qeuham+wex2oa8P4uoCq2bddfu4IPRWqIfoz0vqYgHRlT5tkD24YfrMfsa3Vq45dXMaY SX0zrtG3ZdCEzHtTNUoBM48EVmOVyxPcBXYTyH0Bsb7kVlZsDY/xyFZf51TaYS5itWQR CLuHbGaSx5EDKPPRR8d0V1lD0AStgKwCVuTPGcUXtyrrwkuPcKrIX2zmJWb4bKOxPwfq AeMrjf+A5+TnYzrdisOUl49v+VTHhuzT3K8TBcuirmYqS0uPqCoTbiUDD2eSTmmoy8vv FJFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778230783; x=1778835583; 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=AjVbr/NOmM7hKB0cr1i4CxCGjBAPx4CaOHs0zMtPvmM=; b=eJjJO87jsftWqThRwY61rYrU1I5cOuhtyioex9fpyVmOZIKw+zSSKL8Vo9deiYIszs a5WzKPAQKqUkWVYxcnWrMcgIuXpJ4RloeLieCd06kNitVkCPHveRlbIj010/hsWCgQtC 06MYTBsn5z97RY3+kBTMLTbwiocxHu6x6hib8nyGStUdE/bH95alTOeSGttIpOGuBF1G ikX/w73L2JlXOMCWKcd6+lqAE+OUFVlh5axsqZHuBCserBEzyksKokWplfGADz2RS2ID dF2fjV0nkb/MflpuoPEl5OaSYaeX/6IUzjuIYTMxZLsJDsaPJ/Nz6IxKwJO7RmjAcGJz 9UHA== X-Forwarded-Encrypted: i=1; AFNElJ8TzITjlf35tlr5t0ulxMwV44YFgls3TnrDiLW6jeY+9HHgAozJBiCnsivNCtsJni+2L81e7hvPMTSOaqw=@vger.kernel.org X-Gm-Message-State: AOJu0Ywpgz9SiDOH7ZDmpC7H0vYJVEWWw3GtTvgBrUD7aMXKqQhFcfee nuFJwpxi2aNDyTxsCXg4OrBxU/BEfacHbuOHhMkF8kFG3ye7ng+NbEyG X-Gm-Gg: Acq92OFJSvH/F3EpATDvY8TuGm5IeJXAsRKKlVeMeSPS+gv6TTj+uZvKk5u6uM0yMXd YCLL9jC2kQvV/2cM6UHz15jx/E3Bn8AXlqyjlZ/fOy/v1NjjbzF3rLaRWGNQHBuMYeVXzhNsFn3 SMjxSJuzfxJTkzfon29RJpR/HiPx7p81mbh5wBrFUneHAztZX+bqMb/zSMQ73deHUQNhsZsf/6s xPerhbIcFEP7XHI9+i22WYkOnIgXzltr5xZNFV3qcIjtcrFQFn8sukUc4JgmcT2N8CsYQAfc5Ht lZ5KsbwkVj4pelQBWL6wOGidN9OQkvtXg2t781d4gWBft82rBbxDY2PUC8JJXXGipk1I8bxLruR rghwZuDpwyhDNXkYS0NGgqddp+WLil7ZE08lvapYwVPdtvWTRiuJxAAWj/A6ydLhMUPxMt2e7iZ 6FY5eN/iL3wjtbhyry77h/bmAz8cAutOMHd3ErT4PXs4lInVfsV0AJj5kSMkM0E+Oq3RCy0jnVo yIZ9uB5mi6TuaA+mEwaA5x/NiNunzT1toEe X-Received: by 2002:a17:903:3c2b:b0:2b4:689a:e411 with SMTP id d9443c01a7336-2ba794b80ddmr124847195ad.22.1778230782711; Fri, 08 May 2026 01:59:42 -0700 (PDT) Received: from localhost.localdomain ([111.202.175.43]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1d2709bsm15526795ad.5.2026.05.08.01.59.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 08 May 2026 01:59:42 -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 1/5] ocfs2: validate inline xattr header before ibody lookups Date: Fri, 8 May 2026 16:59:10 +0800 Message-ID: <20260508085914.61647-2-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: quoted-printable Content-Type: text/plain; charset="utf-8" [BUG] mknodat() can read past the end of a dinode block when ACL inheritance walks a corrupted inode-body xattr header. Another report shows the same unchecked lookup later faulting in the VFS open path after create returns a garbage status. KASAN: use-after-free in ocfs2_xattr_find_entry+0x37b/0x3a0 fs/ocfs2/xattr.c:1078 Read of size 2 at addr ffff88801c520300 by task syz.0.10/360 Trace: ... ocfs2_xattr_find_entry+0x37b/0x3a0 fs/ocfs2/xattr.c:1078 ocfs2_xattr_ibody_get fs/ocfs2/xattr.c:1178 [inline] ocfs2_xattr_get_nolock+0x2ee/0x1110 fs/ocfs2/xattr.c:1309 ocfs2_calc_xattr_init+0x716/0xac0 fs/ocfs2/xattr.c:628 ocfs2_mknod+0x935/0x2400 fs/ocfs2/namei.c:333 ocfs2_create+0x158/0x390 fs/ocfs2/namei.c:676 vfs_create fs/namei.c:3493 [inline] vfs_create+0x445/0x6f0 fs/namei.c:3477 do_mknodat+0x2d8/0x5e0 fs/namei.c:4372 __do_sys_mknodat fs/namei.c:4400 [inline] __se_sys_mknodat fs/namei.c:4397 [inline] __x64_sys_mknodat+0xb6/0xf0 fs/namei.c:4397 ... Another report: BUG: unable to handle page fault for address: fffffbfff3e40ec0 RIP: 0010:__d_entry_type include/linux/dcache.h:414 [inline] RIP: 0010:d_can_lookup include/linux/dcache.h:429 [inline] RIP: 0010:d_is_dir include/linux/dcache.h:439 [inline] RIP: 0010:path_openat+0xe2f/0x2ce0 fs/namei.c:4134 Trace: ... do_filp_open+0x1f6/0x430 fs/namei.c:4161 do_sys_openat2+0x117/0x1c0 fs/open.c:1437 __x64_sys_openat+0x15b/0x220 fs/open.c:1463 ... [CAUSE] ocfs2_xattr_ibody_list() already validates the inline xattr size and entry count, but ocfs2_xattr_ibody_get() and ocfs2_xattr_ibody_find() still derive the inline header directly from di->i_xattr_inline_size and then trust xh_count. A corrupted inline size or entry count can therefore move the computed header outside the dinode block before get/find start walking it. That can either make ocfs2_xattr_find_entry() dereference xs->header->xh_count outside the block or make ocfs2_xattr_get_nolock() bubble a garbage status back through ocfs2_calc_xattr_init() into the create/open path. [FIX] Factor the existing ibody header geometry checks into a shared helper. Use it in ocfs2_xattr_ibody_get() and ocfs2_xattr_ibody_find(), and have ocfs2_xattr_ibody_list() reuse the same helper instead of open-coding the validation. Reject corrupt ibody metadata with -EFSCORRUPTED before the lookup path can walk bogus xattr geometry or return a garbage status. Signed-off-by: ZhengYuan Huang Reviewed-by: Joseph Qi --- fs/ocfs2/xattr.c | 82 +++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 86cfd4c2adf9..3a5a17cdcf7e 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -950,6 +950,41 @@ static int ocfs2_xattr_list_entries(struct inode *inod= e, return result; } =20 +static int ocfs2_xattr_ibody_lookup_header(struct inode *inode, + struct ocfs2_dinode *di, + struct ocfs2_xattr_header **header) +{ + u16 xattr_count; + size_t max_entries; + u16 inline_size =3D le16_to_cpu(di->i_xattr_inline_size); + + if (inline_size > inode->i_sb->s_blocksize || + inline_size < sizeof(struct ocfs2_xattr_header)) { + ocfs2_error(inode->i_sb, + "Invalid xattr inline size %u in inode %llu\n", + inline_size, + (unsigned long long)OCFS2_I(inode)->ip_blkno); + return -EFSCORRUPTED; + } + + *header =3D (struct ocfs2_xattr_header *) + ((void *)di + inode->i_sb->s_blocksize - inline_size); + + xattr_count =3D le16_to_cpu((*header)->xh_count); + max_entries =3D (inline_size - sizeof(struct ocfs2_xattr_header)) / + sizeof(struct ocfs2_xattr_entry); + + if (xattr_count > max_entries) { + ocfs2_error(inode->i_sb, + "xattr entry count %u exceeds maximum %zu in inode %llu\n", + xattr_count, max_entries, + (unsigned long long)OCFS2_I(inode)->ip_blkno); + return -EFSCORRUPTED; + } + + return 0; +} + int ocfs2_has_inline_xattr_value_outside(struct inode *inode, struct ocfs2_dinode *di) { @@ -975,39 +1010,13 @@ static int ocfs2_xattr_ibody_list(struct inode *inod= e, struct ocfs2_xattr_header *header =3D NULL; struct ocfs2_inode_info *oi =3D OCFS2_I(inode); int ret =3D 0; - u16 xattr_count; - size_t max_entries; - u16 inline_size; =20 if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)) return ret; =20 - inline_size =3D le16_to_cpu(di->i_xattr_inline_size); - - /* Validate inline size is reasonable */ - if (inline_size > inode->i_sb->s_blocksize || - inline_size < sizeof(struct ocfs2_xattr_header)) { - ocfs2_error(inode->i_sb, - "Invalid xattr inline size %u in inode %llu\n", - inline_size, - (unsigned long long)OCFS2_I(inode)->ip_blkno); - return -EFSCORRUPTED; - } - - header =3D (struct ocfs2_xattr_header *) - ((void *)di + inode->i_sb->s_blocksize - inline_size); - - xattr_count =3D le16_to_cpu(header->xh_count); - max_entries =3D (inline_size - sizeof(struct ocfs2_xattr_header)) / - sizeof(struct ocfs2_xattr_entry); - - if (xattr_count > max_entries) { - ocfs2_error(inode->i_sb, - "xattr entry count %u exceeds maximum %zu in inode %llu\n", - xattr_count, max_entries, - (unsigned long long)OCFS2_I(inode)->ip_blkno); - return -EFSCORRUPTED; - } + ret =3D ocfs2_xattr_ibody_lookup_header(inode, di, &header); + if (ret) + return ret; =20 ret =3D ocfs2_xattr_list_entries(inode, header, buffer, buffer_size); =20 @@ -1200,8 +1209,9 @@ static int ocfs2_xattr_ibody_get(struct inode *inode, return -ENODATA; =20 xs->end =3D (void *)di + inode->i_sb->s_blocksize; - xs->header =3D (struct ocfs2_xattr_header *) - (xs->end - le16_to_cpu(di->i_xattr_inline_size)); + ret =3D ocfs2_xattr_ibody_lookup_header(inode, di, &xs->header); + if (ret) + return ret; xs->base =3D (void *)xs->header; xs->here =3D xs->header->xh_entries; =20 @@ -2726,12 +2736,14 @@ static int ocfs2_xattr_ibody_find(struct inode *ino= de, =20 xs->xattr_bh =3D xs->inode_bh; xs->end =3D (void *)di + inode->i_sb->s_blocksize; - if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) - xs->header =3D (struct ocfs2_xattr_header *) - (xs->end - le16_to_cpu(di->i_xattr_inline_size)); - else + if (oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) { + ret =3D ocfs2_xattr_ibody_lookup_header(inode, di, &xs->header); + if (ret) + return ret; + } else { xs->header =3D (struct ocfs2_xattr_header *) (xs->end - OCFS2_SB(inode->i_sb)->s_xattr_inline_size); + } xs->base =3D (void *)xs->header; xs->here =3D xs->header->xh_entries; =20 --=20 2.43.0 From nobody Sat Jun 13 09:16:15 2026 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 5FD3F378D64 for ; Fri, 8 May 2026 08:59:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778230791; cv=none; b=qCdJM41J1yXOFvF7TytzKrFwdbZD8o0kuIxXpH3Wy37cA+5AEZA6g1HOiBSn2s0qE+HlDKsul7bGr98ApToJ93ZxXl5NV+gpUj2Af1XDGd/T+vh/0ZH//Qnfkj+I/R2+IDRTcK2Wz48BpVrLay45bxCvK63vC5a/hqH/wDYyWfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778230791; c=relaxed/simple; bh=XZ2AxGd44BGqb6s1OpcbJ9fXbkAw+J5LMr3jUSfyuU8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hr8+G6HNL7Eg/9X7C+51LO5choFs8k9upIgb8tzE6DRwGETQJLW5zrFOk0M4xjOVgvoRH3+tG9sv8n7YtMAa0va9rMSdL3SoHy+FIxMxDBESdXUkp530L/B0+YVrJLY1ipUmjjb96GZ386z6CTl9vA7jEdw9TGQ92QnMNWL6Wns= 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=sic2nLcW; arc=none smtp.client-ip=209.85.214.173 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="sic2nLcW" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2ba17c8cfacso17794585ad.2 for ; Fri, 08 May 2026 01:59:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778230790; x=1778835590; 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=EUwXIfq13O1zgTkCmaAhWKKGGyYV15U86EllEIJj79E=; b=sic2nLcW472XoE8szx0Sy3aT+bDZDmNUtZw1zVhtFr3b+7EwWEYoAGPBkjznwhiUVP rAO2QEDDQKioBo1QOiK+ML9tGwqGKu246aEGRCWF2oQVZ3JC6pjSHoXUWxCWOMEeWpRQ 4B0mgVlXopyLsnYUgdYtToDmP1kgPbfM1v1rGNrWUcMlxLKXDEroY36poF6T+U6xPgBY CVkl4MLlscr3Fh00lh03zuWkFr3HkSH9q0u9r/Tzp6YCf/Pxs8n219Pz16HbW3cwzg+X IQFqiWe0LZpo74NOn3oKvJzGo7kc3WDcPxqAYVdMpIjuVjt0ARLjQ6wAhJe+KmfOV76V DQFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778230790; x=1778835590; 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=EUwXIfq13O1zgTkCmaAhWKKGGyYV15U86EllEIJj79E=; b=ZtIoi4jeqhklebDLQgLG7a+FzP3zisLPOVB3x5zYPsbeSn+tRsNx8yPjiuPeYZTj+A ElDa2K3DWTK5J9pN6VJM9D6Swgwd315xzMfG20FTg0Pe2OB/ZhnwwnGpYGDZVynaPqW/ iH/5SBEEf+YW2w2cdncXqL8yI06H1gsk9Bs93DCHlCbrU4clbFQlDT0LRCHatRw/Jb9L aLcy84QYtG2yiFjhXyN5Y+NYYiXiVUVPDRzNDLL5De2lLwSZ30RcaU0lul7gMf466K9J FuPRSYG6T3FtXuSbgVrezYm2al1CGx54hrxavsVc1u/AQXsJj1IE78VApVpz2gCX2FJS pTRQ== X-Forwarded-Encrypted: i=1; AFNElJ+to2ZjcP5wNXH/oHgwVDGvvlhkHdCAGBPW5J91YYYpGbnHGyR77GaoRD4OM+WOi8Grw68LfPUqgeNGTbc=@vger.kernel.org X-Gm-Message-State: AOJu0YxAqEZNpYGQD/8oqq0ZGqz1Ko9s0u3/ZZuslmmcUpn5ycxvCk/b foaswTZNcs+HUPedMNuvIkq4EKBpZ7DkOYgMLuKT8RPPNheqVdlMGiPNIa0c5MWiIpM= X-Gm-Gg: Acq92OFo1s/+heycEVggeQL1Sx+DiBpWw0gth6Teu2JVhmiw7OtKZX0D+W+Z3CSH0fT 3z6ZgI6BEk1tIerHEVwrpTPMa8aaWZFCjdcrV453imzh3SS5K8iaOD1DtGcusZczl88LOdM64qS EHACavzH+sbK/Wq27Wks5LwIDu/sFfvKmWnIGd8sVfAvr8Z8I+tvgWCGpQPs4TKAx86kdNhbNSB RdcZzRatRSpUkBeeohlYuf+pc+ffhS6Te7acoVcOnaCQqi7WZPqkWwYJoRnJ6pA5GZaQ1btFuFC o2qzBYkhllJIqx77H8qcDaRyYD+FhTL3ufYI5vyX0g07sTKmH0JTYIDWrL5JQ+LzKba5iKayDXx LalZlfJrqzEq23HNFnc+OLcwa7ksUZ11WWTTlbD8wr89L5Dmj6lXCgtaaT3JOMvXIdI28SDAc4O cGbF6q6Jzal8C4dbQ0YvY2gjfIotH3P07yZWp2lvjVXT1Inbu6z+48USTeXJxZsb6Nz6BSIKLWU WXwE3r3UWoj/MLWtaZDmLE1rQ== X-Received: by 2002:a17:902:db02:b0:2b0:67a7:5c4b with SMTP id d9443c01a7336-2ba79bdcd67mr114567055ad.28.1778230789622; Fri, 08 May 2026 01:59:49 -0700 (PDT) Received: from localhost.localdomain ([111.202.175.43]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1d2709bsm15526795ad.5.2026.05.08.01.59.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 08 May 2026 01:59:49 -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 2/5] ocfs2: validate inline xattr header before checking outside values Date: Fri, 8 May 2026 16:59:11 +0800 Message-ID: <20260508085914.61647-3-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: quoted-printable Content-Type: text/plain; charset="utf-8" [BUG] A corrupt inline xattr header can make ocfs2_has_inline_xattr_value_outside() walk xh_count from an unchecked header while refcount-tree teardown decides whether inline xattrs still point outside the inode body. [CAUSE] ocfs2_has_inline_xattr_value_outside() still computed the inline header directly from di->i_xattr_inline_size and immediately iterated xh_count. That is the same unchecked metadata boundary as the ibody lookup bug. [FIX] Reuse the shared inline-header helper before iterating xh_count. Because this helper returns a boolean-style answer to its caller, treat a corrupt header conservatively as "has outside values" instead of walking it. Signed-off-by: ZhengYuan Huang Reviewed-by: Joseph Qi --- fs/ocfs2/xattr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 3a5a17cdcf7e..05f6f0a886cf 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -989,11 +989,12 @@ int ocfs2_has_inline_xattr_value_outside(struct inode= *inode, struct ocfs2_dinode *di) { struct ocfs2_xattr_header *xh; + int ret; int i; =20 - xh =3D (struct ocfs2_xattr_header *) - ((void *)di + inode->i_sb->s_blocksize - - le16_to_cpu(di->i_xattr_inline_size)); + ret =3D ocfs2_xattr_ibody_lookup_header(inode, di, &xh); + if (ret) + return 1; =20 for (i =3D 0; i < le16_to_cpu(xh->xh_count); i++) if (!ocfs2_xattr_is_local(&xh->xh_entries[i])) --=20 2.43.0 From nobody Sat Jun 13 09:16:15 2026 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 3BBDB2571C7 for ; Fri, 8 May 2026 08:59:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778230798; cv=none; b=jbMcQIqVToFuFy3rjOTvfBuVQho/e/RKrXgFefX7CZyGRpyop/blMRjegQ07mACl2iz3b7kTJm8X3S7+4ligTbUu6nq8FvEoG5f4iS0azT8vby0wSSmJHrJctz7bCa4f5R4aIFJ8YzXeq80AlHny2Kf5g4LcFyAdp60jkVp6y2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778230798; c=relaxed/simple; bh=hbI4rz8zLPtORw9Xhzfq5UmS+KdGwinToZ5pmJNgdLY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nzmuhgaye+MGpbgdvVvso6F2qFp0PupdMeulrqtrDI6lwZX1PP740Vv52T/yxZrPtbUpqYO5VzBVLPJftTUAAse7ljg1Mb6nCcbKhEBcYlW18utKiVj9ehS31oviCmVBpci7dEtKA5xj3aRiTrDODgx+1ItsnRH+dX06YdfR3zE= 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=cviDay56; arc=none smtp.client-ip=209.85.216.46 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="cviDay56" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-365eecc5885so1647149a91.0 for ; Fri, 08 May 2026 01:59:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778230796; x=1778835596; 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=z7VsT9AqjcyF6s6LYKeTQGzKfn0YABtziNfSDMtnBzw=; b=cviDay56b0d4Euh73HA0SGsJfe6BuLwhMNE9AXuWdQW91KPKNoQmqqqbQqrhYW0XQk 7+S4qo6B01pizaZ0k3OETjhrGVRgTsAMzTljfsKew9Cb9BUFyGIHxYpp/zTUa9aEKXds iFLraLG38gfN+sRZCONj6+/dQ5ylLvN31uBuhtT1JyYh9S/J/WR6bS9xlSEWHKte1j0c HarbP4jLNY9i8B3XcI/RcuyEymIETpOkF5M8AQSRNzTuMa8egB+i6FMIEvFKWm4tBGSd 42KhL7XI+wEp5sPc7Hu8wyOuXXMVo+3G0ij0g/4zLCfwqsaD8Epn8k9oEeQ6M7+rHyZf OIJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778230796; x=1778835596; 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=z7VsT9AqjcyF6s6LYKeTQGzKfn0YABtziNfSDMtnBzw=; b=SSo2CtVKNCpxN8Twj+PJ1niJr4aE8bHXHLiQ4h+5+VSeEcEBSLrJYkLCGfM8HYZ7z3 jVGm7mFqupYM64fIJ6D0M/nMIh8HAX4+fHN5CrmxAv57ufzOtswYy7qYrNWTaxstrJFG RHf6IFqADM5qb+RB0du3seHNRfRuaZ+kxU9nSfYmXmQvqwUAgT+jFS+q+dyVoDh9S7dY 3s7ugXFYWGEBMxjMTcXJl/1J0GKW9ezPCm7HWDMUaAkKJrwTEl6RF6FGdWuQSyabkzHh 6IAnoEs3sm4aPq2VY9FIkaa3hlZy7qx7RCg7O1xKrlyMhSB63tFJEe3BekSwKx+rQUfQ o/Uw== X-Forwarded-Encrypted: i=1; AFNElJ//knNgCxGBoXGy/VOaLi6/hLV+4bfxAvklJjj6PqpyTEO+bNIQOfIUYy003xPl7/HQoqnrfFpiKWmabvM=@vger.kernel.org X-Gm-Message-State: AOJu0YzqsWZpACGtf349uLYS27xrICrtYWnIiVhVF8MZbe+kqpFaGE0P TVtQtcgyyi2TohRRD1Vuv1XjvsW6kVSH8RB6sQ0XnGYrFNd7EsRCDThbV7i1rkC00/s= X-Gm-Gg: Acq92OG0O6Jm/vulqSPkqlRr/zSLmfuT7AQ0hgNDD6KnzQBl40rZ1BHE+i95UAf5M4J IGBSoEdYNiQQpQH/qROQC07DFVhFw21ob93YkBPUscRq6PC4UCgKUWRwFlL3G1njzd+HvHurdWY PUgFa4luna2oXdajKgZ6DuAXakb7uRCVQvIIypf7UyO4oHXX8NAQiVJF6S6g0orY0eNABlXise6 XFu6klmcCKf/MP3AkAG09FgvCXeKYwDpyr536PZCEDQ9L7IeWqRAJhhv79hEbzwb9mO6CRPetVU JTDv94IqHkH/6AwIlM6SsEESLG4QBk1hlZqWcXNOWo9D+NtWGE2NWn7jk1R9L3BYZ+x83etvWcU RDz6Q4M7oMPi/p1EvG1gl3L6cchjBv9v88GeUzkhwfvCN9rsUIpOpDO3Gz2tVx46gw1/74q/6/P 0FxK40eQ5bUTtVN/HvS5E/H/psazxz8+igrhDESP4lAJA2mKwqU7C0FMxD//s6xeZ5CnE1PFuir 77Ksm23Spzb64+H0XLK+a3kJZG7YzseZxhz X-Received: by 2002:a17:90b:4d11:b0:366:5c38:fd61 with SMTP id 98e67ed59e1d1-3665c390b32mr637639a91.12.1778230796370; Fri, 08 May 2026 01:59:56 -0700 (PDT) Received: from localhost.localdomain ([111.202.175.43]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1d2709bsm15526795ad.5.2026.05.08.01.59.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 08 May 2026 01:59:55 -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 3/5] ocfs2: validate inline xattr header before ibody remove Date: Fri, 8 May 2026 16:59:12 +0800 Message-ID: <20260508085914.61647-4-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: quoted-printable Content-Type: text/plain; charset="utf-8" [BUG] A corrupt inline xattr header can make ocfs2_xattr_ibody_remove() pass an unchecked header into ocfs2_remove_value_outside() during inode xattr teardown. [CAUSE] ocfs2_xattr_ibody_remove() still rebuilt the ibody xattr header directly from di->i_xattr_inline_size and then handed it to code that iterates xh_count and entry geometry. [FIX] Validate the inline xattr header with the shared helper before handing it to the outside-value removal path, and propagate -EFSCORRUPTED on bad metadata instead of traversing the unchecked header. Signed-off-by: ZhengYuan Huang Reviewed-by: Joseph Qi --- fs/ocfs2/xattr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 05f6f0a886cf..bbb25a01b097 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -2476,9 +2476,9 @@ static int ocfs2_xattr_ibody_remove(struct inode *ino= de, .vb_access =3D ocfs2_journal_access_di, }; =20 - header =3D (struct ocfs2_xattr_header *) - ((void *)di + inode->i_sb->s_blocksize - - le16_to_cpu(di->i_xattr_inline_size)); + ret =3D ocfs2_xattr_ibody_lookup_header(inode, di, &header); + if (ret) + return ret; =20 ret =3D ocfs2_remove_value_outside(inode, &vb, header, ref_ci, ref_root_bh); --=20 2.43.0 From nobody Sat Jun 13 09:16:15 2026 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 41E7D37F75E for ; Fri, 8 May 2026 09:00:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778230805; cv=none; b=IqvJkyFBePh7FZ16AOfTue9GepBOsSPu2OJYjd73b8XO0j4p0l/TCWFiO1ICEkdylgrrngvgWVzjegJgxtI/7iXk1llaABnbU8ILddoUPboZczORZrXFZ6nEd9RAkKlD3wbY9Q49vbu3WhQMECy9HC4fxOgQ4R+N9Focp9oatpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778230805; c=relaxed/simple; bh=oQ8dke2rWFaSskvr2FsQetdBTXzOiYOJMNp/wJLjeTs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H4Rn6MfazmyOkbL9Z2wUvWKgWbKTRCkjHV89wkeVjJWsJJHtDChFdY/DhxNqk3sItCALiO08WjPMsJLVjurA84lqdHg9r68kACn40oX6wn6CFA+eMz0fuGNjuIT+5fW+8Rx8ri/AQ2EcByJMV5S99xLsPHY/OZJzTnWrRvcz9Dc= 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=kKI1fVSr; arc=none smtp.client-ip=209.85.214.182 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="kKI1fVSr" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2ab077e3f32so8557265ad.3 for ; Fri, 08 May 2026 02:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778230804; x=1778835604; 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=93r39cWo69bIErRsaiSDOdIu+drnExlfendQTTfQlzc=; b=kKI1fVSrVEZUOSxjCkWytEF3exAlZwCkG/1pj7AQnc9CbOjY9CzfXGK14UwXVkge9W oOWTXLOb7Wni0RS9c44LOuJ5AFuesHofR/ZJATHhljCvIzUYeusbp/XfBMPlBo0XYNH9 uHReAidbmYrOmsAxu/wQaGoWntJM9ruCvSzbtKsZVQIzKP4+hVkMewNkdwnVyDnVM9nn 7jdgOK4OrLYi9Fs53oFEcpJ0EjWJzrnL9iDZyHuNu1zAAp56pCwTvYjEPn3jm4VgijSL 38hT/PGdKQfeNqltueFvaFwtUEYXu2oZrHUB7+KGUpZd5qm/n+ru3OnOTRTVT7q0MNFp IrZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778230804; x=1778835604; 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=93r39cWo69bIErRsaiSDOdIu+drnExlfendQTTfQlzc=; b=mqZlpheFM5a/Yp4x4i6JEo05C42oVyEpIisdEvv9Cr0ZhVdxwLQZPieYbkzNISh9lz HPo4TwHLiEERwZ4u++GwfxhjrOhDF8EEXN7VXWmnMK7JcZIfWWVwrR3UwS55TH3vJ7uJ umnxoA2aY5V1vj+aZ79eobE5P3KqHi90FSWG4s2/DW70PP5YBL/ZT/rpUTPGcYm31zWg k0pQwWujqeAwnIiq9U0ncLLjZPe9Lp8LPPukiiPVgQQbFrfrzgWR6NpNruwfE3e6ZOo/ Q1C3Hjp82UwZrxUtYx5Y0ayj7/3U8ZzJzYwu75oZJwhn6n9MAEkFw8s8PXBZ06Lwg7X+ 42cw== X-Forwarded-Encrypted: i=1; AFNElJ/mkT0bHzHG7SOI/h37jvs2XEIpaMU3vch7wYPL7R3vmg9W7NsM+NJxvc2SoRchpxV4gXZ6cZNGZk22qvo=@vger.kernel.org X-Gm-Message-State: AOJu0YwE5pchZQ8zLmWBkwP/0i23qFlNKboVkxxW5TqF8XxFfyP6VP88 ORTmBd7X0vma9tmHQXMsMy+dFGJc3Xak+UiaahEmKNUTeE3p0tOD18U/ X-Gm-Gg: Acq92OHc1+I3hf4ugFC575IjIp5OhAE5llfW4X4/jI+mBR0kTWEdo8dISzFHPkpoyqZ kiBJLfR7R+LdAjhPi2b/5oLjx6qjriJqqvtPVAzcyw73TXxzH8yzcikR9lNF3mL/d/7EHkpHa1Y w4QHr/xJ03q1aLR12Ht8F13Pgc48lZPYkgqsQxJyghPmPHJEPX8pwFFzvN7I7kjOfp3KQ53QF/n L19PHza73/Lq91jiz8+Fgtq374ioEIo4uC2EBq92rPrSJsxmznlalkpzXk/POqtC1uG3p6SsvxB Wt/zuyLhEKOB3w9rBogj5fQQ57gigQg+8+GC5MlFJRC+srhTIjb9f5Jy74HLS7yB10UjFxCZcpi zL3vH5Z3USBKL/5967itzem0B+VBSbEH3mzSlL3kkJPr0v4GyVU7j29jq4CFwj2nltu5tu+9sOC ECd/JPDxwTOfgHmJeEi3QlpmOdnYp76QtBsmnXXYzbAgnxOch+dKvxamPsarDKKOQ9n4PHxAkQn 39RRFGU20KW0wbb4YurLuBdZg== X-Received: by 2002:a17:903:228c:b0:2b2:4194:9521 with SMTP id d9443c01a7336-2ba79287606mr123764565ad.25.1778230803336; Fri, 08 May 2026 02:00:03 -0700 (PDT) Received: from localhost.localdomain ([111.202.175.43]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1d2709bsm15526795ad.5.2026.05.08.01.59.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 08 May 2026 02:00:02 -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 4/5] ocfs2: validate inline xattr header before inline refcount attach Date: Fri, 8 May 2026 16:59:13 +0800 Message-ID: <20260508085914.61647-5-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: quoted-printable Content-Type: text/plain; charset="utf-8" [BUG] A corrupt inline xattr header can make ocfs2_xattr_inline_attach_refcount() feed an unchecked header into the refcount-attachment walk for inline xattr values. [CAUSE] The inline refcount-attach path still derived the header directly from di->i_xattr_inline_size and then passed it to code that iterates xh_count and xattr entries. [FIX] Use the shared ibody header helper before attaching refcounts to inline xattr values so corrupt header geometry is rejected with -EFSCORRUPTED instead of being traversed. Signed-off-by: ZhengYuan Huang Reviewed-by: Joseph Qi --- fs/ocfs2/xattr.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index bbb25a01b097..4877406a83ce 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -6016,14 +6016,17 @@ static int ocfs2_xattr_inline_attach_refcount(struc= t inode *inode, struct ocfs2_cached_dealloc_ctxt *dealloc) { struct ocfs2_dinode *di =3D (struct ocfs2_dinode *)fe_bh->b_data; - struct ocfs2_xattr_header *header =3D (struct ocfs2_xattr_header *) - (fe_bh->b_data + inode->i_sb->s_blocksize - - le16_to_cpu(di->i_xattr_inline_size)); + struct ocfs2_xattr_header *header; + int ret; struct ocfs2_xattr_value_buf vb =3D { .vb_bh =3D fe_bh, .vb_access =3D ocfs2_journal_access_di, }; =20 + ret =3D ocfs2_xattr_ibody_lookup_header(inode, di, &header); + if (ret) + return ret; + return ocfs2_xattr_attach_refcount_normal(inode, &vb, header, ref_ci, ref_root_bh, dealloc); } --=20 2.43.0 From nobody Sat Jun 13 09:16:15 2026 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: quoted-printable Content-Type: text/plain; charset="utf-8" [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 Reviewed-by: Joseph Qi --- 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 =3D OCFS2_SB(args->old_inode->i_sb); struct ocfs2_dinode *di =3D (struct ocfs2_dinode *)args->old_bh->b_data; - int inline_size =3D le16_to_cpu(di->i_xattr_inline_size); - int header_off =3D osb->sb->s_blocksize - inline_size; - struct ocfs2_xattr_header *xh =3D (struct ocfs2_xattr_header *) - (args->old_bh->b_data + header_off); - struct ocfs2_xattr_header *new_xh =3D (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 =3D NULL; struct ocfs2_inode_info *new_oi; struct ocfs2_dinode *new_di; @@ -6525,6 +6523,15 @@ static int ocfs2_reflink_xattr_inline(struct ocfs2_x= attr_reflink *args) .vb_access =3D ocfs2_journal_access_di, }; =20 + ret =3D ocfs2_xattr_ibody_lookup_header(args->old_inode, di, &xh); + if (ret) + goto out; + + inline_size =3D le16_to_cpu(di->i_xattr_inline_size); + header_off =3D osb->sb->s_blocksize - inline_size; + new_xh =3D (struct ocfs2_xattr_header *) + (args->new_bh->b_data + header_off); + ret =3D ocfs2_reflink_lock_xattr_allocators(osb, xh, args->ref_root_bh, &credits, &meta_ac); if (ret) { --=20 2.43.0