Re: [PATCH] nvme-fc: fix double free of fabrics options when nvme_add_ctrl() fails
Keith Busch <[email protected]>
| Newsgroups | org.infradead.lists.linux-nvme,org.kernel.vger.stable |
|---|---|
| Message-ID | <an9Co6vHIqggWNIf@kbusch-mbp> |
On Fri, Aug 14, 2026 at 04:38:34PM +0200, Niklas Cassel wrote: > ctrl->ctrl.opts also stays valid for the whole teardown now. That is > not the bug being fixed, but it removes some fragility around the old > idiom: nvme_free_ctrl() calls nvme_auth_free() before ->free_ctrl(), and > ctrl_max_dhchaps() dereferences ctrl->opts without a NULL check when > ctrl->dhchap_ctxs is set, which nvme-fc permits since NVMF_ALLOWED_OPTS > allows the dhchap options. The nvme sysfs attributes that dereference > ctrl->opts, such as hostnqn and address, evaluate their is_visible() > test once at device_add() time and stay readable until > cdev_device_del(). The allocation that ctrl.opts points is freed in this error path, so any access after that is a use-after-free that needs to be fixed. I think setting opts to NULL is easier than the proxy locked list check.