From nobody Tue Dec 2 02:05:47 2025 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 61001228CBC for ; Thu, 20 Nov 2025 04:11:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763611915; cv=none; b=B1SnlYKYmg6QxxB5zAaF3SibxA/DbB9F7YDJS5ZacRSkn4IbC1j9oXNHLbYQk/1DR/KmuOOxWZ8+k5oRYRVefM1HAABu9Y2BKx76PO3yiwWH+sOGDHq5oVM5nKY2dNtb41vPmANPVYjxx5LI/Bxx44p4bCzN4Mfo6zXcfaS0L/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763611915; c=relaxed/simple; bh=97WnfnQbPA5vGe8X+wXaWHLMQWqNVeB0fUmYg/LcXnU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=cJnYOEpXRqrqN0/nF75wd7hiiA5hhAuGYPrt9CID8JyHydX3oi8oJRjMIXQYzFvYL6TRHyBjmNmx/c8aAgHRHkLMe5QZ6nXOrmhR5L/Yu5Edwk6M8vw4z0Z5k9cE9cQznUaQapAuQ2YOhy3cFjtkdP+YnCFOe8F1tk3QievWB1k= 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=PtJfUvS6; arc=none smtp.client-ip=209.85.210.170 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="PtJfUvS6" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7aae5f2633dso470607b3a.3 for ; Wed, 19 Nov 2025 20:11:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763611914; x=1764216714; 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=OAknHB5tZjEpml4alkW5iZcUUFNVM3J13VfbF4fSGGQ=; b=PtJfUvS6IOa9ekCJ6CkrpbVM74gB4PooZqqWvPtbBygO7Ekw50lhkpX3gkypC0k+Js rMZwCjnovtJpOtYt+WQ4Xk0nrObgLz/q8iFGmOg6ookgfQu8ThbADT8hvBul+wv6PbeC wsz+356+qNspahwU+a+QzrBASYrEXh8VCWlMRhtNLucPu2oq28paOBIJFd4YUToimJ8b QXUqdXnnj/6TCb06vqyH1//AEEy3zlL9rbp20gX3t8tzEc31KC2yiwRNeA4y7d+ymNd5 tBV25Ur+ODy71QUmK5xD6bOCYdM5vcE61g55Whhin3/mUrmxJMlKT8YuxXRfWxgWrt+I Ghew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763611914; x=1764216714; 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=OAknHB5tZjEpml4alkW5iZcUUFNVM3J13VfbF4fSGGQ=; b=PXHNSSNOhn9RfLw+KSB+pefLHJ8d+keG45nFzw0wUTp8zAExqANMPpsbPC8U6EqoU6 LA0LUBShBTVgXrrFxxkXfdh4TJCe4n1tUqsfLW2LXWf/koHqMPe2rI/y1dmrMNBJuz4u oukR6BTlAZlmaSWmQFQRiJQz8yYRP2wa32o/Nn/q4G4ctLPsCbxQCGwc9QcNl1p0YEeD wk7AKhfYcXTAxFbOcqOqwRvrK6MNkmGdpDNiru+OXxnGebefV6yRGghM6gmSXD9SjekU z7QeDsj+RXC+GESNGOIH/lwfdjxJiLlyVmSvAawQ7ZU+LNxbWK4YAp+hAeR/DaIwZqsu vivg== X-Forwarded-Encrypted: i=1; AJvYcCW5eZ5EI7DLYBUf7M9FE69wxAYPrqQ92ZNm68vHL7IQPA6JVxXlf+AsUsYrejp3wfeasgX4bg9mhhcOYmw=@vger.kernel.org X-Gm-Message-State: AOJu0YxT+X89mGnO1178uSDhMC0Da/4NQAMbqvpO2QfLtTQRP5XX/zD6 csMpxHl7mBhZUEqUp+F1PuUnrxqFxwMgT5NhNXyF+tv2zt3RXgl8Ge+e X-Gm-Gg: ASbGnctZyhxPiu9a9zQgt2057+mmcChACKHxvk939YiMLQ8/cBczBobyATjopxSxvJU twrXj2n47aJL2Qzy93aGNBlAU9brjpKvQ/Mi/i0+yXeo0LYKrk2IkWCdMeOAT3CLo7fKPeGoAw0 ELjbEVTYC73gKlab2d26TVXZnJe6QMyNLWHgAKKZ+g28t0Lg/oYvP3/aFOjMaT2o1jdslinIvHk eigPDg7kOvBBaZDiDDuqsjkfYoxh+BHuvlLIe4xR7ABiG8y+CgOojrwsQ0yE54zFzOJ2swzIKds QBupJ4SXpOd2tNsYSBaNuKjCa4QMVQOxVNyzp8v2/5bosZtxVSWXoiRmI8cmFCmPOJg0VRgrOL4 AzyqzAK8t/nXCpvbSpoPZ/NxjSOFR1AKaREkx6lpejZHACBJtZjVPaSISs4Trh8d7gHSLrYfdSc qmpNAAPR5Rim7hSU5390vcCH4VWO8OExLpGSQ= X-Google-Smtp-Source: AGHT+IHvxEhcnjNuS7nEdN4Os+KSqtAwVjCqKQtuUbalhTNoMMg+jKTuqAecvtfgwz4aNhn6XCNghg== X-Received: by 2002:a05:6a00:84b:b0:7c2:60c6:8ca0 with SMTP id d2e1a72fcca58-7c433e0226dmr1144412b3a.5.1763611913572; Wed, 19 Nov 2025 20:11:53 -0800 (PST) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:389d:b699:1eac:7219:cf4a]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7c3ed471060sm1009312b3a.15.2025.11.19.20.11.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 20:11:53 -0800 (PST) From: Deepanshu Kartikey To: mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, heming.zhao@suse.com Cc: ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, Deepanshu Kartikey , syzbot+ab0ad25088673470d2d9@syzkaller.appspotmail.com Subject: [PATCH v4] ocfs2: validate inline xattr size and entry count in ocfs2_xattr_ibody_list Date: Thu, 20 Nov 2025 09:41:45 +0530 Message-ID: <20251120041145.33176-1-kartikey406@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: quoted-printable Content-Type: text/plain; charset="utf-8" Add comprehensive validation of inline xattr metadata in ocfs2_xattr_ibody_list() to prevent out-of-bounds access and use-after-free bugs when processing corrupted inline xattrs. The patch adds two critical validations: 1. Validates i_xattr_inline_size before use: - Ensures it does not exceed block size - Ensures it is at least large enough for xattr header - Prevents pointer arithmetic with corrupted size values that could point outside the inode block 2. Validates xattr entry count (xh_count): - Calculates maximum entries that can fit in the inline space - Rejects counts that exceed this limit - Prevents out-of-bounds array access in subsequent code Without these checks, a corrupted filesystem with invalid inline xattr metadata can cause the code to access memory beyond the allocated space. For example: - A corrupted i_xattr_inline_size of 0 would cause header pointer calculation to point past the end of the block - A corrupted xh_count of 22 with inline_size of 256 would cause array access 7 entries beyond the 15 that actually fit (the syzbot reproducer used xh_count of 20041), leading to use-after-free when accessing freed memory pages The validation uses the correct inline_size (from di->i_xattr_inline_size) rather than block size, ensuring accurate bounds checking for inline xattrs specifically. Reported-by: syzbot+ab0ad25088673470d2d9@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3Dab0ad25088673470d2d9 Tested-by: syzbot+ab0ad25088673470d2d9@syzkaller.appspotmail.com Suggested-by: Heming Zhao Link: https://lore.kernel.org/all/20251111073831.2027072-1-kartikey406@gmai= l.com/ [v1] Link: https://lore.kernel.org/all/20251117063217.5690-1-kartikey406@gmail.c= om/ [v2] Link: https://lore.kernel.org/all/20251117114224.12948-1-kartikey406@gmail.= com/ [v3] Signed-off-by: Deepanshu Kartikey Acked-by: Joseph Qi Reviewed-by: Heming Zhao --- Changes in v4: - Corrected commit message example: max entries is 15, not 7 (pointed out by Heming Zhao) Changes in v3: - Moved validation from ocfs2_xattr_list_entries() to ocfs2_xattr_ibody_list() to use correct inline size calculation (suggested by Heming Zhao) - Added validation of i_xattr_inline_size before use - Added validation of xattr entry count against inline space - Changed return value to -EFSCORRUPTED for consistency --- fs/ocfs2/xattr.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index d70a20d29e3e..98fd4f3f2d2d 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c @@ -971,13 +971,39 @@ static int ocfs2_xattr_ibody_list(struct inode *inode, 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 - - le16_to_cpu(di->i_xattr_inline_size)); + ((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; + } =20 ret =3D ocfs2_xattr_list_entries(inode, header, buffer, buffer_size); =20 --=20 2.43.0