Skip to content

Conversation

@stephenchengCloud
Copy link

The nvme_host_get_hostid() and nvme_host_get_hostnqn() functions can return NULL when the host configuration is incomplete or invalid. Using strdup() directly on these return values causes a segmentation fault when NULL is passed to strdup().

Replace strdup() calls with xstrdup() to safely handle NULL input values.

The nvme_host_get_hostid() and nvme_host_get_hostnqn() functions can
return NULL when the host configuration is incomplete or invalid. Using
strdup() directly on these return values causes a segmentation fault
when NULL is passed to strdup().

Replace strdup() calls with xstrdup() to safely handle NULL input
values.

Signed-off-by: Stephen Cheng <[email protected]>
@stephenchengCloud
Copy link
Author

Here is the crash I observed:

(gdb) bt
#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
#1  0x00007fd6be066933 in __GI___strdup (s=0x0) at strdup.c:41
#2  0x00007fd6be209786 in nvme_host_get_ids (r=r@entry=0x55d846da9540, hostnqn_arg=0x0, hostid_arg=<optimized out>, hostnqn=hostnqn@entry=0x7ffd51ef5a20,
    hostid=hostid@entry=0x7ffd51ef5a18) at ../src/nvme/tree.c:150
#3  0x000055d82ae43a18 in nvmf_discover (desc=0x55d82af35b80 "Discover NVMeoF subsystems and connect to them", argc=<optimized out>, argv=<optimized out>,
    connect=<optimized out>) at ../fabrics.c:763
#4  0x000055d82ae8c7a4 in handle_plugin (argc=8, argv=0x7ffd51ef85c0, plugin=0x55d82af7f820 <builtin>) at ../plugin.c:171
#5  0x000055d82ae4077c in main (argc=9, argv=0x7ffd51ef85b8) at ../nvme.c:9932
(gdb) frame 2
#2  0x00007fd6be209786 in nvme_host_get_ids (r=r@entry=0x55d846da9540, hostnqn_arg=0x0, hostid_arg=<optimized out>, hostnqn=hostnqn@entry=0x7ffd51ef5a20,
    hostid=hostid@entry=0x7ffd51ef5a18) at ../src/nvme/tree.c:150
150                             hid = strdup(nvme_host_get_hostid(h));

(gdb) info locals
nqn = 0x0
hid = <optimized out>
hnqn = 0x0
h = 0x55d846da9670

(gdb) x/gx 0x55d846da9670+0x30
0x55d846da96a0: 0x0000000000000000

@igaw igaw merged commit d65b44c into linux-nvme:master Nov 25, 2025
12 checks passed
@igaw
Copy link
Collaborator

igaw commented Nov 25, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants