Re: [PATCH] nvme-fc: fix double free of fabrics options when nvme_add_ctrl() fails
Niklas Cassel <[email protected]>
| Newsgroups | org.infradead.lists.linux-nvme,org.kernel.vger.stable |
|---|---|
| Message-ID | <aoX2wcyhpakryWHX@ryzen> |
Hello Keith, On Wed, Aug 19, 2026 at 09:28:08AM -0600, Keith Busch wrote: > On Mon, Aug 17, 2026 at 05:10:23PM +0200, Niklas Cassel wrote: > > It seems like Keith did prefer your patch, but as you said, your patch does > > not avoid a NULL pointer dereference in nvme_auth_free(). > > But you're replacing a NULL pointer dereference to a derefence to freed > memory. That should be fixed too, and I'm just saying checking a pointer > for NULL before dereferencing it is more clear than checking if a list > is empty. I am not following. The options is freed in two different places, depending on if the ops->create_ctrl(dev, opts) call in fabrics.c:nvmf_create_ctrl() was successful or not. If the ops->create_ctrl(dev, opts) call in fabrics.c:nvmf_create_ctrl() was successful, the teardown path will be: core.c:nvme_free_ctrl(), which calls nvme_auth_free() (which will use the options), nvme_free_ctrl() will then call ctrl->ops->free_ctrl(ctrl) which will free the options (since the ops->create_ctrl() call was successful, the ctrl will be on the linked-list). If the ops->create_ctrl(dev, opts) call in fabrics.c:nvmf_create_ctrl() fails, the teardown path will be: core.c:nvme_free_ctrl(), which calls nvme_auth_free() (which will use the options), nvme_free_ctrl() will then call ctrl->ops->free_ctrl(ctrl) which will not free the options (since the ops->create_ctrl() call failed, the ctrl will not be on the linked-list), fabrics.c:nvmf_create_ctrl() will thus goto out_module_put, which then does a goto out_free_opts, which calls nvmf_free_options(). In both cases, nvme_auth_free() will access memory that has not yet been freed. So I don't see us dereferencing freed memory. Kind regards, Niklas