From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.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 D95FA23C368 for ; Thu, 16 Apr 2026 07:03:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776322984; cv=none; b=gyhDNEgv7Q58yT53esY9/2kTJ2a1uqAh/SJrw5M3/FrZqJPXsex039solUJeoFYhkr8nwEV8LbIUkigsRa9NvC4K8XFBZVPKU2RHcuNf+IgC2MD38QC19uIYRmpxsFgsCm/XBlAtkLIUhme+BWLMdO3bE+J2CnhQBXWy3WZXSZ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776322984; c=relaxed/simple; bh=06tSmzb3uyiEydP/y4Tc2xYrMNoeAfwk71vRjS/qpAo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=KPSGHEQ8+dsemzYg0XCkFY+DFstshol3So4TiIGna8mf5jFZkBYFw26kF6LvrcCrpWyjzP++LInGLLMmmr9PisRj3pbMLqcCewyAZIHjXHn86k0dNR1ox/bUxUkMdmmQrgwNgPvGQzfM8RcREC0dl/DfZ5iwZ+ne7r2cKHZo1yw= 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=AD99kbsQ; arc=none smtp.client-ip=209.85.210.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="AD99kbsQ" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-82f1bfc9b8fso2478638b3a.1 for ; Thu, 16 Apr 2026 00:03:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776322982; x=1776927782; 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; bh=BmiIo4pDimTCK6yD7w6U/zwXcuTp5tvRAhBoqzdPhHQ=; b=AD99kbsQZkxR3Xqv1IoWearfVvNKHG6AHfor7vyN3Jc9KTkBCtaHbgSXo1PK5ciKSv eZMIiaJe8YZnfQUPfkEAnuGVXM9SZhc1BuQ3p/eOWZunapi0U0Pf16NyxagXtTrxFa/C lacRNIDNGSWTwWJXP4cpoXp/A2QC0oSQJsN6uKpF+S4om8jR3hWO8JNwv20r+IqZddii nJWx7jLu2UDWBwBjdD2+iMjX8+pFhkKatkGyL2pE8XQA9c4709KG1dTKDUVOnPJxJaBx OpCG8YPnIVl5e2kUvV2guhQnqR7qiUMvaNSfsFo1wkrkm/CIGTx9GDueJbUzcAbD6GcT am5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776322982; x=1776927782; 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; bh=BmiIo4pDimTCK6yD7w6U/zwXcuTp5tvRAhBoqzdPhHQ=; b=iCl04CusROGOxh6o7F+uwjbJ3jQKkMhk0IFqF6vy5zBRDdzydXowuqAvS2Lj/tgWAg jWloB5Ztb1JBcbv9rPAd62L+JpiYBql6NZHodsHlKOa8aC6tVXAhUF8AG5I5q4x4oBoQ U+mY9tgG8l8i3W5wuOZDZ+UN7dUt8t2qankh6PxScpSssob2CYzlKjb2dylM23Axo9or gZzMPigPsoWbh5zF/oO9tUjgYQSPAOSkza3/Dkylfq6k37tFC+X5qneOB8zmLW+0QNPi 69r6L19FagAcsK8eGM2kgyQIXWLGU+jOK5AfUWRPTxgzNYGcSf1HR+J6K+QYMH59QfkI s1lw== X-Forwarded-Encrypted: i=1; AFNElJ9yJDC5/QaOQKXqqrm4SYmjcTFJf7YWduAmtaNwcOfxDTLLM0ZaB8WiRP9MUTWSW1wF427+Rv4fhAtOS6Y=@vger.kernel.org X-Gm-Message-State: AOJu0YzL/vy/gjvL5cAeXR+F35OaqdS4suz3V9YGdigeVnv9YnMf9P2j 2q2Db9sHXV9JJKdQExG3VefWmEZ3WWiHlKovn36gg/sZX/7vFLdCyUp4 X-Gm-Gg: AeBDietMUvUjIsXNHJrygDTlUbMHNsAgUFsMiC6NuUpq2PKfqcpeRLW7NanuPI1TE7j VQJryCFBfFtnpQ9XTToP9meLmaAzp28zEChsX73E11Z3HBBqJ3JHkrayPZby/xgdEFi5Fe456HB uR8YO3kil+eiq8pZHDBdrl85QZhlI/CMonJlSD/uisSEJfamLjTktqtMJ2RfhT7zVqp8gBlVqhG uN6YG1o+acH/2Fn/paOdx0Yn4dcaXop4FENxUKZ7P1Hv8NHJbqdF0/nSbECwNesKXa5BrDyUeTq iVKidQWFEcGfWlj7JtiBO5NhJCzDSxLiMB8eGdKxa60Ze6scLKu6Uk4wX3feBDkxrihkQaVzgQC UA+5fCl68YGSrAvsIBEIDSihzK8OczYJVCu2S8wHWTrni8+9xZtmnmcDppN8PD5N2EBq64pJ6qr 8rZv+urjZOaXM/LcT0Wd6tdhWJmCwpsxZ+9orhIMj19j6Bj4y9lELGxiTdNP2aJVACGDrkIMX9b zTO9c8wGg== X-Received: by 2002:a05:6a20:e210:b0:398:8546:c3fc with SMTP id adf61e73a8af0-39fe3c62aeamr25991570637.7.1776322981958; Thu, 16 Apr 2026 00:03:01 -0700 (PDT) Received: from kernel-fuzz.. ([103.172.182.26]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f6702f936sm4133610b3a.6.2026.04.16.00.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Apr 2026 00:03:01 -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 v3] ocfs2: reject inconsistent local xattr entries Date: Thu, 16 Apr 2026 15:02:51 +0800 Message-ID: <20260416070251.481784-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. Once that entry reaches namevalue_size_xe(), the filesystem trips over: 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 do_sys_open fs/open.c:1452 [inline] ... [CAUSE] namevalue_size_xe() assumes on-disk xattr entries keep the local flag and value size consistent, but OCFS2 does not reject an entry that claims local storage for a value larger than the inline limit before handing that entry to namevalue_size_xe(). The exact-match lookup path can return such an entry through xs->here, and bucket defragmentation and splitting can also walk the corrupt entry directly while reorganizing metadata. [FIX] Add a small validator for the local/value_size invariant and call it in the paths that feed disk entries to namevalue_size_xe(): exact-match lookup, bucket lookup results, bucket defragmentation, and bucket splitting. Corrupt metadata is now reported with ocfs2_error() and -EFSCORRUPTED instead of crashing the kernel with BUG_ON(). Signed-off-by: ZhengYuan Huang --- No Fixes tag was added because this is more like a defensive check that is long overdue, not a regression that can be clearly attributed to a specific introduction commit. [CHANGELOG] - Fix Signed-off-by email address and name only; no code changes since v1. Sorry for annoying everyone with a new patch version for such a minor fix. --- diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 86cfd4c2adf9..63b1e55b242f 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -237,6 +237,23 @@ 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 inode *inode, + 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)) { + ocfs2_error(inode->i_sb, + "Inode %llu has corrupt xattr entry: local value_size %llu\n", + (unsigned long long)OCFS2_I(inode)->ip_blkno, + value_len); + return -EFSCORRUPTED; + } + + return 0; +} + static int ocfs2_xattr_bucket_get_name_value(struct super_block *sb, struct ocfs2_xattr_header *xh, @@ -1099,6 +1116,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 ret; if (name == NULL) return -EINVAL; @@ -1121,6 +1139,11 @@ 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, entry); + if (ret) + return ret; + } } if (cmp == 0) break; @@ -3823,6 +3846,9 @@ 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, xe); + if (ret) + break; *xe_index = i; *found = 1; ret = 0; @@ -4463,6 +4489,10 @@ 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, xe); + if (ret) + goto out; + offset = le16_to_cpu(xe->xe_name_offset); len = namevalue_size_xe(xe); @@ -4745,6 +4775,10 @@ 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, 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