From nobody Sun Feb 8 04:12:54 2026 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 87EA730BB8E for ; Thu, 11 Dec 2025 11:52:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765453964; cv=none; b=Kz1TMJ73CJM2yqn3RqqIEbNvulsF7Qm1VeWklbdVfIAlcd00fKsqeoZi2anBG6NAeWjpHG1QMLGqg/afxAqmWXnvVtfbCA1BM8Q5rm07AY9Xt6RZLvE/Onq5+wLZRXpGQ4oDAZgcr6gZ8xcJ8X9R9xe1IFDhGj/a8Wa63RvAA7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765453964; c=relaxed/simple; bh=IHcdPwDYaOP9mnRlaK2tBNRlVnQPrGDe6fxMGkmdV8A=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uTpJ6HQmdHWMahElLOwPV73ektwaF82dXaB76ZpXZ4z/AH3D3+VeFHruhefaln1mEWkZLaFj9JZq7C35uy1SJ72k5csUmHo9QNAKF+5uM//c6Lp6y2CuCyFOYfBvF19DO0xf7Pcplq6LZp3oXWO+9181i/ud65aPxo6/v7z3I48= 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=OsDlnQLa; arc=none smtp.client-ip=209.85.216.48 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="OsDlnQLa" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-340e525487eso720099a91.3 for ; Thu, 11 Dec 2025 03:52:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765453961; x=1766058761; 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=psXlLAerr36Cu3nb3TCz/ORHSimLjF4H60tNxXRDbEY=; b=OsDlnQLaL/s4TNH0uXD0+o0cUzI6N0Uc3Rw7DmMFDiM3QjlBozDllWJgUjSStwPfG9 LP7MddeKnOOahbnxcE5U8LoIieTZxs1zOmf32ZRPIqZBOq2biOHfc2Ej8ub28tAFtHN2 cIaZRXuyaaYZQx3Ktcitlszb+fB/CvV32oHliG0f3ki3VA0cb7D2MdFa4R+F4uGWsXbN wt5J7tCUNf+tmfLXJfVXvFHVeZ9t7x/DFEHeTV7qnviJ98XEgsQJWGa4LZgXbg0V0lvY xBrXlltSL5iyXR0u2Op3LHiSiYwHP4sbLgbgIlXqEkvnK0g3Qgg63CnO9QuSY6scgf9G iizA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765453961; x=1766058761; 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=psXlLAerr36Cu3nb3TCz/ORHSimLjF4H60tNxXRDbEY=; b=hCmwxziv56Qf7iSke7w8o7w8E5NF59fD+dXCSTO4OrBOmSpoTzHUvA0wA8/vw2fN03 Xk+/jeoMhHGheg9AWsnck7TkcBOniQBWyo7CkucxIpMrykHMVL27Eh7Ktu3j9k71YFnw 9CYDQTBPXFrCV1wXZ0NuggdVnzWQKZ6WGW/hUzrTK7CfkizAisZGEO0IBlFvsq08HbHF VHe/HhYPr3wDDtbHaqfpfW7j1ccR3IZm99tamH/Zv7cHc+tBghlD3ImebpaSIQy163lC X2/UN02aZAG8BYFsZyFYMhMaTaSw06rMuMUHaixK6QMtpcKvmhCl8Bw4EA3c6OAZq6F0 65lw== X-Forwarded-Encrypted: i=1; AJvYcCXf7/wZ2a5LF+MgnIV9eca3d8j8ynzQr5C2mTNrZOzMJQd1rG1fegtzH7hPvAYGVimwrbi1VRyDCA0XvbE=@vger.kernel.org X-Gm-Message-State: AOJu0YzsnbbaAFB8JLOGbGNwzVwYnr604JghKyTPiM094nu6IhGDOHgx GFeFVV9YEH/7WcfxrAKd14WEgrDRNxAM4mZid8jwpw8QNdFOQ1JcNsGbFOiR/E1s X-Gm-Gg: AY/fxX7fNLBCZ/hYDFpYF722ARde/7lVkKwO9+7j6SOmwJ0RonA2e7vN6mcOnejvAws 4c+70pnrb2H4Ng7vejztlhDa6y7f45fU0hZY+F3uPQMBj8XC/kVLNUchHLEIeJPFhzJxBT0XeXm Yyr5HpSJg6yBE2eo1qEiCDk7Fx9IlIecKvt0gD190dBWAyH1VqO4GPbpKQOCpSdqy3ik4As1pUN KLPjnKcD2jTtX/EVqrkQBva7VjJ+z01KkitfayKj8XYlcw0pSYhrFYqKO8DaPiYZqvCQLUK5F5d qy8o2weHKsQTTqW/5bfjwe/G+wPQSEn4frRlHIrTXPXYuEDk3h0yU+kE4xRhds68HoKa1uLG3pU D9EKzwYZW1pUGDoUYsdTVBnHjSGtlH6eJe8/MSnro2xp2ia/w7ASyv+E9BnbDNgdiAtnnHgJVoq kwpgvbJ6D4e7j9/K6hU3IhOme/tZrWVu0PTKOWD9nRbMKOlG/zTZVgq+FUjVvPTsaxXalWlhtBp 2Do X-Google-Smtp-Source: AGHT+IG6APBLZxbb/LYrdmx22uddAVJjZ+LzQjdEPj+olmhhgmQHKYUVdd5RPNYmpXE4g4gd6sXHwg== X-Received: by 2002:a17:90b:4b85:b0:343:688e:3252 with SMTP id 98e67ed59e1d1-34a7281c71emr6270191a91.12.1765453961476; Thu, 11 Dec 2025 03:52:41 -0800 (PST) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:389d:7fd7:d1cd:305:6207]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-34a92754ab8sm681880a91.4.2025.12.11.03.52.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 03:52:40 -0800 (PST) From: Deepanshu Kartikey To: mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com Cc: ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, Deepanshu Kartikey , syzbot+c897823f699449cc3eb4@syzkaller.appspotmail.com Subject: [PATCH] ocfs2: validate inline directory i_size during inode read Date: Thu, 11 Dec 2025 17:22:31 +0530 Message-ID: <20251211115231.3560028-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" When reading an inode from disk, ocfs2_validate_inode_block() performs various sanity checks but does not validate the size of inline directories. If the filesystem is corrupted, an inline directory's i_size can exceed the actual inline data capacity (id_count). This causes ocfs2_dir_foreach_blk_id() to iterate beyond the inline data buffer, triggering a use-after-free when accessing directory entries from freed memory. In the syzbot report: - i_size was 1099511627576 bytes (~1TB) - Actual inline data capacity (id_count) is typically <256 bytes - A garbage rec_len (54648) caused ctx->pos to jump out of bounds - This triggered a UAF in ocfs2_check_dir_entry() Fix by adding a validation check in ocfs2_validate_inode_block() to ensure inline directories have i_size <=3D id_count. This catches the corruption early during inode read and prevents all downstream code from operating on invalid data. Reported-by: syzbot+c897823f699449cc3eb4@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3Dc897823f699449cc3eb4 Signed-off-by: Deepanshu Kartikey --- fs/ocfs2/inode.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c index 8340525e5589..9eb364bef5c3 100644 --- a/fs/ocfs2/inode.c +++ b/fs/ocfs2/inode.c @@ -1521,6 +1520,20 @@ int ocfs2_validate_inode_block(struct super_block *s= b, } } =20 + if (S_ISDIR(le16_to_cpu(di->i_mode)) && + (di->i_dyn_features & cpu_to_le16(OCFS2_INLINE_DATA_FL))) { + struct ocfs2_inline_data *data =3D &di->id2.i_data; + + if (le64_to_cpu(di->i_size) > le16_to_cpu(data->id_count)) { + rc =3D ocfs2_error(sb, + "Invalid dinode #%llu: inline directory i_size %llu exceeds id_count= %u\n", + (unsigned long long)bh->b_blocknr, + (unsigned long long)le64_to_cpu(di->i_size), + le16_to_cpu(data->id_count)); + goto bail; + } + } + rc =3D 0; =20 bail: --=20 2.43.0