Skip to content

libnvme/test: fix use after free in test_nvmf_sanitize_addrs() - #3759

Open
LJaved-IBM wants to merge 1 commit into
linux-nvme:masterfrom
LJaved-IBM:fix-use-after-free-test-fabrics
Open

libnvme/test: fix use after free in test_nvmf_sanitize_addrs()#3759
LJaved-IBM wants to merge 1 commit into
linux-nvme:masterfrom
LJaved-IBM:fix-use-after-free-test-fabrics

Conversation

@LJaved-IBM

Copy link
Copy Markdown

If libnvme_create_ctrl() fails, @c is NULL. The subsequent calls to nvmf_sanitize_addrs() and libnvme_free_ctrl() are then made with a NULL pointer, resulting in a use after free.

Guard each nvmf_sanitize_addrs() and libnvme_free_ctrl() block with if (c) to skip the sanitize and free steps when controller creation failed.

Comment thread libnvme/test/test-fabrics.c Outdated
p = ret == -ENVME_CONNECT_TRADDR;
CHECK(p, "hostname host_traddr rejected at connect: %d", ret);
pass &= p;
if (c) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just fail the complete test when libnvme_create_ctrl fails. No point to continue after this point, e.g.

libnvme_create_ctrl(ctx, &params, &c);
shr_assert(c);
p = !strcmp(libnvme_ctrl_get_host_traddr(c), "storage.example.com");

Tests are allowed to completely fail on the first error.

If libnvme_create_ctrl() fails and returns NULL, the subsequent calls
to nvmf_sanitize_addrs() and libnvme_free_ctrl() are made with a NULL
pointer, resulting in a use after free.

Fail the test immediately when controller creation fails by checking
the returned pointer with CHECK() and returning false, so the cause
of any setup failure is immediately visible without proceeding with
invalid state.

Coverity CID: 561730 (Use after free)

Signed-off-by: Laraib Javed <laraib.javed@ibm.com>
@LJaved-IBM
LJaved-IBM force-pushed the fix-use-after-free-test-fabrics branch from 5458216 to 06310e0 Compare August 7, 2026 15:53
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.

2 participants