[PATCH v3 2/2] nvme-auth: fix data race on ctrl->transaction

Guixin Liu kanie at linux.alibaba.com
Mon Nov 16 18:16:15 PST 2026



在 2026/11/16 21:22, Hannes Reinecke 写道:
> On 11/16/26 9:12 AM, Guixin Liu wrote:
>> nvme_ctrl_auth_work() queues the DH-HMAC-CHAP exchange of every queue
>> on nvme-auth-wq without waiting for them, so multiple
>> nvme_queue_auth_work() instances run concurrently and all increment
>> ctrl->transaction in nvme_queue_auth_work(). The plain increment is a
>> data race, and the lost updates hand the same transaction id to
>> concurrent queues.
>>
>> The counter does not need to be shared at all: the controller only
>> echoes the transaction id within a queue, so a per-queue counter is
>> sufficient. Increment chap->transaction instead, drop the reset in
>> nvme_auth_reset_dhchap() so the id stays monotonic across
>> re-authentication, and remove the now unused ctrl->transaction field.
>>
> I disagree. The authentication transaction ID identifies the
> transaction itself, and is used to differentiate between different
> transactions. As such it needs to be unique within each queue.
> But as it carries controller-specific data we should also ensure
> the ID is unique per controller, ensuring we catch any possible
> misdirected authentication packet.
A misdirected packet is caught regardless of the transaction id.
Each queue's exchange carries its own random challenge:
nvmet_auth_challenge() fills req->sq->dhcahp_c1 with get_random_bytes()
per exchange, and the response digest covers that challenge.
A response computed for queue A fails the digest check on queue B even
when the transaction id and the step happen to match, because the
expected digest is different.

So controller-level uniqueness would only detect a case the crypto
layer already rejects, while within a queue the id is unique either
way.

Best Regards,
Guixin Liu
>
> It should be possible to move the controller value to an atomic
> value, and then we could do
>
> chap->transaction = atomic_inc_return(&ctrl->transaction);
>
> Cheers,
>
> Hannes




More information about the Linux-nvme mailing list