From f6db510acfddd1ff73baad8e6244c87bd6ef2771 Mon Sep 17 00:00:00 2001 From: Bas van Loon Date: Mon, 28 Jul 2025 12:55:25 +0200 Subject: [PATCH] fs/ext2: Fix NULL dereference when fs_stat queries root. When fs_stat() queries the root / mountpoint it should return its root i_node but instead it tries to return the parent i_node which does not exist. Fix this by checking if parent is set otherwise return the root i_node. Fixes https://github.com/zephyrproject-rtos/zephyr/issues/94000. Signed-off-by: Bas van Loon (cherry picked from commit 1dcf123e2de81081cf1eced0647db08ad73c4b91) --- subsys/fs/ext2/ext2_ops.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/subsys/fs/ext2/ext2_ops.c b/subsys/fs/ext2/ext2_ops.c index 509a1c1b73d57..445cb3772aa1a 100644 --- a/subsys/fs/ext2/ext2_ops.c +++ b/subsys/fs/ext2/ext2_ops.c @@ -598,12 +598,11 @@ static int ext2_stat(struct fs_mount_t *mountp, const char *path, struct fs_dire } uint32_t offset = args.offset; - struct ext2_inode *parent = args.parent; - struct ext2_file dir = {.f_inode = parent, .f_off = offset}; + struct ext2_file dir = {.f_inode = args.parent ? args.parent : args.inode, .f_off = offset}; rc = ext2_get_direntry(&dir, entry); - ext2_inode_drop(parent); + ext2_inode_drop(args.parent); ext2_inode_drop(args.inode); return rc; }