Skip to content

libnvme: a connect can send the DH-HMAC-CHAP secret of another subsystem #4165

Closed

Description

@martin-belanger

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

  1. The topology scan reads the DH-HMAC-CHAP secret of each live controller and copies it into the host object (libnvme_scan_ctrl() in tree-linux.c). Each controller overwrites the previous one, so the host ends up with the secret of the last controller scanned, whatever its subsystem.
  2. build_options() in fabrics.c sends the host key. It uses the key of the controller only when the host has no key.
  3. setup_connection() in fabrics.c stores 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 connect to subsystem A without --kxchap-secret sends the secret of a live controller of subsystem B.
  • nvme connect-all (or autoconnect) with several entries: an entry without kxchap-secret sends 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(), then libnvmf_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->hostkey is 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

  1. added a commit that references this issue on Oct 14, 2026
    859c890
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions