nvmet: lock config semaphore when accessing DH-HMAC-CHAP key

When the DH-HMAC-CHAP key is accessed via configfs we need to take the
config semaphore as a reconnect might be running at the same time.

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
This commit is contained in:
Hannes Reinecke 2024-04-30 15:19:24 +02:00 committed by Keith Busch
parent 6ad0d7e0f4
commit 213cbada7b
2 changed files with 19 additions and 5 deletions

View File

@ -44,6 +44,7 @@ int nvmet_auth_set_key(struct nvmet_host *host, const char *secret,
dhchap_secret = kstrdup(secret, GFP_KERNEL);
if (!dhchap_secret)
return -ENOMEM;
down_write(&nvmet_config_sem);
if (set_ctrl) {
kfree(host->dhchap_ctrl_secret);
host->dhchap_ctrl_secret = strim(dhchap_secret);
@ -53,6 +54,7 @@ int nvmet_auth_set_key(struct nvmet_host *host, const char *secret,
host->dhchap_secret = strim(dhchap_secret);
host->dhchap_key_hash = key_hash;
}
up_write(&nvmet_config_sem);
return 0;
}

View File

@ -1990,11 +1990,17 @@ static struct config_group nvmet_ports_group;
static ssize_t nvmet_host_dhchap_key_show(struct config_item *item,
char *page)
{
u8 *dhchap_secret = to_host(item)->dhchap_secret;
u8 *dhchap_secret;
ssize_t ret;
down_read(&nvmet_config_sem);
dhchap_secret = to_host(item)->dhchap_secret;
if (!dhchap_secret)
return sprintf(page, "\n");
return sprintf(page, "%s\n", dhchap_secret);
ret = sprintf(page, "\n");
else
ret = sprintf(page, "%s\n", dhchap_secret);
up_read(&nvmet_config_sem);
return ret;
}
static ssize_t nvmet_host_dhchap_key_store(struct config_item *item,
@ -2018,10 +2024,16 @@ static ssize_t nvmet_host_dhchap_ctrl_key_show(struct config_item *item,
char *page)
{
u8 *dhchap_secret = to_host(item)->dhchap_ctrl_secret;
ssize_t ret;
down_read(&nvmet_config_sem);
dhchap_secret = to_host(item)->dhchap_ctrl_secret;
if (!dhchap_secret)
return sprintf(page, "\n");
return sprintf(page, "%s\n", dhchap_secret);
ret = sprintf(page, "\n");
else
ret = sprintf(page, "%s\n", dhchap_secret);
up_read(&nvmet_config_sem);
return ret;
}
static ssize_t nvmet_host_dhchap_ctrl_key_store(struct config_item *item,