From: syzbot <syzbot+c897823f699449cc3eb4@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: [PATCH] ocfs2: fix use-after-free when reading a bad inode
Date: Thu, 11 Dec 2025 00:06:50 -0800 [thread overview]
Message-ID: <693a7b9a.050a0220.4004e.02f7.GAE@google.com> (raw)
In-Reply-To: <693a631e.a70a0220.33cd7b.0028.GAE@google.com>
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] ocfs2: fix use-after-free when reading a bad inode
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
When ocfs2_read_locked_inode() fails with -ENOMEM or other errors,
it calls make_bad_inode() to mark the inode as bad but still returns
a valid inode pointer through the iget machinery. The function
_ocfs2_get_system_file_inode() only checks for IS_ERR(inode) but
not for bad inodes, causing the bad inode to be returned to callers.
During orphan recovery, ocfs2_queue_orphans() gets this bad inode
for the orphan directory and passes it to ocfs2_dir_foreach().
Since the inode was never properly initialized due to the earlier
read failure, iterating the directory accesses freed or uninitialized
memory, triggering a use-after-free in ocfs2_check_dir_entry().
Fix this by adding an is_bad_inode() check in _ocfs2_get_system_file_inode()
after ocfs2_iget() returns. If the inode is bad, release it with iput()
and return NULL. This protects all callers of ocfs2_get_system_file_inode()
from receiving bad inodes.
Reported-by: syzbot+c897823f699449cc3eb4@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c897823f699449cc3eb4
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
fs/ocfs2/sysfile.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/fs/ocfs2/sysfile.c b/fs/ocfs2/sysfile.c
index d53a6cc866be..f443479f7d3e 100644
--- a/fs/ocfs2/sysfile.c
+++ b/fs/ocfs2/sysfile.c
@@ -145,6 +145,13 @@ static struct inode * _ocfs2_get_system_file_inode(struct ocfs2_super *osb,
inode = NULL;
goto bail;
}
+
+ if(is_bad_inode(inode)) {
+ iput(inode);
+ inode = NULL;
+ goto bail;
+ }
+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
if (type == LOCAL_USER_QUOTA_SYSTEM_INODE ||
type == LOCAL_GROUP_QUOTA_SYSTEM_INODE ||
--
2.43.0
next prev parent reply other threads:[~2025-12-11 8:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-11 6:22 [syzbot] [ocfs2?] KASAN: use-after-free Read in ocfs2_check_dir_entry syzbot
2025-12-11 8:06 ` syzbot [this message]
2025-12-11 9:27 ` Forwarded: [PATCH] ocfs2: validate inline directory i_size during inode read syzbot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=693a7b9a.050a0220.4004e.02f7.GAE@google.com \
--to=syzbot+c897823f699449cc3eb4@syzkaller.appspotmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=syzkaller-bugs@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox