Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1194245pxb; Thu, 9 Sep 2021 23:44:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUH4E1lXDD+4KvKa5H5Z4jTEWllRbqCQSEyEiudS1fubfcQb+aqw40X82dBNrwpyQZdtH+ X-Received: by 2002:a05:6638:2493:: with SMTP id x19mr3214701jat.57.1631256278546; Thu, 09 Sep 2021 23:44:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631256278; cv=none; d=google.com; s=arc-20160816; b=r/Lb8fsgv5D/Q9l8NMd2emUwCRfY9AkimV6pISNF/91CDzjQs7A4W8sF52XooJW8Qv 15qzx5o1zlsNalzYKU40E0glFxk5U1TY4PIQ+tyms9btYOGiXSKEM2BhAubCeueeNwrF mURtjkj056vqhOrxPQS/3tCmkCXWi1R5Z4Jv5F/gm7cfPR6NqpY5vf5CqTHOZcEV+M81 AAHssCeItgOanIX0Sye3cuoniHH1JERB3wLjFmEzYJWc8ukA124icHsVmtYka8JWX0ln rKA1nPJeE+sDrnxH0JQtBd9KecWE4YiqEZpbqhnJrX8ZCeD/0TGCIrUURxW608HK5YHJ JILg== 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=/bhXoI+NYux7cxf3GbMWyXOSi3QTT+qJMxHbAox/FyQ=; b=uzG2eHBbSYAp6lX142jybQZ2Ee6RFrL7YOWJb92vSUwC/QVPNc8I0DhJqz1oG58MZ0 p2DuXs6U+3pAWGto7SWdet5ySoXqgb2HPITKP3gJ7V6q6luiFsaRy0lSmoN0uw0jI79A +gn9kKU+Jl3OcuIef56We3om9PiUi9M6uZ6KYyykd0R8CLxBJ6o/5PFMQgbsrCSeY/Uv Hdf/iZI/AHSc5hVFv77M+atMeuYZRQ41YOtc3lMii/mWIC8lcdblLntiQ80eIN9UzdP4 5EW99Me/Pc9Lali+rPXmwDz75Dad70K/4zVKtKGsAzTnNHSQwoRT6cVjmEu5Eg72IIvq ktqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=XxpjPGfz; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=qnJPuUYf; 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 m10si5203683ilu.53.2021.09.09.23.44.26; Thu, 09 Sep 2021 23:44: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=XxpjPGfz; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=qnJPuUYf; 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 S231205AbhIJGo6 (ORCPT + 99 others); Fri, 10 Sep 2021 02:44:58 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:42294 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231209AbhIJGov (ORCPT ); Fri, 10 Sep 2021 02:44:51 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 370CA22407; Fri, 10 Sep 2021 06:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1631256219; 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=/bhXoI+NYux7cxf3GbMWyXOSi3QTT+qJMxHbAox/FyQ=; b=XxpjPGfz3eHAmG4y0aG2iVNxtnT5t2M0QJbImL1Rkl6QNXmE5eDpetPkzeiYLdbXXQQDVz fdcC+WsAOqCNbAk4DS8Dv5Owku8RNhx13tdeQ2uClpc/yjCP0Pwu1eHh8yAF/xXcDxna0F FgSrhDya8FcMOqu8O/n+B7INa4JbyKM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1631256219; 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=/bhXoI+NYux7cxf3GbMWyXOSi3QTT+qJMxHbAox/FyQ=; b=qnJPuUYf3eH/L6lyV9jDtoRY8lOnuHSWQYdQeopn+JBvBMhZ9lrcdpNnC8p4LuBSinE0I7 ICdroPa6JtKSCnBw== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 2D2F6A3BB2; Fri, 10 Sep 2021 06:43:39 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id C82EC518E332; Fri, 10 Sep 2021 08:43:36 +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/12] nvmet-auth: expire authentication sessions Date: Fri, 10 Sep 2021 08:43:22 +0200 Message-Id: <20210910064322.67705-13-hare@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210910064322.67705-1-hare@suse.de> References: <20210910064322.67705-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 d0849404f398..84bf7043674e 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