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

Hannes Reinecke hare at suse.de
Tue Nov 24 01:21:45 PST 2026


On 11/23/26 6:30 PM, sashiko-bot at kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [Medium] nvme-fabrics: keyring=<id> fails in nvmf_parse_key() when TLS
>    is disabled
> - [Medium] nvme-fabrics: match_int() in nvmf_parse_options() misparses
>    keyring names
> --
> 
> commit 1438f3b90feece0503d30638e100925a9591818f
> Author: Hannes Reinecke <hare at kernel.org>
> 
> nvme-fabrics: allow to pass in keyring by name
> 
> This commit updates the fabrics keyring= option to accept keyring names via
> request_key() in addition to numeric key serial IDs, and guards the option
> with CONFIG_NVME_KEYRING instead of CONFIG_NVME_TCP_TLS.
> 
>> diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
>> index 2937e5dc9ecd2..aae094bbbf0dd 100644
>> --- a/drivers/nvme/host/fabrics.c
>> +++ b/drivers/nvme/host/fabrics.c
>> @@ -14,6 +14,7 @@
>>   #include "fabrics.h"
>>   #include <linux/nvme-auth.h>
>>   #include <linux/nvme-keyring.h>
>> +#include <linux/key-type.h>
>>   
>>   static DECLARE_RWSEM(nvmf_transports_rwsem);
>>   static LIST_HEAD_GUARDED(nvmf_transports, nvmf_transports_rwsem);
>> @@ -696,8 +697,10 @@ static const match_table_t opt_tokens = {
>>   	{ NVMF_OPT_NR_WRITE_QUEUES,	"nr_write_queues=%d"	},
>>   	{ NVMF_OPT_NR_POLL_QUEUES,	"nr_poll_queues=%d"	},
>>   	{ NVMF_OPT_TOS,			"tos=%d"		},
>> +#if IS_ENABLED(CONFIG_NVME_KEYRING)
>> +	{ NVMF_OPT_KEYRING,		"keyring=%s"		},
>> +#endif
>>   #ifdef CONFIG_NVME_TCP_TLS
>> -	{ NVMF_OPT_KEYRING,		"keyring=%d"		},
>>   	{ NVMF_OPT_TLS_KEY,		"tls_key=%d"		},
>>   #endif
>>   	{ NVMF_OPT_FAIL_FAST_TMO,	"fast_io_fail_tmo=%d"	},
>> @@ -992,17 +995,29 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
>>   			opts->tos = token;
>>   			break;
>>   		case NVMF_OPT_KEYRING:
>> +#if IS_ENABLED(CONFIG_NVME_KEYRING)
>>   			if (match_int(args, &key_id) || key_id <= 0) {
> 
> [Severity: Medium]
> Can match_int() misparse a keyring name that starts with digits as a
> numeric serial ID?
> 
> Because opt_tokens now matches keyring=%s, args[0] holds the full string.
> match_int() calls match_number(), which uses simple_strtol() and only
> checks endp == buf without verifying that the entire string was consumed:
> 
> lib/parser.c:match_number() {
>      ...
> 	val = simple_strtol(buf, &endp, base);
> 	if (endp == buf)
> 		ret = -EINVAL;
>      ...
> }
> 
> Any keyring name shorter than 24 bytes beginning with a positive integer
> prefix (such as "1nvme") returns 0 from match_int() with key_id > 0,
> routing the truncated prefix to nvmf_parse_key() instead of looking up the
> keyring by name with request_key().
> 
Inverted the check for the next version.

>> -				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;
>> +				}
>>   			}
> 
> [Severity: Medium]
> Does passing a keyring by serial number fail when CONFIG_NVME_HOST_AUTH is
> enabled but CONFIG_NVME_TCP_TLS is disabled?
> 
> NVMF_OPT_KEYRING is now guarded by CONFIG_NVME_KEYRING (which is also
> selected by CONFIG_NVME_AUTH), and keyring=<name> succeeds via
> request_key().  However, the numeric path calls nvmf_parse_key(), which
> still requires CONFIG_NVME_TCP_TLS:
> 
> drivers/nvme/host/fabrics.c:nvmf_parse_key() {
> 	struct key *key;
> 
> 	if (!IS_ENABLED(CONFIG_NVME_TCP_TLS)) {
> 		pr_err("TLS is not supported\n");
> 		return ERR_PTR(-EINVAL);
> 	}
>      ...
> }
> 
> In addition, NVMF_ALLOWED_OPTS includes NVMF_OPT_DHCHAP_SECRET and
> NVMF_OPT_DHCHAP_CTRL_SECRET for all transports, which use opts->keyring in
> nvmf_parse_options(), but NVMF_OPT_KEYRING is still only set in
> nvme_tcp_transport.allowed_opts and omitted from NVMF_ALLOWED_OPTS.
> 
Fixed for 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