[PATCH v7 14/14] nvme-auth: allow to update pre-provisioned keys

Hannes Reinecke hare at suse.de
Fri Nov 27 02:48:36 PST 2026


On 11/26/26 3:31 PM, sashiko-bot at kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential
> issues to consider:
> - [High] nvme-auth: uninitialized old_key dereference in
>    dhchap_*_secret_store()
> - [High] nvme-keyring: .update callback added to psk instead of dhchap
>    key_type
> - [Medium] nvme-auth: wrong pre-populated key check in
>    dhchap_*_secret_store()
> --
> 
> commit 3ccb1f2ff3d815bafe5e4d68e5e266a56f5a6f51
> Author: Hannes Reinecke <hare at kernel.org>
> 
> nvme-auth: allow to update pre-provisioned keys
> 
> This commit attempts to support rotating pre-provisioned DH-HMAC-CHAP keys
> via keyctl update by adding a key_type .update callback and disallowing
> sysfs key replacements for pre-populated controller keys.
> 
>> diff --git a/drivers/nvme/common/keyring.c b/drivers/nvme/common/keyring.c
>> index bee64c592752a..ffabd37cd090d 100644
>> --- a/drivers/nvme/common/keyring.c
>> +++ b/drivers/nvme/common/keyring.c
>> @@ -100,6 +100,7 @@ static struct key_type nvme_tls_psk_key_type = {
>>   	.free_preparse  = user_free_preparse,
>>   	.match_preparse = nvme_tls_psk_match_preparse,
>>   	.instantiate    = generic_key_instantiate,
>> +	.update         = user_update,
>>   	.revoke         = user_revoke,
>>   	.destroy        = user_destroy,
>>   	.describe       = nvme_tls_psk_describe,
> 
> [Severity: High]
> Was .update added to nvme_tls_psk_key_type instead of
> nvme_dhchap_psk_key_type?  Because nvme_dhchap_psk_key_type still has no
> .update callback, calling keyctl update on a dhchap key fails with
> -EOPNOTSUPP.
> 
Fixed with the next version.

>> diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
>> index 0ffea12fcfb6b..0eb68b3973a1e 100644
>> --- a/drivers/nvme/host/sysfs.c
>> +++ b/drivers/nvme/host/sysfs.c
>> @@ -887,9 +887,17 @@ static ssize_t dhchap_secret_store(struct device *dev,
>>   		kfree_sensitive(dhchap_secret);
>>   		return ret;
>>   	}
>> +	if (!generated &&
>> +	    key_serial(old_key) != key_serial(key)) {
> 
> [Severity: Medium]
> Should this check !ctrl->host_key_generated under ctrl->dhchap_auth_mutex
> instead of !generated (and similarly !ctrl->ctrl_key_generated in
> dhchap_ctrl_secret_store())?
> 
> nvme_auth_extract_key() sets generated based on whether the newly written
> sysfs input is a raw DHHC-1 secret or an existing key lookup, not whether
> the controller's current key was pre-populated.  Writing a raw DHHC-1
> secret sets generated = true, bypassing this check and overwriting a
> pre-populated ctrl->host_key with a newly generated key, while writing a
> pre-populated key identifier to a controller that currently uses a
> generated key is rejected with -EPERM.
> 
Fixed up in the next version.

>> +		dev_warn(ctrl->device, "cannot change pre-populated key %08x\n",
>> +			 key_serial(old_key));
>> +		key_put(key);
>> +		kfree_sensitive(dhchap_secret);
>> +		return -EPERM;
>> +	}
>>   	mutex_lock(&ctrl->dhchap_auth_mutex);
>>   	old_key = ctrl->host_key;
> 
> [Severity: High]
> Does key_serial(old_key) dereference an uninitialized old_key pointer in
> both dhchap_secret_store() and dhchap_ctrl_secret_store()?
> 
> old_key is declared on the stack without an initializer and is only
> assigned from ctrl->host_key (or ctrl->ctrl_key) after acquiring
> ctrl->dhchap_auth_mutex below.  When writing a pre-populated key to sysfs
> (generated == false), key_serial(old_key) reads old_key->serial from the
> uninitialized pointer, or returns 0 when CONFIG_INIT_STACK_ALL_ZERO=y and
> causes every re-authentication write to fail with -EPERM.
> 
Fixed with the next version.

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