[PATCH v7 12/14] nvme-fabrics: allow to pass in keyring by name

Hannes Reinecke hare at suse.de
Fri Nov 27 02:14:49 PST 2026


On 11/26/26 3:31 PM, sashiko-bot at kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 8 potential
> issues to consider:
> - [High] nvme-fabrics: NULL dereference and key leak in
>    nvmf_parse_options()
> - [High] nvme-fabrics: missing keyring link and key leak in
>    tls_keyring_store()
> - [High] nvme-fabrics: vmlinux link failure when CONFIG_NVME_KEYRING=m
> - [High] nvme-keyring: broken header stubs when CONFIG_NVME_KEYRING=n
> - [Medium] nvme-fabrics: unstripped newline in tls_keyring_store()
>    breaks lookup
> - [Medium] nvme-fabrics: missing key type and state checks in keyring ID
>    fallback
> - [Medium] nvme-fabrics: unsynchronized opts->keyring access in
>    tls_keyring_store()
> - [Low] nvme-fabrics: unreachable !keyring path in
>    nvme_tls_attrs_are_visible()
> --
> 
> commit cea520ca62b4a11b68d9d8f8ca9eeea627f871dd
> Author: Hannes Reinecke <hare at kernel.org>
> 
> nvme-fabrics: allow to pass in keyring by name
> 
> This commit allows specifying the fabrics keyring option by name in
> addition to serial number, enables the keyring option for all fabrics
> transports, and makes the tls_keyring sysfs attribute writable.
> 
>> diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
>> index bba6a4848f227..12a30ed16f9ef 100644
>> --- a/drivers/nvme/host/fabrics.c
>> +++ b/drivers/nvme/host/fabrics.c
>> @@ -663,8 +663,8 @@ static struct key *nvmf_parse_key(int key_id)
>>   {
>>   	struct key *key;
>>   
>> -	if (!IS_ENABLED(CONFIG_NVME_TCP_TLS)) {
>> -		pr_err("TLS is not supported\n");
>> +	if (!IS_ENABLED(CONFIG_NVME_KEYRING)) {
>> +		pr_err("nvme keyring is not supported\n");
>>   		return ERR_PTR(-EINVAL);
>>   	}
> 
> [Severity: High]
> Can this fail to link vmlinux when CONFIG_NVME_KEYRING=m?
> 
> IS_ENABLED(CONFIG_NVME_KEYRING) is true when NVME_KEYRING is a module,
> while NVME_FABRICS in drivers/nvme/host/Kconfig only selects NVME_KEYRING
> if NVME_TCP_TLS is enabled.  If CONFIG_NVME_FABRICS=y (with
> CONFIG_NVME_TCP_TLS=n and CONFIG_NVME_HOST_AUTH=n) and
> CONFIG_NVME_KEYRING=m (for example via CONFIG_NVME_TARGET=m), built-in
> fabrics.o references nvme_tls_key_lookup() and nvme_keyring_link() in
> nvme-keyring.ko.  Similarly, when CONFIG_NVME_CORE=y, CONFIG_NVME_TCP=m,
> and CONFIG_NVME_TCP_TLS=y, NVME_FABRICS=m selects CONFIG_NVME_KEYRING=m,
> so built-in drivers/nvme/host/sysfs.o fails to link against
> nvme_keyring_name() and nvme_keyring_unlink().
> 
Modified Kconfig selection to include NVME_AUTH when selecting NVME_KEYRING

> [ ... ]
> 
>> @@ -993,14 +995,24 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
>>   			opts->tos = token;
>>   			break;
>>   		case NVMF_OPT_KEYRING:
>> -			if (match_int(args, &key_id) || key_id <= 0) {
>> -				ret = -EINVAL;
>> +#if IS_ENABLED(CONFIG_NVME_KEYRING)
>> +			p = match_strdup(args);
>> +			if (!p) {
>> +				ret = -ENOMEM;
>>   				goto out;
>>   			}
>> -			key = nvmf_parse_key(key_id);
>> +			key = request_key(&key_type_keyring, p, NULL);
>> +			kfree(p);
>>   			if (IS_ERR(key)) {
>> -				ret = PTR_ERR(key);
>> -				goto out;
>> +				if (match_int(args, &key_id) || key_id <= 0) {
>> +					ret = -EINVAL;
>> +					goto out;
>> +				}
>> +				key = nvmf_parse_key(key_id);
>> +				if (IS_ERR(key)) {
>> +					ret = PTR_ERR(key);
>> +					goto out;
>> +				}
>>   			}
>>   			ret = nvme_keyring_link(opts->keyring);
>>   			if (ret) {
>> @@ -1008,6 +1020,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
>>   				goto out;
>>   			}
>>   			opts->keyring = key;
>> +#endif
>>   			break;
> 
> [Severity: High]
> Does nvme_keyring_link(opts->keyring) pass NULL instead of the newly
> looked-up key?
> 
> On the first keyring= option, opts->keyring is NULL, so
> nvme_keyring_link(NULL) calls key_link(nvme_keyring, NULL) ->
> __key_link_lock(), triggering a NULL pointer dereference on
> index_key->type with nvme_keyring->sem held write-locked.  If keyring= is
> specified more than once in the option string, the previous opts->keyring
> is also overwritten without being unlinked or released with key_put().
> 
Fixed with the next version.

> [Severity: High]
> Does guarding this block with #if IS_ENABLED(CONFIG_NVME_KEYRING) expose
> broken stubs in include/linux/nvme-keyring.h when CONFIG_NVME_KEYRING=n?
> 
Fixed by modifying Kconfig selection in the next patch.

> include/linux/nvme-keyring.h {
>      ...
> static const char *nvme_keyring_name(void)
> {
> 	return NULL;
> }
> static int nvme_keyring_link(struct key *keyring)
> {
> 	return 0;
> }
> int nvme_keyring_unlink(struct key *keyring)
> {
> 	return 0;
> }
>      ...
> }
> 
> When CONFIG_NVME_KEYRING is disabled, nvme_keyring_unlink() is defined as
> a non-static function in the header, causing multiple-definition linker
> errors across fabrics.o, sysfs.o, and tcp.o, while the non-inline static
> nvme_keyring_link() stub becomes unused in fabrics.c and triggers
> -Wunused-function.
> 
Fixed with the next version.

>> diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
>> index 4ebc03a8ddcae..0ffea12fcfb6b 100644
>> --- a/drivers/nvme/host/sysfs.c
>> +++ b/drivers/nvme/host/sysfs.c
>> @@ -1212,7 +1212,38 @@ static ssize_t tls_keyring_show(struct device *dev,
>>   		return sysfs_emit(buf, "%s\n", nvme_keyring_name());
>>   	return sysfs_emit(buf, "%s\n", keyring->description);
>>   }
>> -static DEVICE_ATTR_RO(tls_keyring);
>> +
>> +static ssize_t tls_keyring_store(struct device *dev,
>> +		struct device_attribute *attr, const char *buf, size_t count)
>> +{
>> +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
>> +	struct key *keyring = ctrl->opts->keyring;
>> +	int ret;
>> +
>> +	keyring = request_key(&key_type_keyring, buf, NULL);
> 
> [Severity: Medium]
> Does passing buf directly to request_key() without stripping a trailing
> newline break keyring lookup by name from sysfs?
> 
> Writes such as "echo my_keyring > tls_keyring" pass "my_keyring\n" to
> request_key(), which fails with -ENOKEY and falls through to kstrtoul(),
> returning -EINVAL.  Other sysfs handlers in this file (such as
> dhchap_secret_store()) strip the trailing newline with strcspn(buf, "\n").
> 
Dropped this hunk from the next version, so all reviews to this function
no longer apply.

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