From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98BD1C6FD1D for ; Tue, 21 Mar 2023 12:44:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=v2A74WtsIK29Gu2jzeKTfRlCeRbGVc/9x6v650hC+A0=; b=l8chp59S7OZkrGa5Ye2rt5M9bC NqddTG8NkSGKME7+yPk8P/LAwdqU0rblT+OcT5YME+I65nWGj1/aW3rGYvdpM7qdF+aGrFaDxXzws /ox0ps7AwTj9oNSB7nHKOOZrSRbAHdalDynp/cX2esSrMofTMTBZMD72gEGahwhdUPmFpHN3VMXtL /LrLig4Mpqan7JdPeQH3HsFxROrVouSRclA5UVtVbtOsnvZ6WJDKfy44GDt0RDMya+ljyD01N0LZk 8hfiEcGMlnDyu6t0My5lxKpPVVEABbiiEqQNMdtPoA8Cy9f6POMADCrsmr6LUbj6qL7z0aVw4j0yv Wn2Y+rPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pebLZ-00CNZ6-1x; Tue, 21 Mar 2023 12:44:13 +0000 Received: from smtp-out2.suse.de ([195.135.220.29]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pebLN-00CNOS-1a for linux-nvme@lists.infradead.org; Tue, 21 Mar 2023 12:44:05 +0000 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id D4E901FFFD; Tue, 21 Mar 2023 12:43:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1679402637; 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=v2A74WtsIK29Gu2jzeKTfRlCeRbGVc/9x6v650hC+A0=; b=mPBqJi9DFGuu1fwYjBh0cxKor2KHyvEaXw9oSKAU+0HOeY/61/k4bD547qjOcmL3F/FyaM Sc7SjQv97SIwVjI22RP8IlZvWS73YZz5jZTJyjj94XOxnGkWmvSEJx1mnM2wGNtDVPht/5 UlbN2WjgeIC18pwTNQXSH3aCl/oLWKk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1679402637; 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=v2A74WtsIK29Gu2jzeKTfRlCeRbGVc/9x6v650hC+A0=; b=iozcyBfzOsFFS7oMfVQnz5CiYB5dNZIoWPHkxHx7YNo4f7ZmiKwpxNPMzkMk7hddlqwZPw KySYYof2Jsf4NWCA== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id BA72E2C142; Tue, 21 Mar 2023 12:43:57 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id A3C1251BEE96; Tue, 21 Mar 2023 13:43:57 +0100 (CET) From: Hannes Reinecke To: Christoph Hellwig Cc: Sagi Grimberg , Keith Busch , linux-nvme@lists.infradead.org, Chuck Lever , kernel-tls-handshake@lists.linux.dev, Hannes Reinecke Subject: [PATCH 01/18] nvme-keyring: register '.nvme' keyring Date: Tue, 21 Mar 2023 13:43:08 +0100 Message-Id: <20230321124325.77385-2-hare@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230321124325.77385-1-hare@suse.de> References: <20230321124325.77385-1-hare@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230321_054401_747403_96D209AE X-CRM114-Status: GOOD ( 18.61 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org Register a '.nvme' keyring to hold keys for TLS and DH-HMAC-CHAP. We need a separate keyring as for NVMe the might not be a userspace process attached (eg during reconnect), and so the use of a session keyring or any other process-related keyrings might not be possible. Signed-off-by: Hannes Reinecke --- drivers/nvme/common/Makefile | 2 +- drivers/nvme/common/keyring.c | 36 +++++++++++++++++++++++++++++++++++ drivers/nvme/host/core.c | 10 +++++++++- include/linux/nvme-keyring.h | 12 ++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 drivers/nvme/common/keyring.c create mode 100644 include/linux/nvme-keyring.h diff --git a/drivers/nvme/common/Makefile b/drivers/nvme/common/Makefile index 720c625b8a52..c4e3b312d2cc 100644 --- a/drivers/nvme/common/Makefile +++ b/drivers/nvme/common/Makefile @@ -4,4 +4,4 @@ ccflags-y += -I$(src) obj-$(CONFIG_NVME_COMMON) += nvme-common.o -nvme-common-y += auth.o +nvme-common-y += auth.o keyring.o diff --git a/drivers/nvme/common/keyring.c b/drivers/nvme/common/keyring.c new file mode 100644 index 000000000000..3a6e8a0b38e2 --- /dev/null +++ b/drivers/nvme/common/keyring.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2020 Hannes Reinecke, SUSE Linux + */ + +#include +#include +#include +#include +#include + +static struct key *nvme_keyring; + +int nvme_keyring_init(void) +{ + int err; + + nvme_keyring = keyring_alloc(".nvme", + GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, + current_cred(), + (KEY_POS_ALL & ~KEY_POS_SETATTR) | + (KEY_USR_ALL & ~KEY_USR_SETATTR), + KEY_ALLOC_NOT_IN_QUOTA, NULL, NULL); + if (IS_ERR(nvme_keyring)) + return PTR_ERR(nvme_keyring); + + return 0; +} +EXPORT_SYMBOL_GPL(nvme_keyring_init); + +void nvme_keyring_exit(void) +{ + key_revoke(nvme_keyring); + key_put(nvme_keyring); +} +EXPORT_SYMBOL_GPL(nvme_keyring_exit); diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index d4be525f8100..839bc7587f54 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -25,6 +25,7 @@ #include "nvme.h" #include "fabrics.h" #include +#include #define CREATE_TRACE_POINTS #include "trace.h" @@ -5415,11 +5416,17 @@ static int __init nvme_core_init(void) goto unregister_generic_ns; } - result = nvme_init_auth(); + result = nvme_keyring_init(); if (result) goto destroy_ns_chr; + + result = nvme_init_auth(); + if (result) + goto keyring_exit; return 0; +keyring_exit: + nvme_keyring_exit(); destroy_ns_chr: class_destroy(nvme_ns_chr_class); unregister_generic_ns: @@ -5443,6 +5450,7 @@ static int __init nvme_core_init(void) static void __exit nvme_core_exit(void) { nvme_exit_auth(); + nvme_keyring_exit(); class_destroy(nvme_ns_chr_class); class_destroy(nvme_subsys_class); class_destroy(nvme_class); diff --git a/include/linux/nvme-keyring.h b/include/linux/nvme-keyring.h new file mode 100644 index 000000000000..a875c06cc922 --- /dev/null +++ b/include/linux/nvme-keyring.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2021 Hannes Reinecke, SUSE Software Solutions + */ + +#ifndef _NVME_KEYRING_H +#define _NVME_KEYRING_H + +int nvme_keyring_init(void); +void nvme_keyring_exit(void); + +#endif -- 2.35.3