[PATCH v3 2/2] nvme-auth: fix data race on ctrl->transaction
Hannes Reinecke
hare at suse.de
Mon Nov 16 23:23:38 PST 2026
On 11/16/26 4:37 PM, Keith Busch wrote:
> On Mon, Nov 16, 2026 at 02:22:51PM +0100, Hannes Reinecke wrote:
>> 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 the proposal *is* unique within the queue. It's just not unique at
> the controller level, and it sounds like the protocol doesn't need to
> be.
>
>> 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.
>
> I don't understand. The qid:T_ID tuple already identifies the
> transaction. If a controller mixes up transactions across queues, it's
> already broken in ways we can't fix, so we shouldn't design around it.
>
>> It should be possible to move the controller value to an atomic
>> value, and then we could do
>
> If there's no protocol reason to require this type of uniqueness, then
> I'm not seeing why the driver is putting this constraint on itself.
It's somewhat ambiguous.
Spec says 'carrying the same transaction identifier value for the entire
authentication transaction' (for AUTH_negotiate), and later on 'carrying
the same transaction identifier' (for any other AUTH message).
So actually we just have to make sure they are identical.
(The random number is '4' ...)
But the overall idea here is to distinguish transactions, so the
implication is that each transaction should carry different identifiers.
And my issue here is precisely 'each transaction'. Surely within each
queue, but I'd really would want to distinguish _across_ queues, too.
(And possibly with a random starting value to boot).
Just to avoid any fuzzers trying to be clever with guessing the
authentication ID (or bugs setting the transaction ID to 0 for every
queue ... same reason why we introduced the 'genctr' for the command
ID).
But if you don't feel that's an issue, fine, I'll be shutting up.
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare at suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
More information about the Linux-nvme
mailing list