Skip to content

EXT2 fs_stat on mount point fails with a NULL pointer dereference. #94000

@bas-archembedded

Description

@bas-archembedded

Describe the bug

Hello,

When calling fs_stat(<mount_point>) using the EXT2 filesystem, the call causes a NULL pointer dereference. The problem becomes really visible when enabling MPU protections for NULL pointers on our custom NXP RT117x based board. The issue should be fixed by returning the root inode when there is no parent inode present.

Regression

  • This is a regression.

Steps to reproduce

Build and run the following PR #93767 with the following modifications:

diff --git a/samples/subsys/fs/ext2_fstab/prj.conf b/samples/subsys/fs/ext2_fstab/prj.conf
index 9fccaa96d8a..0f610f8eea5 100644
--- a/samples/subsys/fs/ext2_fstab/prj.conf
+++ b/samples/subsys/fs/ext2_fstab/prj.conf
@@ -12,3 +12,15 @@ CONFIG_EXT2_FSTAB_AUTOMOUNT=y
 # Needed for MKFS
 CONFIG_ENTROPY_GENERATOR=y
 CONFIG_XOSHIRO_RANDOM_GENERATOR=y
+
+CONFIG_DEBUG_OPTIMIZATIONS=y
+CONFIG_DEBUG_THREAD_INFO=y
+
+# add asserts
+CONFIG_ASSERT=y
+CONFIG_ASSERT_VERBOSE=y
+CONFIG_ASSERT_NO_COND_INFO=n
+CONFIG_ASSERT_NO_MSG_INFO=n
+CONFIG_MPU_STACK_GUARD=y
+CONFIG_NULL_POINTER_EXCEPTION_DETECTION_MPU=y
+CONFIG_STACK_CANARIES=y
diff --git a/samples/subsys/fs/ext2_fstab/src/main.c b/samples/subsys/fs/ext2_fstab/src/main.c
index 79730160125..ceadc55930c 100644
--- a/samples/subsys/fs/ext2_fstab/src/main.c
+++ b/samples/subsys/fs/ext2_fstab/src/main.c
@@ -70,6 +70,12 @@ int main(void)
                return rc;
        }

+       rc = fs_stat(MOUNT_POINT, &stat);
+       if (rc != 0) {
+               LOG_ERR("File status check failed %d", rc);
+               return rc;
+       }
+
        LOG_INF("Filesystem access successful");

        return 0;

Relevant log output

*** Booting Zephyr OS build v4.2.0-731-g6879cb1ba4a0 ***
E: ***** MPU FAULT *****
E:   Data Access Violation
E:   MMFAR Address: 0x10
E: r0/a1:  0x00000000  r1/a2:  0x8401c68c  r2/a3:  0x00000001
E: r3/a4:  0x00000000 r12/ip:  0x00000000 r14/lr:  0x8000f233
E:  xpsr:  0x61000000
E: Faulting instruction address (r15/pc): 0x8000489e
E: >>> ZEPHYR FATAL ERROR 19: Unknown error on CPU 0
E: Current thread: 0x840010d8 (main)
E: Halting system

Impact

Showstopper – Prevents release or major functionality; system unusable.

Environment

  • Windows
  • zephyr-sdk 17.2
  • Zephyr 4.2

Additional Context

Ran on custom NXP RT117x based board.

Screenshot from debug:

Image

Metadata

Metadata

Assignees

Labels

area: File SystembugThe issue is a bug, or the PR is fixing a bugpriority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions