Repository navigation
Description
This is the 3.x counterpart of linux-nvme/libnvme#1150, which fixes the same problem in the legacy libnvme. I found it by reading the code. I'm working on a fix. Created this issue for tracking. As usual, a test will come with the fix.
Problem
- The topology scan reads the DH-HMAC-CHAP secret of each live controller and copies it into the host object (
libnvme_scan_ctrl()intree-linux.c). Each controller overwrites the previous one, so the host ends up with the secret of the last controller scanned, whatever its subsystem. build_options()infabrics.csends the host key. It uses the key of the controller only when the host has no key.setup_connection()infabrics.cstores the key of the connection (fctx->hostkey) in the host object. The host object is shared by all the connections of a global context.
nvme connect and nvme connect-all scan the topology before they connect.
The scan copy dates from 2021, when the DH-HMAC-CHAP key was modeled as one key per host. Keys per controller came in 2022, and the INI schema binds them to the (host, subsystem) pair, but the scan and build_options() still follow the first model.
Consequences
nvme connectto subsystem A without--kxchap-secretsends the secret of a live controller of subsystem B.nvme connect-all(or autoconnect) with several entries: an entry withoutkxchap-secretsends the key of an earlier entry, or the scanned secret of another subsystem.- A program that sets the key on the controller (
libnvme_ctrl_set_kxchap_host_key(), thenlibnvmf_add_ctrl(), for example through the Python bindings) sends the scanned host key instead. If subsystem A requires authentication, the connect fails.
An entry that has its own kxchap-secret is not affected: setup_connection() replaces the scanned secret with it.
Proposed fix
- Do not copy the secret into the host during the scan. The controller keys of a live controller are already read per controller (
libnvmf_ctrl_load_fabrics_attrs()). - Do not store the key of a connection in the host object.
fctx->hostkeyis already set on the controller. - In
build_options(), use the controller key first, then the host key.
The second patch of #1150 (nvme config --scan --update saves the scanned secret) has no 3.x counterpart: the INI configuration does not write a scanned host key.
Activity
libnvme: do not share the DH-HMAC-CHAP secret through the host