From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 1DDB7329C7F for ; Mon, 17 Nov 2025 11:42:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763379755; cv=none; b=IwcN7QTwD3huUfWdIK+JdFFJR8gMkBbi5+hEmZ8nLMwzvWeXWpA6hSkvIJgBl8z/o7oJ8I0/rCsTfBdRqzPT74iyybXk7ddmIG33eTW0ZSMMI8adHqTB0WNwv7cgOo3rqhHcL6BLelOKNMefylfgNTKYdS7/aeaYuIoyU9uT8OA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763379755; c=relaxed/simple; bh=UZCACtO/pqe+26J2EJiBR/zQesvYpmL0azfVHaXmv4E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=fdcp5/DVnzMxIRJsrto7tqCoogCH5KaWjIT1GF32jag88ek0+ijnOaPpL1fANIf1qvGebxs6psiKCDmAdN+Li7G+/rspkfR5Nk+djcLi/L3nTOwXifhGB8cD06tUskHRoQf3aRFy8d6EcqALqcN9M54LN85ULvUf1W/3jZ6bgCA= 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=VgQ/XDyV; arc=none smtp.client-ip=209.85.214.179 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="VgQ/XDyV" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-297ef378069so40743755ad.3 for ; Mon, 17 Nov 2025 03:42:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763379752; x=1763984552; 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=XNpL5Ghz/qrVsjxUngeGJ80bJJXI7kHj0yflRXScBjc=; b=VgQ/XDyVAGdw36RLnaACSDzH/CITnHpWPVgMnJFRDbGJO0Ogv+CPYqSyYT/U6ngo1h DbmSSda/3UXXjvTuORQdUOjVWnw/TuHg3xWcnFJaoYGqBjComn94D4Krj2k/WkE7uIou gVRZi/IIzKigB1tLBIdq9ng770ApbRKD7TOUpnTOpuAQGN5+TCcd2GXd5+R3VA++fv32 3Q9XjjnUSBh/22WdyiqjoqyTMbPiYo6BeRvci5kaFdjC+XLZebz6NjLPbJ5bqVQMwgOL 10G6zdxdK4fQ+MfGtI7Yx31sRf//+zNMccFs4R8NqP32KAaZyXOU0f5JbUjbnrk7WJtW 7OAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763379752; x=1763984552; 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=XNpL5Ghz/qrVsjxUngeGJ80bJJXI7kHj0yflRXScBjc=; b=waVoKjH2Ykzu3bI5YvXLxY0Brjd9u3pZduWrn2NTroEV2zaG/GB77+9FNvhZeDD4iV 9wk2/Ixmf5AxLdOtXlelsht/Y/e1XqmYMEzvI+vvWg1N7j2KK53KMux2d7hxXHcwcw77 mzVdJCNwZF3L43rs+VqanjUV3Qz0LUuqDyhY6fJkORVV9ucHAXsdfosAErLHhuQ6MpIg 89aWEV+AGMlxkiai4iXGUjapcLQ7m2JcUd0/cF90v8bASVF2FBABy93bPmnKjudWV+iV z058mty2/N1yu50XaM7TmeyZwL5S2ElMdzhNBP+16CU8uAA31y4jU00NHDIVCdoIJp/O e9YQ== X-Forwarded-Encrypted: i=1; AJvYcCVy1TCEWZJzOJn6PP3ZVjiq1Tv0rj2IivFrfyQI+fEc9GZH+sPUmwnGeae8c0iNzqENMFlLsTCuEsQIOPw=@vger.kernel.org X-Gm-Message-State: AOJu0YxLue578s+0jdkuqgMNZULq+DaB3AWOS+PzpDQbXZJ45obTBO2e 7idNjo5nj+5rNmEejOjQC0El4DKg7AA81vwf1vJU7gccWu7hr/A/vXnE X-Gm-Gg: ASbGncsVq6eVWWPjgwNC+uW4JjmrJ9pbJsnsKGaZB36ZH9vu82P1Qw1Rl1xdnYZ5xnw QL/Jqm/YjZKIAFNWkdwKzSU4DZKTvSHjAEtPxBYDug5lTlpPhUNKpTRecfhJKRkfqtw815Pmpmk Fhqqx00K49v3hsS5L++gEHFpZIwuOWziNxdzSwaUOA0EP5ZoX/5ZvlGtcBY4VyH0DJnTVbNxRbc SKFv7CI98+DDyuBvgbZsh6m4Pzg862djuIGOYRISl7Ccca+fInRPJBpd0kUfy2seXh/eXpFjoFQ 8WP6A+deN/ERcPqoJcIJ16P6aybI2hwlp9acsn/b6RLsT2BpOV+zcmB0YzTTYeXZgXyGga/v+rl pZlTccz9Zw/IGDKd+LUriWvuTm4Ep7xsqG70HHhwPKeRPQbIC8OD3cqpV5Z/BJydNSgB11jTf57 IGaASIZOQQSBk9xAr4SfkeY3dUxycf172hbA== X-Google-Smtp-Source: AGHT+IGxrtKLd/UOJMvhgpyn5AUt8VVfblBbqs7p1VeDOePaMAcUpYI4zG5FYpSR1dDOZq0Z4oEcag== X-Received: by 2002:a17:902:e543:b0:28d:18fb:bb93 with SMTP id d9443c01a7336-2986a6b8261mr140865095ad.7.1763379752238; Mon, 17 Nov 2025 03:42:32 -0800 (PST) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:389d:b6cd:9c19:e37a:84a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2986a60b116sm105452895ad.79.2025.11.17.03.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Nov 2025 03:42:31 -0800 (PST) From: Deepanshu Kartikey To: mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Deepanshu Kartikey , syzbot+ab0ad25088673470d2d9@syzkaller.appspotmail.com, Heming Zhao Subject: [PATCH v3] ocfs2: validate inline xattr size and entry count in ocfs2_xattr_ibody_list Date: Mon, 17 Nov 2025 17:12:24 +0530 Message-ID: <20251117114224.12948-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: 8bit 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 20041 with inline_size of 256 would cause array access beyond the 7 entries that actually fit, 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=ab0ad25088673470d2d9 Tested-by: syzbot+ab0ad25088673470d2d9@syzkaller.appspotmail.com Suggested-by: Heming Zhao Link: https://lore.kernel.org/all/20251111073831.2027072-1-kartikey406@gmail.com/ [v1] Link: https://lore.kernel.org/all/20251117063217.5690-1-kartikey406@gmail.com/T/ [v2] Signed-off-by: Deepanshu Kartikey --- 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 = NULL; struct ocfs2_inode_info *oi = OCFS2_I(inode); int ret = 0; + u16 xattr_count; + size_t max_entries; + u16 inline_size; if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL)) return ret; + inline_size = 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 = (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 = le16_to_cpu(header->xh_count); + max_entries = (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 = ocfs2_xattr_list_entries(inode, header, buffer, buffer_size); -- 2.43.0