Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3601042pxt; Tue, 10 Aug 2021 07:15:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhyt+UeotfSdfwMPVRCGud+V9QJOMeXvrWK3N/pJcq+dOte0il6CKTB8jBVR/7r1jx4TZu X-Received: by 2002:a05:6402:42ce:: with SMTP id i14mr5271066edc.345.1628604938165; Tue, 10 Aug 2021 07:15:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628604938; cv=none; d=google.com; s=arc-20160816; b=WHzkNWCg2QiEcjXpfrvoowwcaNAN5U7eIlNmvlvQCOnhS++izh8iuXqPpawA/IRcMo vwORHzw27+BRP2caogj0Tc16+Rh8wILv56fi/Q44ZTYEnf10afaTCxj9vxJDOwy4iJmu 5+gSMxvRY5uLV17JDn3AxVX/DPTkwo55ZAzZgbl38hdUs/K9XtPD4XTAVoOdwi4Sas69 OwWy94/NmKWxbc94XHMtNdapciuR/sy1NJPV+Lp+7GXqFJMCuRUeKkQje5i/9LmvON0s V10b3g10lnqQlCm21zsXs3zNXbvtjAD/uFCm5HXABVXaSeFsQpCA8yx8f1bKYKCkrP9/ Liog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=EAXODgiujF2oaJLmoXzKTPrRQC7FAIhPJf3tiDCgFDU=; b=LwU+++9+CFkSB9FOX9r+F2NlUJnWVUrAODyqfYlNb+m0d3igG+W2vEpZJCJG8H1ra0 bpzBeOLZjJ+MudZW0N+jln9MRCtRSO/gSO6zC1LunQ4w8tXspou785TR4lFhq9CP4xNq N0cyBLcrNlP/j902mjPr22KT3htA9r/F7MvvieeBA0S0v4UVJCn70JcXbdLu7bzSHeWM 7yaeu6UyFgmutpCx0M/GYT727AYvvbsl+xAPhowoMlbiJnut214ZblSPcuDbiloRg5aI HZUzYLObPY8dyENquxXdT6G7O6iKdiJTcc0XB/6+241uo7ZqbWoluYrGC31imTAsp3Oz Q9+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=hc04FUze; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="/XxgLceF"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nc27si4507840ejc.342.2021.08.10.07.15.11; Tue, 10 Aug 2021 07:15:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=hc04FUze; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="/XxgLceF"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240733AbhHJMnY (ORCPT + 99 others); Tue, 10 Aug 2021 08:43:24 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:40820 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240713AbhHJMnQ (ORCPT ); Tue, 10 Aug 2021 08:43:16 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 29DDF22064; Tue, 10 Aug 2021 12:42:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1628599372; 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=EAXODgiujF2oaJLmoXzKTPrRQC7FAIhPJf3tiDCgFDU=; b=hc04FUze4vMVfTcjNaTtMdo19sPa6L/IoUSbuTuQsUcO4AFtJOFJoIywpIaBPt4hufzx8U V7pP34iI62yniR6S7bZA3OtfXGyB9EUiCS+QZ2JzNDUH9+LmvmR1TTIZLuxr6uS7an4DAx Y5sdWMPphqXGPEC8ENujh4PhU7gKbSs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1628599372; 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=EAXODgiujF2oaJLmoXzKTPrRQC7FAIhPJf3tiDCgFDU=; b=/XxgLceFTq/9/9eh3/6sxJfQqG4gcHNmsayc6NTXkrs/cFu+tb/oAz9vWBgTygpRnjzSCj VxvwxOsiuPF8BxCg== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 20A21A3B95; Tue, 10 Aug 2021 12:42:52 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 8AFCE518C558; Tue, 10 Aug 2021 14:42:50 +0200 (CEST) From: Hannes Reinecke To: Christoph Hellwig Cc: Sagi Grimberg , Keith Busch , Herbert Xu , "David S . Miller" , linux-nvme@lists.infradead.org, linux-crypto@vger.kernel.org, Hannes Reinecke Subject: [PATCH 12/13] nvmet-auth: expire authentication sessions Date: Tue, 10 Aug 2021 14:42:29 +0200 Message-Id: <20210810124230.12161-13-hare@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210810124230.12161-1-hare@suse.de> References: <20210810124230.12161-1-hare@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Each authentication step is required to be completed within the KATO interval (or two minutes if not set). So add a workqueue function to reset the transaction ID and the expected next protocol step; this will automatically the next authentication command referring to the terminated authentication. Signed-off-by: Hannes Reinecke --- drivers/nvme/target/auth.c | 1 + drivers/nvme/target/fabrics-cmd-auth.c | 20 +++++++++++++++++++- drivers/nvme/target/nvmet.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c index fe44593a37f8..c7c62ba089da 100644 --- a/drivers/nvme/target/auth.c +++ b/drivers/nvme/target/auth.c @@ -197,6 +197,7 @@ int nvmet_setup_auth(struct nvmet_ctrl *ctrl) void nvmet_auth_sq_free(struct nvmet_sq *sq) { + cancel_delayed_work(&sq->auth_expired_work); kfree(sq->dhchap_c1); sq->dhchap_c1 = NULL; kfree(sq->dhchap_c2); diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/fabrics-cmd-auth.c index 2f1b95098917..7e7322846b82 100644 --- a/drivers/nvme/target/fabrics-cmd-auth.c +++ b/drivers/nvme/target/fabrics-cmd-auth.c @@ -12,9 +12,22 @@ #include "nvmet.h" #include "../host/auth.h" +static void nvmet_auth_expired_work(struct work_struct *work) +{ + struct nvmet_sq *sq = container_of(to_delayed_work(work), + struct nvmet_sq, auth_expired_work); + + pr_debug("%s: ctrl %d qid %d transaction %u expired, resetting\n", + __func__, sq->ctrl->cntlid, sq->qid, sq->dhchap_tid); + sq->dhchap_step = NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE; + sq->dhchap_tid = -1; +} + void nvmet_init_auth(struct nvmet_ctrl *ctrl, struct nvmet_req *req) { /* Initialize in-band authentication */ + INIT_DELAYED_WORK(&req->sq->auth_expired_work, + nvmet_auth_expired_work); req->sq->authenticated = false; req->sq->dhchap_step = NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE; req->cqe->result.u32 |= 0x2 << 16; @@ -303,8 +316,13 @@ void nvmet_execute_auth_send(struct nvmet_req *req) req->cqe->result.u64 = 0; nvmet_req_complete(req, status); if (req->sq->dhchap_step != NVME_AUTH_DHCHAP_MESSAGE_SUCCESS2 && - req->sq->dhchap_step != NVME_AUTH_DHCHAP_MESSAGE_FAILURE2) + req->sq->dhchap_step != NVME_AUTH_DHCHAP_MESSAGE_FAILURE2) { + unsigned long auth_expire_secs = ctrl->kato ? ctrl->kato : 120; + + mod_delayed_work(system_wq, &req->sq->auth_expired_work, + auth_expire_secs * HZ); return; + } /* Final states, clear up variables */ nvmet_auth_sq_free(req->sq); if (req->sq->dhchap_step == NVME_AUTH_DHCHAP_MESSAGE_FAILURE2) diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index e9d18ca6ebbf..91975356964b 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -109,6 +109,7 @@ struct nvmet_sq { u32 sqhd; bool sqhd_disabled; #ifdef CONFIG_NVME_TARGET_AUTH + struct delayed_work auth_expired_work; bool authenticated; u16 dhchap_tid; u16 dhchap_status; -- 2.29.2