From patchwork Wed Jan 9 17:54:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10754733 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C7E4013B4 for ; Wed, 9 Jan 2019 17:54:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8D3128702 for ; Wed, 9 Jan 2019 17:54:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACB38284E8; Wed, 9 Jan 2019 17:54:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2D8BB284E8 for ; Wed, 9 Jan 2019 17:54:37 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1FC4C211B5A44; Wed, 9 Jan 2019 09:54:37 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8D61E211B5098 for ; Wed, 9 Jan 2019 09:54:36 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jan 2019 09:54:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,458,1539673200"; d="scan'208";a="126011195" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by orsmga001.jf.intel.com with ESMTP; 09 Jan 2019 09:54:36 -0800 Subject: [PATCH v7 08/12] ndctl: add overwrite operation support From: Dave Jiang To: vishal.l.verma@intel.com, dan.j.williams@intel.com Date: Wed, 09 Jan 2019 10:54:35 -0700 Message-ID: <154705647591.23227.16371557710830841069.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <154705633843.23227.15903675663299735878.stgit@djiang5-desk3.ch.intel.com> References: <154705633843.23227.15903675663299735878.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/unknown-version MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Add support for overwrite to libndctl. The operation will be triggered by the sanitize-dimm command with -o switch. This will initiate the request to wipe the entire nvdimm. Success return of the command only indicate overwrite has started and does not indicate completion of overwrite. Signed-off-by: Dave Jiang --- Documentation/ndctl/ndctl-sanitize-dimm.txt | 4 ++++ ndctl/dimm.c | 21 +++++++++++++++++---- ndctl/lib/dimm.c | 8 ++++++++ ndctl/lib/keys.c | 25 +++++++++++++++++-------- ndctl/lib/libndctl.sym | 2 ++ ndctl/libndctl.h | 8 ++++++++ 6 files changed, 56 insertions(+), 12 deletions(-) diff --git a/Documentation/ndctl/ndctl-sanitize-dimm.txt b/Documentation/ndctl/ndctl-sanitize-dimm.txt index a1eab8bc..d37c2a4b 100644 --- a/Documentation/ndctl/ndctl-sanitize-dimm.txt +++ b/Documentation/ndctl/ndctl-sanitize-dimm.txt @@ -34,4 +34,8 @@ include::xable-dimm-options.txt[] Replaces encryption keys and securely erases the data. This does not change label data. This is the default sanitize method. +-o:: +--ovewrite:: + Wipe the entire DIMM, including label data. Can take significant time. + include::../copyright.txt[] diff --git a/ndctl/dimm.c b/ndctl/dimm.c index a91b40d5..799823d6 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -48,6 +48,7 @@ static struct parameters { const char *key_path; const char *master_key; bool crypto_erase; + bool overwrite; bool force; bool json; bool verbose; @@ -910,7 +911,7 @@ static int action_sanitize_dimm(struct ndctl_dimm *dimm, * Setting crypto erase to be default. The other method will be * overwrite. */ - if (!param.crypto_erase) { + if (!param.crypto_erase && !param.overwrite) { param.crypto_erase = true; printf("No santize method passed in, default to crypto-erase\n"); } @@ -921,6 +922,12 @@ static int action_sanitize_dimm(struct ndctl_dimm *dimm, return rc; } + if (param.overwrite) { + rc = ndctl_dimm_overwrite_key(dimm, param.key_path); + if (rc < 0) + return rc; + } + return 0; } @@ -1023,7 +1030,9 @@ OPT_STRING('m', "master-key", ¶m.master_key, ":", \ #define SANITIZE_OPTIONS() \ OPT_BOOLEAN('c', "crypto-erase", ¶m.crypto_erase, \ - "crypto erase a dimm") + "crypto erase a dimm"), \ +OPT_BOOLEAN('o', "overwrite", ¶m.overwrite, \ + "overwrite a dimm") static const struct option read_options[] = { BASE_OPTIONS(), @@ -1361,7 +1370,11 @@ int cmd_sanitize_dimm(int argc, const char **argv, void *ctx) sanitize_options, "ndctl sanitize-dimm [..] []"); - fprintf(stderr, "sanitized %d nmem%s.\n", count >= 0 ? count : 0, - count > 1 ? "s" : ""); + if (param.overwrite) + fprintf(stderr, "overwrite issued for %d nmem%s.\n", + count >= 0 ? count : 0, count > 1 ? "s" : ""); + else + fprintf(stderr, "sanitized %d nmem%s.\n", + count >= 0 ? count : 0, count > 1 ? "s" : ""); return count >= 0 ? 0 : EXIT_FAILURE; } diff --git a/ndctl/lib/dimm.c b/ndctl/lib/dimm.c index 285e09ce..f27b966c 100644 --- a/ndctl/lib/dimm.c +++ b/ndctl/lib/dimm.c @@ -685,3 +685,11 @@ NDCTL_EXPORT int ndctl_dimm_secure_erase(struct ndctl_dimm *dimm, long key) sprintf(buf, "erase %ld\n", key); return write_security(dimm, buf); } + +NDCTL_EXPORT int ndctl_dimm_overwrite(struct ndctl_dimm *dimm, long key) +{ + char buf[SYSFS_ATTR_SIZE]; + + sprintf(buf, "overwrite %ld\n", key); + return write_security(dimm, buf); +} diff --git a/ndctl/lib/keys.c b/ndctl/lib/keys.c index 95abd61a..2eb23d38 100644 --- a/ndctl/lib/keys.c +++ b/ndctl/lib/keys.c @@ -85,10 +85,9 @@ static char *load_key_blob(struct ndctl_ctx *ctx, const char *path, int *size) char prefix[] = "load "; rc = stat(path, &st); - if (rc < 0) { - err(ctx, "stat: %s\n", strerror(errno)); + if (rc < 0) return NULL; - } + if ((st.st_mode & S_IFMT) != S_IFREG) { err(ctx, "%s not a regular file\n", path); return NULL; @@ -404,10 +403,11 @@ static int check_key_run_and_discard(struct ndctl_dimm *dimm, key = dimm_check_key(dimm, false); if (key < 0) { key = dimm_load_key(dimm, false, keypath); - if (key < 0) { + if (key < 0 && run_op != ndctl_dimm_overwrite) { err(ctx, "Unable to load key\n"); return -ENOKEY; - } + } else + key = 0; } rc = run_op(dimm, key); @@ -417,9 +417,11 @@ static int check_key_run_and_discard(struct ndctl_dimm *dimm, return rc; } - rc = dimm_remove_key(dimm, false, keypath); - if (rc < 0) - err(ctx, "Unable to cleanup key.\n"); + if (key) { + rc = dimm_remove_key(dimm, false, keypath); + if (rc < 0) + err(ctx, "Unable to cleanup key.\n"); + } return 0; } @@ -436,3 +438,10 @@ NDCTL_EXPORT int ndctl_dimm_secure_erase_key(struct ndctl_dimm *dimm, return check_key_run_and_discard(dimm, ndctl_dimm_secure_erase, "crypto erase", keypath); } + +NDCTL_EXPORT int ndctl_dimm_overwrite_key(struct ndctl_dimm *dimm, + const char *keypath) +{ + return check_key_run_and_discard(dimm, ndctl_dimm_overwrite, + "overwrite", keypath); +} diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index 0e3aa5d9..0fedae1a 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -398,4 +398,6 @@ global: ndctl_dimm_freeze_security; ndctl_dimm_secure_erase; ndctl_dimm_secure_erase_key; + ndctl_dimm_overwrite; + ndctl_dimm_overwrite_key; } LIBNDCTL_18; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index 772aa7bb..1fbcfff4 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -704,6 +704,7 @@ int ndctl_dimm_update_passphrase(struct ndctl_dimm *dimm, int ndctl_dimm_disable_passphrase(struct ndctl_dimm *dimm, long key); int ndctl_dimm_freeze_security(struct ndctl_dimm *dimm); int ndctl_dimm_secure_erase(struct ndctl_dimm *dimm, long key); +int ndctl_dimm_overwrite(struct ndctl_dimm *dimm, long key); enum ndctl_key_type { ND_USER_KEY, @@ -718,6 +719,7 @@ int ndctl_dimm_update_key(struct ndctl_dimm *dimm, const char *master, int ndctl_dimm_disable_key(struct ndctl_dimm *dimm, const char *keypath); int ndctl_dimm_secure_erase_key(struct ndctl_dimm *dimm, const char *keypath); +int ndctl_dimm_overwrite_key(struct ndctl_dimm *dimm, const char *keypath); #else static inline int ndctl_dimm_enable_key(struct ndctl_dimm *dimm, const char *master, const char *keypath) @@ -742,6 +744,12 @@ static inline int ndctl_dimm_secure_erase_key(struct ndctl_dimm *dimm, { return -EOPNOTSUPP; } + +static inline int ndctl_dimm_overwrite_key(struct ndctl_dimm *dimm, + const char *keypath) +{ + return -EOPNOTSUPP; +} #endif #ifdef __cplusplus