Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp2022450lqa; Tue, 30 Apr 2024 06:27:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVYtYGc3Q4ycxd8TchMK220mVTv5P8yePbi51fcBKdmbQbpyGLqEnlk5FIoplUmkVmu2sZD6x4qZDHnyIRTFSLYmALvhg+bYNFX1zQzPw== X-Google-Smtp-Source: AGHT+IFR5N79yKI1Spd1lxZA5/WtWYjdnbhTYM1/BXf+4NRbvI/fPKKoAxBAWHBe0/cY5uPv6oQA X-Received: by 2002:a17:906:3bd5:b0:a55:3488:f730 with SMTP id v21-20020a1709063bd500b00a553488f730mr9853273ejf.31.1714483675539; Tue, 30 Apr 2024 06:27:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714483675; cv=pass; d=google.com; s=arc-20160816; b=J50d6cz4Mi+RjOCq7zw8qePyc+zMS4ndZjG62Rg5q6efr68RCVjdEPjFaX/SrJo+V8 gy9ypP2JahEY/RxDc0CjAU8Ll23YlaA5pQcScbiGqUdOzlI74FKf/PbTcDpENtLeKRxx x/D0i67Hdy1jPdvJeWzBT0IzjVBxLQjyGBmMeQnx5UI1CexHUr5v5nV2VPhdD89MbNf/ ZlMNyV6LFakegWwrD6h8tM4ibVRlCDjB18toA5mOIdSUfqelUdwt1nhPA3g2icrSxtKf yN6bCRrWZlMovH7aRzHwkIWfLXFhLbqwNQ8Xe492vl+AfsnojZLF365rP9cgy+Zp7g4c FgTw== 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 :dkim-signature:dkim-signature; bh=8kHuZ0DDHSIPFjpB94qJZpVkKgyPiQEkg0Af+hvjw3M=; fh=8T2GmAX/HLZRkQSbU72gI278zsfTbC34m++RNyHx6SY=; b=dSO2zef/ZSIlDAFHgYQbHABRp8LMiBeA8yKYr2kLhW2+x+yAi9uhznB07Mwel35JZw vZkKc3xSsF/kUdPD3voAQKTvxMH+2an6DLqRrqakfuNq+nl+wbg7JoRyL43SNhkcmT5s ZtbUDIU1BY2t42tvsO6QU1Q86PfQ+Syv5ls422zAlGpofCxQgvs9Bftah5HZwvmizyaN FsaATaCTlduAyy7a+Tje7XXygPa58QGntF4whlm9xRqcxDdNQHiHOxcM9Pw6jBexE6cW KDzMGuTn4rJYauniPiAS7AueSh2Cxhy3GjfuJFbSYFOMq7bez5Gjb3vS7hCvIMzM+eGp uluw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=HBwqzsO2; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=HBwqzsO2; 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 dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-163982-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163982-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id p10-20020a17090653ca00b00a587e1423basi9014069ejo.70.2024.04.30.06.27.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 06:27:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163982-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=HBwqzsO2; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=HBwqzsO2; 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 dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-163982-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163982-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2AFEA1F250EE for ; Tue, 30 Apr 2024 13:20:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5DF6517276D; Tue, 30 Apr 2024 13:19:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="HBwqzsO2"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="IDvklSiT"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="HBwqzsO2"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="IDvklSiT" 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 E996F171664 for ; Tue, 30 Apr 2024 13:19:37 +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=1714483179; cv=none; b=JCZse+BEQ6NAi+pcRr3q++mYiLA08DrMHvIi/1abgBqzBam/fsUchmAFATyNJhjCdMZUWQJeV6YEu1nIxrM5k7ZPbdX3SJBFUlBO2lqjKjlaY2jn1vna2wZqJRWH6vh1c3M4dXE4FAIZSxQcxyVwEcKdIWKC4Yu1Gvz8XcGmeaY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714483179; c=relaxed/simple; bh=2pEw6VivEu28Mo3DUny6NNh9kyZmW0ocFsTrPvhuHtI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ckID+RUToA8ksm4KPbbjUby3PqwV8irFG/dUDSuulOfiZB2uJkJGTSzQL4xnufKpSaAZwunfagYLLAL36NPrjyn0JQcq5u04D9AdyOcku1rLdjX0jvNOw0a4EmxwVQcqCZxxiITHsgCcCf2tYwNzjQ9VJrqiAXhg4GreyPZE8vE= 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=HBwqzsO2; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=IDvklSiT; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=HBwqzsO2; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=IDvklSiT; 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 imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (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 193313406B; Tue, 30 Apr 2024 13:19:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714483176; 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=8kHuZ0DDHSIPFjpB94qJZpVkKgyPiQEkg0Af+hvjw3M=; b=HBwqzsO2tvy7femgoknMrDBC+32vIVXELC0BJG9CmIEtwFhTm8JzQmmHYrEd1rgC47av4u ykss4v37J5MoT3DnO8iGLvP+Qw6rnveED52FaB8RG4bcId+NPZL1NqbmwnPJi/e5xsQM0U UpebAyhHHChvA64p8oYKhVfnd9p4voc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714483176; 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=8kHuZ0DDHSIPFjpB94qJZpVkKgyPiQEkg0Af+hvjw3M=; b=IDvklSiTmCd/cD2cNhR+fqaN0Zl+MF2LrqFiZIldbf8zqhV6kCSbF9/FwH1XjsrcSGTq1N jdBiEM6mQKEhqCDQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1714483176; 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=8kHuZ0DDHSIPFjpB94qJZpVkKgyPiQEkg0Af+hvjw3M=; b=HBwqzsO2tvy7femgoknMrDBC+32vIVXELC0BJG9CmIEtwFhTm8JzQmmHYrEd1rgC47av4u ykss4v37J5MoT3DnO8iGLvP+Qw6rnveED52FaB8RG4bcId+NPZL1NqbmwnPJi/e5xsQM0U UpebAyhHHChvA64p8oYKhVfnd9p4voc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1714483176; 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=8kHuZ0DDHSIPFjpB94qJZpVkKgyPiQEkg0Af+hvjw3M=; b=IDvklSiTmCd/cD2cNhR+fqaN0Zl+MF2LrqFiZIldbf8zqhV6kCSbF9/FwH1XjsrcSGTq1N jdBiEM6mQKEhqCDQ== Received: from imap1.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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 073CC133A7; Tue, 30 Apr 2024 13:19:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id urFMAOjvMGZwMAAAD6G6ig (envelope-from ); Tue, 30 Apr 2024 13:19:36 +0000 From: Daniel Wagner To: Christoph Hellwig Cc: Keith Busch , Sagi Grimberg , James Smart , Hannes Reinecke , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Hannes Reinecke , Daniel Wagner Subject: [PATCH v7 1/5] nvmet: lock config semaphore when accessing DH-HMAC-CHAP key Date: Tue, 30 Apr 2024 15:19:24 +0200 Message-ID: <20240430131928.29766-2-dwagner@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430131928.29766-1-dwagner@suse.de> References: <20240430131928.29766-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 [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_SEVEN(0.00)[9]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Flag: NO 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. Reviewed-by: Sagi Grimberg Reviewed-by: Christoph Hellwig 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