Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp148477lqp; Thu, 4 Apr 2024 09:11:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX6yDfarmxJMO5K4/QdQp8PlwuZDlO3ACovLqITRFIGiatXp7ctFqA9KedlRjzKXv5iYU+4tf9c2wHcC7OSMAENzVUWAfk+YB7jpBTLMA== X-Google-Smtp-Source: AGHT+IEOmpNKElDVJdYfs1IoYx4V8b3+zJkV8ASIDjrjRPoBvGb+2uP3A1Aem8iq+v9IoLxq4ATD X-Received: by 2002:a17:902:e885:b0:1e2:c355:fae1 with SMTP id w5-20020a170902e88500b001e2c355fae1mr552015plg.21.1712247069107; Thu, 04 Apr 2024 09:11:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712247069; cv=pass; d=google.com; s=arc-20160816; b=sb87ztfB/hF1czyUOKKLyO+udDPWPoPNd9M52Qg3jkGSDmJ8EIZvDqszciFNKGpXNk DUR62kIcqTClqiml36B+XpV/ikSa5ow2qKgoPWSgEG1Il/O7Qb/yfD8mo1FY7buGhLqU X+cYLar6AUfrcZFDyg25XDKZN7sCKMbBi7xVe3yUKgKO4r8DghN1WIyAsrTqnpK1j8sc Za+ZYDImk0z00FnIjpIQlUJDOoJ4Z7Q3y7vgT47rq4bHnylsE3nuSQZDxIcXucObFcGS bdKFb01R1RLkAgw7DNe9/JI3wctP9N08PeAM7y3R0wgWUxJIhEKMLs9SXc3tAeRbRhR8 Y6LQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature; bh=TyZA3j85Z7pMInECy/q8xvo8tWrjUgChlPcQlRjOZI8=; fh=pUTGaEp/sPQhOCZxnsUMkn7cDaXyld7tOrXMOiR6SpE=; b=DAao/M3GFJEvuvfTzYLs5ofbq/dKUtv24jn6cU5YY7T/9yuhH1CD/Dnl6/bZ1fMBcS OTfZe2fmt6vclhu0L5VjfieVBz9jf/nb4R6N/21F4XsNSaGMiTSS/ET0k8Iddt6uAVkU CYstgZkezyD/B9Kjh6LUwYFp/oV6p2hhKeiTpc8IOJOKhCJZ8v6rWek+6xhGLrVrw5kZ zLmhkI07zcG1Av4Q3Q+EONWWCK8i08ARZflMenjNrkoRkYd9CgDxOu5YaCmFgvuJuNW0 aRjwI371iJDtOqm0ov2bcWuNCCFIoisscbpCw1ER590UxXsIygtYpD9VegitqXKBtMUU AwUg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=uRM6vYiy; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-131747-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131747-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id s18-20020a17090302d200b001e007479acfsi15941809plk.120.2024.04.04.09.11.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 09:11:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131747-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=uRM6vYiy; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-131747-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131747-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id DA1A2B223E7 for ; Thu, 4 Apr 2024 15:45:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2EA5812AAD5; Thu, 4 Apr 2024 15:45:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="uRM6vYiy"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="/lpkBLAb" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0AEE86ADB for ; Thu, 4 Apr 2024 15:45:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712245511; cv=none; b=V3BRYz9bFRwtG5++R7Y6jriqvw/WK9YXwzanh93ZlcSFLK7jkllWe+2n/JxUSCzno5OMV1Q1Kh5jFay5Q1ITNV0Og2yzwJVrRkmAP96t+HvS95xUqyz74RN860Xyg8xusXqRK5bGg8be1x2NAcWCn2dg91RbAhkBbHHo7RFOTNs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712245511; c=relaxed/simple; bh=g3w88NJvNIVVNbZvLx445agXw1wOt26dDzIYw21Eab0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MbRmBFgMzW5Sd0wqDbZBBryFFD17LCgAV2+G8gEO84FiQJAOAGe1i3y2gAMwq7Beyn1AOU6nelKAj98tFKoZcv6OGdalNfNLhcY0b54VKaf5kb2YZ2SNXWxUKCFmj96LtZMze9FVftfbLvNS+0inWKaeC5v6WIfELLaLyvEYbd0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=uRM6vYiy; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=/lpkBLAb; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E51E237BF4; Thu, 4 Apr 2024 15:45:07 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712245507; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TyZA3j85Z7pMInECy/q8xvo8tWrjUgChlPcQlRjOZI8=; b=uRM6vYiy8O5ipHZj3pAley1JHNq3/bTfHZzeUcvQFendSed27uPNnuNxGZNCYNiwjWr7s5 iCmBN+I4hZbe6fikW2BhvsXXkWw7xCjvzBqUuXviGHpf43T3oBtelFLhK70XHdHzRmJR/y WTV7rbdpFz5vJhvSIAYHPf99jvuj8jU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712245507; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TyZA3j85Z7pMInECy/q8xvo8tWrjUgChlPcQlRjOZI8=; b=/lpkBLAbYIlW9iVDx8gVCYKRi/RMaXLZQczePwsIJayUAi6nQvnHST30Ao//GinYbWSktM v7jf2ITy9Ujor0Dw== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id D279513AA3; Thu, 4 Apr 2024 15:45:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id UrXyMQPLDmYGIgAAn2gu4w (envelope-from ); Thu, 04 Apr 2024 15:45:07 +0000 From: Daniel Wagner To: James Smart Cc: Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Hannes Reinecke , Daniel Wagner Subject: [PATCH v4 2/5] nvmet: lock config semaphore when accessing DH-HMAC-CHAP key Date: Thu, 4 Apr 2024 17:44:57 +0200 Message-ID: <20240404154500.2101-3-dwagner@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240404154500.2101-1-dwagner@suse.de> References: <20240404154500.2101-1-dwagner@suse.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Flag: NO X-Spam-Score: -4.00 X-Rspamd-Queue-Id: E51E237BF4 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action From: Hannes Reinecke 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. Signed-off-by: Hannes Reinecke Signed-off-by: Daniel Wagner --- drivers/nvme/target/auth.c | 2 ++ drivers/nvme/target/configfs.c | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c index 3ddbc3880cac..9afc28f1ffac 100644 --- a/drivers/nvme/target/auth.c +++ b/drivers/nvme/target/auth.c @@ -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; } diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c index 77a6e817b315..7c28b9c0ee57 100644 --- a/drivers/nvme/target/configfs.c +++ b/drivers/nvme/target/configfs.c @@ -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, -- 2.44.0