Skip to content

Do not let a scanned dhchap secret override a configured key - #1150

Merged
igaw merged 2 commits into
linux-nvme:masterfrom
joaquinv98:dhchap-host-key
Oct 14, 2026
Merged

igaw merged 2 commits into
linux-nvme:masterfrom
joaquinv98:dhchap-host-key

Conversation

@joaquinv98

Copy link
Copy Markdown
Contributor

When a host already has a controller connected to subsystem B, nvme connect --config for subsystem A sends the secret of B instead of the key configured for A, and the connect fails with an authentication error. The topology scan copies the live secret into the host object and it then wins over the configured key, at host or port level.

The first patch keeps a key set by the caller and prefers a usable port key over a scanned secret. A host key set by the caller still wins over a port key, as before, and with no key configured at all it still falls back to the scanned secret. The second patch stops nvme config --scan --update from saving a scanned secret as the host key.

Tested with nvmet over TCP and nvme-cli 2.x, which already skips connected controllers in connect --config (linux-nvme/nvme-cli#4150).

nvme_scan_ctrl() copies the dhchap_secret of every live controller that
has one into its host object. So when a host has a controller connected
to subsystem B, 'nvme connect --config' for subsystem A sends the secret
of B instead of the key configured for A, and authentication fails. A
key set on the port loses too, because build_options() prefers the host
key.

Remember whether the host key was read from sysfs. A scanned secret no
longer replaces a key set by the caller, and a usable host key of the
controller itself, like the 'dhchap_key' of its port, now wins over a
scanned one.

Add a test that fakes sysfs and /dev/nvme-fabrics.

Fixes: b547cdb ("Implement 'dhchap_key' host and controller attributes")
Fixes: 6614a55 ("Parse dhchap_host_key on controller level")
Signed-off-by: Joaquin Varela <joaquinvarela@neatech.ar>
After a scan the host key can be the secret of a live controller.
json_update_config() writes it as the host 'dhchap_key', so
'nvme config --scan --update' saves the key of one subsystem as the key
of the whole host.

Only write a host key that was set by the caller. Extend the dhchap-key
test for this.

Fixes: b547cdb ("Implement 'dhchap_key' host and controller attributes")
Signed-off-by: Joaquin Varela <joaquinvarela@neatech.ar>
@igaw

igaw commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Do we need something similar in nvme-cli/libnvme 3.x? We did some major surgery in this area but I lost overview what we have done there. @martin-belanger

@martin-belanger

Copy link
Copy Markdown
Contributor

Do we need something similar in nvme-cli/libnvme 3.x? We did some major surgery in this area but I lost overview what we have done there. @martin-belanger

Yes, 3.x has the same problem. The scan copies each live controller's dhchap_secret into the host, and build_options() prefers the host key. So a connect without a configured key sends the secret of another subsystem. Let me look closer into it. I'll submit a PR.

@igaw
igaw merged commit ad14310 into linux-nvme:master Oct 14, 2026
12 checks passed
@igaw

igaw commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

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