Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1501233ybl; Wed, 14 Aug 2019 18:35:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxhrlLMnEadXdVTtWC9yk6n0Xr/ONuh7dkgdvx7mQwxKg2aynPfsNOIg60I/RMo3BeZRc+3 X-Received: by 2002:aa7:8b55:: with SMTP id i21mr2938165pfd.155.1565832946268; Wed, 14 Aug 2019 18:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565832946; cv=none; d=google.com; s=arc-20160816; b=FeaezHrHK38y4xRNIKfj5dQ/+nXyZ55mndOFMcMtVUyp1MJ2GaIzaTEbQpOMOo9N5d pDV6LlgOURmuGuiyXZImrZnsBcCiyFqE6pKbBAW5wc/vXnjK0hjdKEE7/L33OSU4DABK YRt/fKBtEPwjE5ZfDx34LDnwHlBFS/xDUlBy5uMX/lfxEa3686s4JpRnyUCL2wYd7MPE nOA5axpld2zvPVJMxLemu77fRLu4BnmvrZLZg7+69mFwShq5CtA+ZnPSr4G+t8B0gygy ejtixHmZWag5royOP9pdHIIgmvCPYO0PhHT6O3KW3dMxlYfXXnKSdeJKNT4YvUifRJeL ztvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject; bh=FbSO9d/r0WyXMTg6d6lZcLfb33t3C+TU5pq5IwiW0SI=; b=DzsjtDD6hqchoPU2bGJ4kRULkazu2WAYBBI/q0R11SSQv4Wj6rgM9L5IY4zuiqFakl l5SheicUWz8U+QuavrGVd08cKzB5SbVVlVHJ6boS3u0pn/HImVrCrtSdRw4oxx2pukvU wztJj1eOPXzWNoKKAVUfawXOmUGgV/yeiHsc/KXvdzHYR3r0A12zCVMcAg8PNU0qbmuk eOJT0xjwedxgxn0bJjXR88+AIeqPVbAyyYjF76VNmnxEoJ+0EQ5IvPcJCgDVfCAnEwmY R8kYB/O1VMr8xSqeYKviWDa3aErQsz6KxsZf4LPL0B0HpEM7xSPjvbO8Tll5ymcBN0cN o7ug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y12si877564pgg.585.2019.08.14.18.35.30; Wed, 14 Aug 2019 18:35:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729485AbfHOBem (ORCPT + 99 others); Wed, 14 Aug 2019 21:34:42 -0400 Received: from mga02.intel.com ([134.134.136.20]:19753 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727659AbfHOBel (ORCPT ); Wed, 14 Aug 2019 21:34:41 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Aug 2019 18:34:41 -0700 X-IronPort-AV: E=Sophos;i="5.64,387,1559545200"; d="scan'208";a="179234967" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Aug 2019 18:34:41 -0700 Subject: [PATCH 2/3] libnvdimm/security: Tighten scope of nvdimm->busy vs security operations From: Dan Williams To: linux-nvdimm@lists.01.org Cc: Dave Jiang , linux-kernel@vger.kernel.org Date: Wed, 14 Aug 2019 18:20:23 -0700 Message-ID: <156583202386.2815870.16611751329252858110.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156583201347.2815870.4687949334637966672.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156583201347.2815870.4687949334637966672.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The blanket blocking of all security operations while the DIMM is in active use in a region is too restrictive. The only security operations that need to be aware of the ->busy state are those that mutate the state of data, i.e. erase and overwrite. Refactor the ->busy checks to be applied at the entry common entry point in __security_store() rather than each of the helper routines. Cc: Dave Jiang Signed-off-by: Dan Williams --- drivers/nvdimm/dimm_devs.c | 33 ++++++++++++++++----------------- drivers/nvdimm/security.c | 10 ---------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/drivers/nvdimm/dimm_devs.c b/drivers/nvdimm/dimm_devs.c index 53330625fe07..d837cb9be83d 100644 --- a/drivers/nvdimm/dimm_devs.c +++ b/drivers/nvdimm/dimm_devs.c @@ -424,9 +424,6 @@ static ssize_t __security_store(struct device *dev, const char *buf, size_t len) unsigned int key, newkey; int i; - if (atomic_read(&nvdimm->busy)) - return -EBUSY; - rc = sscanf(buf, "%"__stringify(SEC_CMD_SIZE)"s" " %"__stringify(KEY_ID_SIZE)"s" " %"__stringify(KEY_ID_SIZE)"s", @@ -451,23 +448,25 @@ static ssize_t __security_store(struct device *dev, const char *buf, size_t len) } else if (i == OP_DISABLE) { dev_dbg(dev, "disable %u\n", key); rc = nvdimm_security_disable(nvdimm, key); - } else if (i == OP_UPDATE) { - dev_dbg(dev, "update %u %u\n", key, newkey); - rc = nvdimm_security_update(nvdimm, key, newkey, NVDIMM_USER); - } else if (i == OP_ERASE) { - dev_dbg(dev, "erase %u\n", key); - rc = nvdimm_security_erase(nvdimm, key, NVDIMM_USER); + } else if (i == OP_UPDATE || i == OP_MASTER_UPDATE) { + dev_dbg(dev, "%s %u %u\n", ops[i].name, key, newkey); + rc = nvdimm_security_update(nvdimm, key, newkey, i == OP_UPDATE + ? NVDIMM_USER : NVDIMM_MASTER); + } else if (i == OP_ERASE || i == OP_MASTER_ERASE) { + dev_dbg(dev, "%s %u\n", ops[i].name, key); + if (atomic_read(&nvdimm->busy)) { + dev_dbg(dev, "Unable to secure erase while DIMM active.\n"); + return -EBUSY; + } + rc = nvdimm_security_erase(nvdimm, key, i == OP_ERASE + ? NVDIMM_USER : NVDIMM_MASTER); } else if (i == OP_OVERWRITE) { dev_dbg(dev, "overwrite %u\n", key); + if (atomic_read(&nvdimm->busy)) { + dev_dbg(dev, "Unable to overwrite while DIMM active.\n"); + return -EBUSY; + } rc = nvdimm_security_overwrite(nvdimm, key); - } else if (i == OP_MASTER_UPDATE) { - dev_dbg(dev, "master_update %u %u\n", key, newkey); - rc = nvdimm_security_update(nvdimm, key, newkey, - NVDIMM_MASTER); - } else if (i == OP_MASTER_ERASE) { - dev_dbg(dev, "master_erase %u\n", key); - rc = nvdimm_security_erase(nvdimm, key, - NVDIMM_MASTER); } else return -EINVAL; diff --git a/drivers/nvdimm/security.c b/drivers/nvdimm/security.c index 5862d0eee9db..2166e627383a 100644 --- a/drivers/nvdimm/security.c +++ b/drivers/nvdimm/security.c @@ -334,11 +334,6 @@ int nvdimm_security_erase(struct nvdimm *nvdimm, unsigned int keyid, || !nvdimm->sec.flags) return -EOPNOTSUPP; - if (atomic_read(&nvdimm->busy)) { - dev_dbg(dev, "Unable to secure erase while DIMM active.\n"); - return -EBUSY; - } - rc = check_security_state(nvdimm); if (rc) return rc; @@ -380,11 +375,6 @@ int nvdimm_security_overwrite(struct nvdimm *nvdimm, unsigned int keyid) || !nvdimm->sec.flags) return -EOPNOTSUPP; - if (atomic_read(&nvdimm->busy)) { - dev_dbg(dev, "Unable to overwrite while DIMM active.\n"); - return -EBUSY; - } - if (dev->driver == NULL) { dev_dbg(dev, "Unable to overwrite while DIMM active.\n"); return -EINVAL;