From mboxrd@z Thu Jan 1 00:00:00 1970 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 5F500374A1D for ; Thu, 25 Jun 2026 09:01:11 +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=1782378072; cv=none; b=s3xKXEZzgkamdOu5Ce/LOiekk9TXyPzB7dAIr6JipwXKuBFJ+EKbgozsgWfnxeqYUBMrPa1uYoZ/GOXWqAmdmlnpaJjFwgAsWbPQOcT8q+tgPOERz0/pbR1v6kDq5FJEC+b3h9Kx1yzpSZOY1Fa2oJ9hrgUyEqdFCDL+jct8p7o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782378072; c=relaxed/simple; bh=9910rDOdgntu/IdL/bzHysNcQGCMg3BxBboAi+zYMeo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QWQJoB/mhV+xZtdIhhW9DlEZodec5M8WBlyxqtWFUFewOxNnEpUeX8/R8MHye8voqx9/VlKjKtDS5ibBlo013KBQRb6dF0YkabbvECG1lRjBpjYyD/9EPVVN7/dsTF3NS26gqIIS0o6FMWzhiBMGFszZiXIQauLFE4svjbNahT8= 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=GWZSPHUt; 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="GWZSPHUt" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2c6d31bfc70so12776595ad.3 for ; Thu, 25 Jun 2026 02:01:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782378071; x=1782982871; 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=NqPfV+tCqNEZnFIAUu2y2M5HYLqzWY3lJT6vyiF2WMo=; b=GWZSPHUtH7hVlT+feHKcbd4h2RtQCy3vKIKmEoZD8tol8/Afq0eHJGRKL4RVo4z4oq iaaqh3skgtmtofZq5IFeliAC/Fqrva3rAKOGxyL6OUPZ1J0D+kP5hIg/XWsrABYViEuj nFrfYUY0TBQgcrr+gh8i/FqeT/e++cS9q8/llW1g3+kHzL6HtJKy3T/Ck2rUVWRMlwn6 75nTGIPT3wwn7NTpD5NWameKsnbLQsE7AT6y635AKZUhg0wD+RIFg1oWuUC+bh4HaAtt L9WPrbbNXah5MYs9Xd7ZBS1exflciwmyE8fnRfWM2JQXpFCap2Umin/cYsY3Vay+Hoi9 /c7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782378071; x=1782982871; 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=NqPfV+tCqNEZnFIAUu2y2M5HYLqzWY3lJT6vyiF2WMo=; b=crOZbL6Lmds/dEZnFwViF7VQj6l9qFfPJc+ziDvta9P9wjIWi1FNMptNsyUApqv94H IpZfZ+g6HNQNGZ519daNloGOUeUqaccnvA2eySKDKTMnAntx81rzZJx4a8DHg75p72ao KhEwj/oxiJpPTGc9jMnX856ZVEg6T8GtjQl2SUInzB64D01AsNf3YNvv04KbtoN7uOnE PZtIM5Q7npWp51nENjTJFtaYuLqIVpmO1sFKAOht/4JiTDwG36tajOIkXT6jmIJyIIuy 88sQJXuER9pTC/unixYET70WChtQT6uv9c/zmmCLdoYSLaypQMOMWFBJRyZt1YSlNnw9 TwQA== X-Forwarded-Encrypted: i=1; AHgh+RrZLts0Cu8y/2OxLUy6wluWaI0IHcCHM1xnNx6mf6opPxb5S7LFVQ4r1JEUWWGr8o23Pm3MgGR3ZkC9Xcs=@vger.kernel.org X-Gm-Message-State: AOJu0YxgMHrc2/ZL3OTHJhiX7UApTboBfMy+2h6kFoFtGrNNbFswGe16 E6wwx6098nPue+QUPeoS5FYby7YM8sxjs10x1V2Lro9aUylOUYc9D7zlxZFkwYSY X-Gm-Gg: AfdE7cmApNOc85pK3pTNtvY1lPNgJr32Xvs7EYZ2k9oZsZy6Ac0b+NT0pstlxovr30g 8yicdzZum7MgUCDm6X/mihAuWDc5qYcNCfUr4AuXgOUmySTxte3KgtE8rhiL5eupoKkhmb27uKi pl8dadlpEXu+CMk0WJnlnaX840C76p6OO+RRr//bkq5pucdsjvaC8lPG9cRaQu1Gh3AznUa7m9R p4LWsaeZIFBBLuvXBAxIUToqwu3g+DLr7wSmOKxamwDedj4jAaaSR2JF8krUXVDjfXdkS2Uf3c+ g8fs6i56XrjuooZk/HnncOSTC1jq0weGfyRYqaaAufEwlVm5UYL6lxbSvv163EsU49QwUJFPc/I XalqyUqfZJwJu17ExbtMDeksONF2dLfKYk9RXmYe4k7PbE33DCy+m0hQNevyKvyXtzPaZlR9oG1 uhUC6xPk8= X-Received: by 2002:a17:902:e741:b0:2c7:9b3e:3987 with SMTP id d9443c01a7336-2c7fc890ac0mr16734415ad.25.1782378070529; Thu, 25 Jun 2026 02:01:10 -0700 (PDT) Received: from localhost ([111.228.63.84]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c7f6518bb1sm15365715ad.84.2026.06.25.02.01.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2026 02:01:10 -0700 (PDT) From: Cen Zhang To: Joseph Qi , Mark Fasheh , Joel Becker Cc: ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, zzzccc427@gmail.com Subject: [PATCH v5 2/2] ocfs2: validate external xattr entries when reading metadata Date: Thu, 25 Jun 2026 17:01:00 +0800 Message-Id: <20260625090100.202881-3-zzzccc427@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260625090100.202881-1-zzzccc427@gmail.com> References: <20260622130332.2094018-1-zzzccc427@gmail.com> <20260625090100.202881-1-zzzccc427@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 ocfs2_validate_xattr_block() checks the xattr block header before the block reaches higher-level xattr users, but it does not verify that a non-indexed block's xh_count and entry offsets fit inside the block. Indexed buckets likewise reach list/get consumers after ECC without an entry-bounds check. Reuse the xattr entry validator for non-indexed external xattr blocks and indexed buckets at metadata read time. The enum entry type selects the storage geometry: non-indexed blocks use the xattr block payload, while buckets keep the entry table bounded by the first bucket block and check name/value offsets against the bucket block they target. Reject corrupted external xattr metadata before listxattr() or getxattr() can walk out-of-range entry arrays or name/value offsets. Validation reproduced this kernel report: BUG: KASAN: use-after-free in ocfs2_xattr_list_entries+0xd7/0x190 Read of size 1 at addr ffff88810a654007 by task ocfs2_xattr_lis/630 Call Trace: dump_stack_lvl+0x66/0xa0 print_report+0xce/0x630 kasan_report+0xe0/0x110 ocfs2_xattr_list_entries+0xd7/0x190 ocfs2_listxattr+0x3f6/0x610 listxattr+0x90/0xe0 path_listxattrat+0xed/0x220 do_syscall_64+0x115/0x6a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Fixes: cf1d6c763fbc ("ocfs2: Add extended attribute support") Fixes: 0c044f0b24b9 ("ocfs2: Add xattr bucket iteration for large numbers of EAs") Assisted-by: Codex:gpt-5.5 Signed-off-by: Cen Zhang --- fs/ocfs2/xattr.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index b6f00926849d..cb0775d526b8 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -396,6 +396,13 @@ static int ocfs2_init_xattr_bucket(struct ocfs2_xattr_bucket *bucket, return rc; } +static int ocfs2_validate_xattr_entries(struct super_block *sb, u64 blkno, + struct ocfs2_xattr_header *xh, + enum ocfs2_xattr_entry_type type, + size_t storage_size); +static int ocfs2_validate_xattr_bucket(struct ocfs2_xattr_bucket *bucket, + u64 blkno); + /* Read the xattr bucket at xb_blkno */ static int ocfs2_read_xattr_bucket(struct ocfs2_xattr_bucket *bucket, u64 xb_blkno) @@ -414,6 +421,8 @@ static int ocfs2_read_xattr_bucket(struct ocfs2_xattr_bucket *bucket, spin_unlock(&OCFS2_SB(bucket->bu_inode->i_sb)->osb_xattr_lock); if (rc) mlog_errno(rc); + else + rc = ocfs2_validate_xattr_bucket(bucket, xb_blkno); } if (rc) @@ -515,6 +524,11 @@ static int ocfs2_validate_xattr_block(struct super_block *sb, le32_to_cpu(xb->xb_fs_generation)); } + if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) + return ocfs2_validate_xattr_entries(sb, bh->b_blocknr, + &xb->xb_attrs.xb_header, + OCFS2_XATTR_BLOCK, 0); + return 0; } @@ -1119,6 +1133,17 @@ int ocfs2_validate_inode_xattr(struct super_block *sb, u64 blkno, inline_size); } +static int ocfs2_validate_xattr_bucket(struct ocfs2_xattr_bucket *bucket, + u64 blkno) +{ + struct super_block *sb = bucket->bu_inode->i_sb; + + return ocfs2_validate_xattr_entries(sb, blkno, bucket_xh(bucket), + OCFS2_XATTR_BUCKET, + sb->s_blocksize * + bucket->bu_blocks); +} + static int ocfs2_xattr_ibody_lookup_header(struct inode *inode, struct ocfs2_dinode *di, struct ocfs2_xattr_header **header) -- 2.43.0