From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 B1FEC412C17 for ; Thu, 6 Aug 2026 08:50:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786006232; cv=none; b=tFGNGOySq/CVjqVXDm27mZacIVDhq87laohS/Sh+jI3Cn5zlQVP3mB9l845GTwjxgK9kiFHJs6RdvEG33izBOn2mJX1DBTiyPo/91/sqEe/Xm2+N4IVNm1KYy6lG4TNKaTF7f/1FN/0HkWsw0WukTRiWy6AZ8reTlu/ALky3GLA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786006232; c=relaxed/simple; bh=im1LKzQmgi06AfOhesBf58dj0k46LJNJXNlhFQaVK20=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=jgFVrU0kFLnOxbhjdEl4WEil5Vb9ApGjuUWqJB7UKdHadDuee82aQay8g4wvCZi1iNsudUkFWQd9gDDFpPeNFWWuLkwx8AU55wssODekvaHvEMEmPU1tb0RhNHiRl0DQpJ5gaH6L0ddVEge/vGCQEoJSDR6UxdglJHDmvIurXKA= 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=kLVhIUgj; arc=none smtp.client-ip=209.85.214.169 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="kLVhIUgj" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2d0407aedd6so22360685ad.0 for ; Thu, 06 Aug 2026 01:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786006230; x=1786611030; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=h/tm6kDS4XdRMjbHSlDUXWElUUdP/MBkRMA0J1fvkHw=; b=kLVhIUgj3niaownfuiqY3qRAD40TQ+9+MIWyu6uHQb99vd+Hw05O1rDzCNKORV2v+v tslJL7N6vRh3YOp+zKG3MFYERmKLzSdAEaJbjirf+68irlnREgiiBPUBVlOGW8+O4LpZ ym2LevCAc3MUszylYQJBxZsazHKgWC1dwCvwbtPsd/HCzSFwpq9bFL6+gGbMeKhDfxpS IBzbBP8P9NPIcpFH4CFk2pbNxkZRPyQBFozKr45iYvu3qcRx0UnbwJ+v4MrhUkXZccnX qoIYP5Fkoynr0YB3qJAP9LTiwmJf+twJsSD89lssZhpC4YISVBoTRIuwWIWbftHwU9wh jquQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786006230; x=1786611030; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=h/tm6kDS4XdRMjbHSlDUXWElUUdP/MBkRMA0J1fvkHw=; b=nZHqBmBV7KUuRumTSqwYL32AngaZhn7tEYAbnZLDPV09qztnYzDRc8M8Dc1mi3n+n1 Ns/3Lxx4MaMHOV0UzrgBRH2b7Ujf6g/TnPyWmU5JWgT5CCpC3kmlv3VQzzFesqnFGgc1 zXk8CO+fjjMoEYjZSDJc0DYFPfAxuC7+P4StUJmQ3dtOFlSAXXmZNM/6EGIuny9243z7 vTICPJcJtiyQSWkePSslCUnNb3pAOFw04tja9oFf+0SfDIAmzTT7U4ZUdjL0ZZIHR0mW flLdqSyfkiCy9rdK5aooeJuSsEStZZg0uPSv9pTVCnAbap/mm/mZgniZPgqyxnMXYVcP llNQ== X-Forwarded-Encrypted: i=1; AHgh+RqZhnSqnEJkxjpZqbtdUgC8CIXPjwyIaR59bxNcWtADo+YHSKUxKlCe7zTtwGoKc5y+iJsFBewbJEgtVrI=@vger.kernel.org X-Gm-Message-State: AOJu0Yzzsrm6Ev/5g8y4nLca9/7nM7TXY8sHJjraglXpIWu+yWPs+qOV 0UG1ctH9mh1XGKYjO4NRhPzSyvOSHBg4enVDRCRbtIjT2TscZCV3Q5AJ X-Gm-Gg: AR+sD133xv86mbl5bHfk5jhqlUWWtODZ169bodfZCGFjKhPIH4/5U+uLdVkZ9zPFAsf Bo6y42OGPITUyBgO8O4cUSNtsyIzc5FGByz1IFUK4uRkpVB+TzaBNcN1QyhSuL3irXmgXU9nIPn Y4Ju9GUS1spsDOTRpl/8qP5DR87wb804/bZuLJ6ArrKiUhiQRfeOVWtYp/l7gMnQHb8da5i/iq9 4ceDnDa6VYn4ri31AFBC5hHDDkQ/SSWgNBBCo7Np9QsxrLHjT+v1UezakXqU448qKNLQ8WzM5SG crFNxCppbB26O/54CQP48zt4wZHzUjxTPZ9KMW5Q9PCLruTzTyBurke4zVDWjDdd/BcLLF1voFO ayu2n76eDiLqfyvbVk/WU0bzIP+h6HC8h057Os91q7JMG/ew0rYdqwmxAALE39jIkjqxewKI1xp 0CI0pv/K6qPJrTnTdYttTzRvwtALVfQ/3zKhmjx3ez4WpEQZIlTg2ZOoh/wAKPXPwdFGTKHGncd wBTl5ceJ3lkevIt4NdkWb3wrpeC7A== X-Received: by 2002:a17:903:3c48:b0:2ce:7563:70a5 with SMTP id d9443c01a7336-2d0ca70d53bmr167187695ad.6.1786006229885; Thu, 06 Aug 2026 01:50:29 -0700 (PDT) Received: from gmail.com ([138.199.21.246]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d0a9ff4f33sm28948195ad.25.2026.08.06.01.50.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2026 01:50:29 -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 v2] ocfs2: reject inconsistent local xattr entries Date: Thu, 6 Aug 2026 16:50:12 +0800 Message-ID: <20260806085012.2650042-1-gality369@gmail.com> X-Mailer: git-send-email 2.43.0 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 OCFS2 xattr entry can set OCFS2_XATTR_ENTRY_LOCAL while keeping xe_value_size larger than OCFS2_XATTR_INLINE_SIZE. When that entry reaches namevalue_size_xe(), the filesystem hits its BUG_ON: kernel BUG at fs/ocfs2/xattr.c:231! Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI RIP: 0010:namevalue_size_xe fs/ocfs2/xattr.c:231 [inline] RIP: 0010:ocfs2_xa_block_wipe_namevalue+0x2e4/0x330 fs/ocfs2/xattr.c:1638 Call Trace: ocfs2_xa_wipe_namevalue fs/ocfs2/xattr.c:1470 [inline] ocfs2_xa_remove_entry+0xae/0x1d0 fs/ocfs2/xattr.c:1941 ocfs2_xa_remove fs/ocfs2/xattr.c:2043 [inline] ocfs2_xa_set+0x11a8/0x30a0 fs/ocfs2/xattr.c:2247 ocfs2_xattr_ibody_set+0x302/0xc50 fs/ocfs2/xattr.c:2795 __ocfs2_xattr_set_handle+0x7e6/0xdb0 fs/ocfs2/xattr.c:3416 ocfs2_xattr_set+0x1447/0x2610 fs/ocfs2/xattr.c:3650 ocfs2_xattr_security_set+0x37/0x50 fs/ocfs2/xattr.c:7241 __vfs_removexattr+0x14d/0x1d0 fs/xattr.c:518 cap_inode_killpriv+0x29/0x50 security/commoncap.c:355 security_inode_killpriv+0x105/0x220 security/security.c:2724 setattr_prepare+0x147/0x8a0 fs/attr.c:219 ocfs2_setattr+0x504/0x1fd0 fs/ocfs2/file.c:1148 notify_change+0x4b5/0x1030 fs/attr.c:546 do_truncate+0x1d2/0x230 fs/open.c:68 handle_truncate fs/namei.c:3596 [inline] do_open fs/namei.c:3979 [inline] path_openat+0x260f/0x2ce0 fs/namei.c:4134 do_filp_open+0x1f6/0x430 fs/namei.c:4161 do_sys_openat2+0x117/0x1c0 fs/open.c:1437 ... [CAUSE] namevalue_size_xe() assumes that local entries contain an inline value no larger than OCFS2_XATTR_INLINE_SIZE. Existing xattr metadata validation only checks whether the value fits the storage region, and cached entries can reach lookup and bucket maintenance paths without a semantic check. A corrupt entry can therefore be passed to namevalue_size_xe(). [FIX] Validate the local/value-size invariant in the existing flat and bucket metadata validators and before accepting matched entries or traversing bucket entries in paths that call namevalue_size_xe(). Return an OCFS2 corruption error instead of firing the assertion. Signed-off-by: ZhengYuan Huang --- v2: - Rebase onto the ACL lock-order fix in linux-next. - Reuse the existing xattr metadata validators. - Keep validation in cached lookup and bucket maintenance paths. --- fs/ocfs2/xattr.c | 53 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 35bcbb0ff607..e955126e4d7d 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -237,6 +237,21 @@ static int namevalue_size_xe(struct ocfs2_xattr_entry *xe) return namevalue_size(xe->xe_name_len, value_len); } +static int ocfs2_validate_xattr_entry(struct super_block *sb, u64 blkno, + struct ocfs2_xattr_entry *xe) +{ + u64 value_len = le64_to_cpu(xe->xe_value_size); + + if (value_len > OCFS2_XATTR_INLINE_SIZE && + ocfs2_xattr_is_local(xe)) + return ocfs2_error(sb, + "Invalid local xattr in block %llu: value size %llu\n", + (unsigned long long)blkno, + (unsigned long long)value_len); + + return 0; +} + static int ocfs2_xattr_bucket_get_name_value(struct super_block *sb, struct ocfs2_xattr_header *xh, @@ -992,7 +1007,7 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno, size_t entries_limit = region_size; size_t nv_limit = region_size; size_t max_entries; - int i; + int i, ret; if (region_size < sizeof(*xh)) return ocfs2_error(sb, @@ -1012,6 +1027,11 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno, struct ocfs2_xattr_entry *xe = &xh->xh_entries[i]; size_t name_offset = le16_to_cpu(xe->xe_name_offset); size_t value_offset; + u64 value_len = le64_to_cpu(xe->xe_value_size); + + ret = ocfs2_validate_xattr_entry(sb, blkno, xe); + if (ret) + return ret; if (name_offset > nv_limit || xe->xe_name_len > nv_limit - name_offset) @@ -1026,8 +1046,7 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno, (unsigned long long)blkno, i); if (ocfs2_xattr_is_local(xe)) { - if (le64_to_cpu(xe->xe_value_size) > - nv_limit - value_offset) + if (value_len > nv_limit - value_offset) return ocfs2_error(sb, "Invalid xattr in block %llu: entry %d value is out of bounds\n", (unsigned long long)blkno, @@ -1112,7 +1131,7 @@ static int ocfs2_validate_xattr_bucket(struct ocfs2_xattr_bucket *bucket, size_t entries_limit = sb->s_blocksize; size_t nv_limit = sb->s_blocksize; size_t max_entries; - int i; + int i, ret; if (region_size < sizeof(*xh)) return ocfs2_error(sb, @@ -1140,6 +1159,11 @@ static int ocfs2_validate_xattr_bucket(struct ocfs2_xattr_bucket *bucket, size_t block_off = name_offset >> sb->s_blocksize_bits; size_t block_offset = name_offset % nv_limit; size_t value_offset; + u64 value_len = le64_to_cpu(xe->xe_value_size); + + ret = ocfs2_validate_xattr_entry(sb, blkno, xe); + if (ret) + return ret; if (name_offset >= region_size || block_off >= bucket->bu_blocks) return ocfs2_error(sb, @@ -1158,8 +1182,7 @@ static int ocfs2_validate_xattr_bucket(struct ocfs2_xattr_bucket *bucket, (unsigned long long)blkno, i); if (ocfs2_xattr_is_local(xe)) { - if (le64_to_cpu(xe->xe_value_size) > - nv_limit - value_offset) + if (value_len > nv_limit - value_offset) return ocfs2_error(sb, "Invalid xattr bucket %llu: entry %d value is out of bounds\n", (unsigned long long)blkno, @@ -1307,7 +1330,7 @@ static int ocfs2_xattr_find_entry(struct inode *inode, int name_index, { struct ocfs2_xattr_entry *entry; size_t name_len; - int i, name_offset, cmp = 1; + int i, name_offset, cmp = 1, ret; if (name == NULL) return -EINVAL; @@ -1330,6 +1353,12 @@ static int ocfs2_xattr_find_entry(struct inode *inode, int name_index, return -EFSCORRUPTED; } cmp = memcmp(name, (xs->base + name_offset), name_len); + if (!cmp) { + ret = ocfs2_validate_xattr_entry(inode->i_sb, + OCFS2_I(inode)->ip_blkno, entry); + if (ret) + return ret; + } } if (cmp == 0) break; @@ -4041,6 +4070,10 @@ static int ocfs2_find_xe_in_bucket(struct inode *inode, xe_name = bucket_block(bucket, block_off) + new_offset; if (!memcmp(name, xe_name, name_len)) { + ret = ocfs2_validate_xattr_entry(inode->i_sb, + OCFS2_I(inode)->ip_blkno, xe); + if (ret) + break; *xe_index = i; *found = 1; ret = 0; @@ -4681,6 +4714,9 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode, xe = xh->xh_entries; end = OCFS2_XATTR_BUCKET_SIZE; for (i = 0; i < le16_to_cpu(xh->xh_count); i++, xe++) { + ret = ocfs2_validate_xattr_entry(inode->i_sb, blkno, xe); + if (ret) + goto out; offset = le16_to_cpu(xe->xe_name_offset); len = namevalue_size_xe(xe); @@ -4963,6 +4999,9 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode, name_value_len = 0; for (i = 0; i < start; i++) { xe = &xh->xh_entries[i]; + ret = ocfs2_validate_xattr_entry(inode->i_sb, blk, xe); + if (ret) + goto out; name_value_len += namevalue_size_xe(xe); if (le16_to_cpu(xe->xe_name_offset) < name_offset) name_offset = le16_to_cpu(xe->xe_name_offset); -- 2.43.0