[PATCH v5 8/9] nvme-fabrics: allow to pass in keyring by name

Hannes Reinecke hare at suse.de
Mon Nov 23 07:32:37 PST 2026


On 11/23/26 1:29 PM, sashiko-bot at kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [High] nvme-fabrics: keyring= fails in nvmf_parse_options() for
>    CONFIG_NVME_KEYRING=m
> - [Medium] nvme-fabrics: match_int() in nvmf_parse_options() misparses
>    keyring names
> --
> 
> commit 357df670b0cbbd8ea5cc07d96b4413e6b84ca631
> Author: Hannes Reinecke <hare at kernel.org>
> 
> nvme-fabrics: allow to pass in keyring by name
> 
> This commit updates the NVMe-oF option parser to accept a keyring name
> in addition to a numeric key serial ID for the keyring= option.
> 
>> diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
>> index 1277749c6e2e3..5dc1e1d5fb462 100644
>> --- a/drivers/nvme/host/fabrics.c
>> +++ b/drivers/nvme/host/fabrics.c
> 
> [ ... ]
> 
>> @@ -697,7 +698,7 @@ static const match_table_t opt_tokens = {
>>   	{ NVMF_OPT_NR_POLL_QUEUES,	"nr_poll_queues=%d"	},
>>   	{ NVMF_OPT_TOS,			"tos=%d"		},
>>   #ifdef CONFIG_NVME_TCP_TLS
>> -	{ NVMF_OPT_KEYRING,		"keyring=%d"		},
>> +	{ NVMF_OPT_KEYRING,		"keyring=%s"		},
>>   	{ NVMF_OPT_TLS_KEY,		"tls_key=%d"		},
>>   #endif
>>   	{ NVMF_OPT_FAIL_FAST_TMO,	"fast_io_fail_tmo=%d"	},
>> @@ -992,17 +993,33 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
>>   			opts->tos = token;
>>   			break;
>>   		case NVMF_OPT_KEYRING:
>> +#ifdef CONFIG_NVME_KEYRING
>>   			if (match_int(args, &key_id) || key_id <= 0) {
> 
> [Severity: Medium]
> Can match_int() misparse a keyring name that starts with a positive
> number (such as "1nvme") as a numeric key serial ID?
> 
> Because opt_tokens now matches keyring=%s instead of %d, args[0] spans
> the entire string without requiring all characters to be digits.
> match_int() -> match_number() calls simple_strtol(buf, &endp, 0) and
> only checks endp == buf, ignoring trailing non-numeric characters on
> strings under 24 bytes.  A keyring name with a leading positive integer
> will therefore take the else branch and pass that prefix to
> nvmf_parse_key(key_id) instead of looking up the keyring by name via
> request_key().
> 
Yes, it can. but this will be a user error.

>> -				ret = -EINVAL;
>> -				goto out;
>> -			}
>> -			key = nvmf_parse_key(key_id);
>> -			if (IS_ERR(key)) {
>> -				ret = PTR_ERR(key);
>> -				goto out;
>> +				p = match_strdup(args);
>> +				if (!p) {
>> +					ret = -ENOMEM;
>> +					goto out;
>> +				}
>> +				key = request_key(&key_type_keyring, p, NULL);
>> +				kfree(p);
>> +				if (IS_ERR(key)) {
>> +					ret = PTR_ERR(key);
>> +					goto out;
>> +				}
>> +			} else {
>> +				key = nvmf_parse_key(key_id);
>> +				if (IS_ERR(key)) {
>> +					ret = PTR_ERR(key);
>> +					goto out;
>> +				}
>>   			}
>>   			key_put(opts->keyring);
>>   			opts->keyring = key;
>> +#else
>> +			pr_warn("nvme keyring is disabled\n");
>> +			ret = -EINVAL;
>> +			goto out;
>> +#endif
> 
> [Severity: High]
> Does #ifdef CONFIG_NVME_KEYRING reject all keyring= options with
> -EINVAL when CONFIG_NVME_KEYRING=m?
> 
> NVME_KEYRING is a tristate Kconfig symbol, so modular builds define
> CONFIG_NVME_KEYRING_MODULE rather than CONFIG_NVME_KEYRING, causing
> nvmf_parse_options() to compile the #else branch and fail controller
> creation.  Should this use #if IS_ENABLED(CONFIG_NVME_KEYRING) (like
> include/linux/nvme-keyring.h)?
> 
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