Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hannes Reinecke" <hare@kernel.org>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH v6 8/9] nvme-fabrics: allow to pass in keyring by name
Date: Mon, 23 Nov 2026 17:30:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-229752@kernel.org> (raw)
In-Reply-To: <20261123-dhchap-keyring-v4-v6-8-5082a49715ab@kernel.org>

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@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().

> -				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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-dhchap-keyring-v4-v6-0-5082a49715ab@kernel.org?part=8


  reply	other threads:[~2026-11-23 17:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 17:10 [PATCH v6 0/9] nvme-auth: switch to use the kernel keyring Hannes Reinecke
2026-11-23 17:10 ` [PATCH v6 1/9] nvme-auth: modify nvme_auth_transform_key() to return status Hannes Reinecke
2026-11-23 17:10 ` [PATCH v6 2/9] nvme-keyring: add 'dhchap' key type Hannes Reinecke
2026-11-23 17:31   ` sashiko-bot
2026-11-23 17:10 ` [PATCH v6 3/9] nvme-auth: switch to use 'struct key' Hannes Reinecke
2026-11-23 17:32   ` sashiko-bot
2026-11-23 17:10 ` [PATCH v6 4/9] nvme: parse dhchap keys during option parsing Hannes Reinecke
2026-11-23 17:26   ` sashiko-bot
2026-11-23 17:10 ` [PATCH v6 5/9] nvmet-auth: parse dhchap key from configfs attribute Hannes Reinecke
2026-11-23 17:30   ` sashiko-bot
2026-11-23 17:10 ` [PATCH v6 6/9] nvme: allow to pass in key description as dhchap secret Hannes Reinecke
2026-11-23 17:32   ` sashiko-bot
2026-11-23 17:10 ` [PATCH v6 7/9] nvme-auth: wait for authentication to finish when changing keys Hannes Reinecke
2026-11-23 17:10 ` [PATCH v6 8/9] nvme-fabrics: allow to pass in keyring by name Hannes Reinecke
2026-11-23 17:30   ` sashiko-bot [this message]
2026-11-23 17:10 ` [PATCH v6 9/9] nvmet: add configfs attribute 'dhchap_keyring' Hannes Reinecke
2026-11-23 17:33   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-229752@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hare@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox