Root Cause Analysis
1. Relevant Functions, Structs, and Files
2. Technical Mechanism and Lifecycle Violation
When a filesystem context is created for a new mount (via fsopen("ext2", ...)), fc->purpose is initialized to FS_CONTEXT_FOR_MOUNT, and fc->source is initially NULL. fc->source is only populated when userspace explicitly supplies the "source" parameter (handled by vfs_parse_fs_param_source()).
Under the mount API (fsconfig), userspace is permitted to configure filesystem mount parameters in arbitrary order before issuing FSCONFIG_CMD_CREATE. Furthermore, userspace may configure parameters without ever providing a "source" parameter.
In fs/ext2/super.c, ext2_msg_fc() formats and emits log messages during mount context processing:
static void ext2_msg_fc(struct fs_context *fc, const char *prefix,
const char *fmt, ...)
{
struct va_format vaf;
va_list args;
const char *s_id;
if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) {
s_id = fc->root->d_sb->s_id;
} else {
/* get last path component of source */
s_id = strrchr(fc->source, '/');
if (s_id)
s_id++;
else
s_id = fc->source;
}
...
When fc->purpose != FS_CONTEXT_FOR_RECONFIGURE (e.g. for any new mount context):
ext2_msg_fc() enters the else branch and unconditionally executes s_id = strrchr(fc->source, '/'); without verifying whether fc->source is NULL.
- Several options in
ext2_parse_param() invoke ext2_msg_fc() to log informational or deprecation/warning messages:
Opt_dax: ext2_msg_fc(fc, KERN_WARNING, "DAX support has been removed. dax option ignored."); (line 598)
Opt_xip: ext2_msg_fc(fc, KERN_WARNING, "DAX support has been removed. xip option ignored."); (line 595)
Opt_nobh: ext2_msg_fc(fc, KERN_INFO, "nobh option not supported\n"); (line 568)
Opt_reservation: ext2_msg_fc(fc, KERN_INFO, "reservations ON/OFF"); (lines 620, 623)
- Unsupported
user_xattr, acl, or quota configurations (lines 579, 591, 614)
- If userspace sends an
fsconfig() request for one of these options (such as "dax" via FSCONFIG_SET_FLAG) before "source" has been configured, fc->source is NULL.
strrchr(NULL, '/') is invoked, immediately reading through r0 = 0x00000000 (ldrb r2, [r0], #1 in arch/arm/lib/strrchr.S:16), resulting in the reported kernel NULL pointer dereference crash.