From patchwork Fri Jul 27 22:02:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10547767 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 D70D4139A for ; Fri, 27 Jul 2018 22:02:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2C002C73D for ; Fri, 27 Jul 2018 22:02:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6C892C776; Fri, 27 Jul 2018 22:02:07 +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 ED22E2C777 for ; Fri, 27 Jul 2018 22:02:05 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D8799210C42A0; Fri, 27 Jul 2018 15:02:05 -0700 (PDT) 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=192.55.52.151; helo=mga17.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 C1252210C0CE6 for ; Fri, 27 Jul 2018 15:02:04 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2018 15:02:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,411,1526367600"; d="scan'208";a="76152312" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by fmsmga001.fm.intel.com with ESMTP; 27 Jul 2018 15:02:04 -0700 Subject: [PATCH v2 1/6] ndctl: add support for display security state From: Dave Jiang To: vishal.l.verma@intel.com Date: Fri, 27 Jul 2018 15:02:04 -0700 Message-ID: <153272892404.12034.8204619027211673490.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <153272888859.12034.12514972515977309760.stgit@djiang5-desk3.ch.intel.com> References: <153272888859.12034.12514972515977309760.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.27 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 Adding libndctl API call for retrieving security state for a DIMM and also adding support to ndctl list for displaying security state. Signed-off-by: Dave Jiang --- Documentation/ndctl/ndctl-list.txt | 8 ++++++++ ndctl/lib/dimm.c | 16 ++++++++++++++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 1 + util/json.c | 8 ++++++++ 5 files changed, 34 insertions(+) diff --git a/Documentation/ndctl/ndctl-list.txt b/Documentation/ndctl/ndctl-list.txt index 13ebdcdd..57eac1fe 100644 --- a/Documentation/ndctl/ndctl-list.txt +++ b/Documentation/ndctl/ndctl-list.txt @@ -97,6 +97,14 @@ include::xable-region-options.txt[] -D:: --dimms:: Include dimm info in the listing +[verse] +{ + "dev":"nmem0", + "id":"cdab-0a-07e0-ffffffff", + "handle":0, + "phys_id":0, + "security_state:":"disabled" +} -H:: --health:: diff --git a/ndctl/lib/dimm.c b/ndctl/lib/dimm.c index b3e032e0..8ed58559 100644 --- a/ndctl/lib/dimm.c +++ b/ndctl/lib/dimm.c @@ -579,3 +579,19 @@ NDCTL_EXPORT unsigned long ndctl_dimm_get_available_labels( return strtoul(buf, NULL, 0); } + +NDCTL_EXPORT int ndctl_dimm_get_security_state(struct ndctl_dimm *dimm, + char *state) +{ + struct ndctl_ctx *ctx = ndctl_dimm_get_ctx(dimm); + char *path = dimm->dimm_buf; + int len = dimm->buf_len; + + if (snprintf(path, len, "%s/security", dimm->dimm_path) >= len) { + err(ctx, "%s: buffer too small!\n", + ndctl_dimm_get_devname(dimm)); + return -ERANGE; + } + + return sysfs_read_attr(ctx, path, state); +} diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index 8932ef66..8040d7de 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -371,4 +371,5 @@ global: LIBNDCTL_17 { global: ndctl_dimm_smart_inject_supported; + ndctl_dimm_get_security_state; } LIBNDCTL_16; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index 8a96c846..d48513ce 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -659,6 +659,7 @@ unsigned long long ndctl_cmd_fw_fquery_get_fw_rev(struct ndctl_cmd *cmd); enum ND_FW_STATUS ndctl_cmd_fw_xlat_firmware_status(struct ndctl_cmd *cmd); struct ndctl_cmd *ndctl_dimm_cmd_new_ack_shutdown_count(struct ndctl_dimm *dimm); int ndctl_dimm_fw_update_supported(struct ndctl_dimm *dimm); +int ndctl_dimm_get_security_state(struct ndctl_dimm *dimm, char *state); #ifdef __cplusplus } /* extern "C" */ diff --git a/util/json.c b/util/json.c index 13324588..90f05528 100644 --- a/util/json.c +++ b/util/json.c @@ -164,6 +164,7 @@ struct json_object *util_dimm_to_json(struct ndctl_dimm *dimm, unsigned int handle = ndctl_dimm_get_handle(dimm); unsigned short phys_id = ndctl_dimm_get_phys_id(dimm); struct json_object *jobj; + char security_state[32]; if (!jdimm) return NULL; @@ -243,6 +244,13 @@ struct json_object *util_dimm_to_json(struct ndctl_dimm *dimm, json_object_object_add(jdimm, "flag_smart_event", jobj); } + if (ndctl_dimm_get_security_state(dimm, security_state) == 0) { + jobj = json_object_new_string(security_state); + if (!jobj) + goto err; + json_object_object_add(jdimm, "security_state:", jobj); + } + return jdimm; err: json_object_put(jdimm); From patchwork Fri Jul 27 22:02:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10547769 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 A1397139A for ; Fri, 27 Jul 2018 22:02:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90ED62C784 for ; Fri, 27 Jul 2018 22:02:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EEE02C787; Fri, 27 Jul 2018 22:02:12 +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 10A012C77D for ; Fri, 27 Jul 2018 22:02:12 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EE098210C42A4; Fri, 27 Jul 2018 15:02:11 -0700 (PDT) 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.31; helo=mga06.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 5775F210C0CE5 for ; Fri, 27 Jul 2018 15:02:10 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2018 15:02:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,411,1526367600"; d="scan'208";a="71069263" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by fmsmga002.fm.intel.com with ESMTP; 27 Jul 2018 15:02:09 -0700 Subject: [PATCH v2 2/6] ndctl: add update to security support From: Dave Jiang To: vishal.l.verma@intel.com Date: Fri, 27 Jul 2018 15:02:09 -0700 Message-ID: <153272892940.12034.13224628964126308664.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <153272888859.12034.12514972515977309760.stgit@djiang5-desk3.ch.intel.com> References: <153272888859.12034.12514972515977309760.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.27 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 API call for triggering sysfs knob to update the security for a DIMM in libndctl. Also add the ndctl "update-security" to trigger that as well. ndctl does not actually handle the passphrase file. It only initiates the update and expects all the necessary mechanisms are already in place. Signed-off-by: Dave Jiang --- Documentation/ndctl/Makefile.am | 1 + Documentation/ndctl/ndctl-update-security.txt | 21 +++++++++++++++++++++ builtin.h | 1 + ndctl/dimm.c | 22 ++++++++++++++++++++++ ndctl/lib/dimm.c | 20 ++++++++++++++++++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 1 + ndctl/ndctl.c | 1 + 8 files changed, 68 insertions(+) create mode 100644 Documentation/ndctl/ndctl-update-security.txt diff --git a/Documentation/ndctl/Makefile.am b/Documentation/ndctl/Makefile.am index 4fd9636f..02405c44 100644 --- a/Documentation/ndctl/Makefile.am +++ b/Documentation/ndctl/Makefile.am @@ -46,6 +46,7 @@ man1_MANS = \ ndctl-inject-error.1 \ ndctl-inject-smart.1 \ ndctl-update-firmware.1 \ + ndctl-update-security.1 \ ndctl-list.1 CLEANFILES = $(man1_MANS) diff --git a/Documentation/ndctl/ndctl-update-security.txt b/Documentation/ndctl/ndctl-update-security.txt new file mode 100644 index 00000000..38ca02fa --- /dev/null +++ b/Documentation/ndctl/ndctl-update-security.txt @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 + +ndctl-update-security(1) +======================== + +NAME +---- +ndctl-update-security - enabling or update the security passphrase for an NVDIMM + +SYNOPSIS +-------- +[verse] +'ndctl update-security' + +DESCRIPTION +----------- +Provide a generic interface for enabling or updating security passphrase for +NVDIMM. The use of this depends on support from the underlying libndctl, kernel, +as well as the platform itself. + +include::../copyright.txt[] diff --git a/builtin.h b/builtin.h index d3cc7239..e6dc5340 100644 --- a/builtin.h +++ b/builtin.h @@ -47,4 +47,5 @@ int cmd_bat(int argc, const char **argv, void *ctx); #endif int cmd_update_firmware(int argc, const char **argv, void *ctx); int cmd_inject_smart(int argc, const char **argv, void *ctx); +int cmd_update_security(int argc, const char **argv, void *ctx); #endif /* _NDCTL_BUILTIN_H_ */ diff --git a/ndctl/dimm.c b/ndctl/dimm.c index 97643a3c..274714d6 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -821,6 +821,18 @@ static int action_update(struct ndctl_dimm *dimm, struct action_context *actx) return rc; } +static int action_security_update(struct ndctl_dimm *dimm, + struct action_context *actx) +{ + int rc; + + rc = ndctl_dimm_set_change_key(dimm); + if (rc < 0) + error("Failed to update security for %s\n", + ndctl_dimm_get_devname(dimm)); + return rc; +} + static struct parameters { const char *bus; const char *outfile; @@ -1178,3 +1190,13 @@ int cmd_update_firmware(int argc, const char **argv, void *ctx) count > 1 ? "s" : ""); return count >= 0 ? 0 : EXIT_FAILURE; } + +int cmd_update_security(int argc, const char **argv, void *ctx) +{ + int count = dimm_action(argc, argv, ctx, action_security_update, base_options, + "ndctl update-security [..] []"); + + fprintf(stderr, "security updated %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 8ed58559..ca4d439b 100644 --- a/ndctl/lib/dimm.c +++ b/ndctl/lib/dimm.c @@ -595,3 +595,23 @@ NDCTL_EXPORT int ndctl_dimm_get_security_state(struct ndctl_dimm *dimm, return sysfs_read_attr(ctx, path, state); } + +static int ndctl_dimm_write_security(struct ndctl_dimm *dimm, const char *cmd) +{ + struct ndctl_ctx *ctx = ndctl_dimm_get_ctx(dimm); + char *path = dimm->dimm_buf; + int len = dimm->buf_len; + + if (snprintf(path, len, "%s/security", dimm->dimm_path) >= len) { + err(ctx, "%s: buffer too small!\n", + ndctl_dimm_get_devname(dimm)); + return -ERANGE; + } + + return sysfs_write_attr(ctx, path, cmd); +} + +NDCTL_EXPORT int ndctl_dimm_set_change_key(struct ndctl_dimm *dimm) +{ + return ndctl_dimm_write_security(dimm, "update"); +} diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index 8040d7de..e2a359b8 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -372,4 +372,5 @@ LIBNDCTL_17 { global: ndctl_dimm_smart_inject_supported; ndctl_dimm_get_security_state; + ndctl_dimm_set_change_key; } LIBNDCTL_16; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index d48513ce..663847b6 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -660,6 +660,7 @@ enum ND_FW_STATUS ndctl_cmd_fw_xlat_firmware_status(struct ndctl_cmd *cmd); struct ndctl_cmd *ndctl_dimm_cmd_new_ack_shutdown_count(struct ndctl_dimm *dimm); int ndctl_dimm_fw_update_supported(struct ndctl_dimm *dimm); int ndctl_dimm_get_security_state(struct ndctl_dimm *dimm, char *state); +int ndctl_dimm_set_change_key(struct ndctl_dimm *dimm); #ifdef __cplusplus } /* extern "C" */ diff --git a/ndctl/ndctl.c b/ndctl/ndctl.c index 7daadebd..81987e81 100644 --- a/ndctl/ndctl.c +++ b/ndctl/ndctl.c @@ -88,6 +88,7 @@ static struct cmd_struct commands[] = { { "inject-smart", cmd_inject_smart }, { "wait-scrub", cmd_wait_scrub }, { "start-scrub", cmd_start_scrub }, + { "update-security", cmd_update_security }, { "list", cmd_list }, { "help", cmd_help }, #ifdef ENABLE_TEST From patchwork Fri Jul 27 22:02:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10547771 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 B7C0B13BB for ; Fri, 27 Jul 2018 22:02:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A622C2C77B for ; Fri, 27 Jul 2018 22:02:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 932F22C787; Fri, 27 Jul 2018 22:02:17 +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 212B22C77E for ; Fri, 27 Jul 2018 22:02:17 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1A73F210C0CE6; Fri, 27 Jul 2018 15:02:17 -0700 (PDT) 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=192.55.52.115; helo=mga14.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 1BC55210C0CE6 for ; Fri, 27 Jul 2018 15:02:16 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2018 15:02:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,411,1526367600"; d="scan'208";a="61323433" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by orsmga006.jf.intel.com with ESMTP; 27 Jul 2018 15:02:15 -0700 Subject: [PATCH v2 3/6] ndctl: add disable security support From: Dave Jiang To: vishal.l.verma@intel.com Date: Fri, 27 Jul 2018 15:02:14 -0700 Message-ID: <153272893474.12034.381764899107567778.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <153272888859.12034.12514972515977309760.stgit@djiang5-desk3.ch.intel.com> References: <153272888859.12034.12514972515977309760.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.27 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 disable security to libndctl and also command line option of "disable-security" for ndctl. This provides a way to disable security on the nvdimm. ndctl does not handle the actual processing of the passphrase. It only starts the request. Signed-off-by: Dave Jiang --- Documentation/ndctl/Makefile.am | 1 + Documentation/ndctl/ndctl-disable-security.txt | 21 +++++++++++++++++++++ builtin.h | 1 + ndctl/dimm.c | 22 ++++++++++++++++++++++ ndctl/lib/dimm.c | 5 +++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 1 + ndctl/ndctl.c | 1 + 8 files changed, 53 insertions(+) create mode 100644 Documentation/ndctl/ndctl-disable-security.txt diff --git a/Documentation/ndctl/Makefile.am b/Documentation/ndctl/Makefile.am index 02405c44..b1cb3b5b 100644 --- a/Documentation/ndctl/Makefile.am +++ b/Documentation/ndctl/Makefile.am @@ -47,6 +47,7 @@ man1_MANS = \ ndctl-inject-smart.1 \ ndctl-update-firmware.1 \ ndctl-update-security.1 \ + ndctl-disable-security.1 \ ndctl-list.1 CLEANFILES = $(man1_MANS) diff --git a/Documentation/ndctl/ndctl-disable-security.txt b/Documentation/ndctl/ndctl-disable-security.txt new file mode 100644 index 00000000..651f8d03 --- /dev/null +++ b/Documentation/ndctl/ndctl-disable-security.txt @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 + +ndctl-disable-security(1) +======================== + +NAME +---- +ndctl-disable-security - enabling or disable security for an NVDIMM + +SYNOPSIS +-------- +[verse] +'ndctl disable-security' + +DESCRIPTION +----------- +Provide a generic interface for disabling security for NVDIMM. The use of this +depends on support from the underlying libndctl, kernel, as well as the +platform itself. + +include::../copyright.txt[] diff --git a/builtin.h b/builtin.h index e6dc5340..e8ba9aee 100644 --- a/builtin.h +++ b/builtin.h @@ -48,4 +48,5 @@ int cmd_bat(int argc, const char **argv, void *ctx); int cmd_update_firmware(int argc, const char **argv, void *ctx); int cmd_inject_smart(int argc, const char **argv, void *ctx); int cmd_update_security(int argc, const char **argv, void *ctx); +int cmd_disable_security(int argc, const char **argv, void *ctx); #endif /* _NDCTL_BUILTIN_H_ */ diff --git a/ndctl/dimm.c b/ndctl/dimm.c index 274714d6..e64f6717 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -833,6 +833,18 @@ static int action_security_update(struct ndctl_dimm *dimm, return rc; } +static int action_security_disable(struct ndctl_dimm *dimm, + struct action_context *actx) +{ + int rc; + + rc = ndctl_dimm_disable_security(dimm); + if (rc < 0) + error("Failed to disable security for %s\n", + ndctl_dimm_get_devname(dimm)); + return rc; +} + static struct parameters { const char *bus; const char *outfile; @@ -1200,3 +1212,13 @@ int cmd_update_security(int argc, const char **argv, void *ctx) count > 1 ? "s" : ""); return count >= 0 ? 0 : EXIT_FAILURE; } + +int cmd_disable_security(int argc, const char **argv, void *ctx) +{ + int count = dimm_action(argc, argv, ctx, action_security_disable, base_options, + "ndctl disable-security [..] []"); + + fprintf(stderr, "security disabled %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 ca4d439b..13c2806c 100644 --- a/ndctl/lib/dimm.c +++ b/ndctl/lib/dimm.c @@ -615,3 +615,8 @@ NDCTL_EXPORT int ndctl_dimm_set_change_key(struct ndctl_dimm *dimm) { return ndctl_dimm_write_security(dimm, "update"); } + +NDCTL_EXPORT int ndctl_dimm_disable_security(struct ndctl_dimm *dimm) +{ + return ndctl_dimm_write_security(dimm, "disable"); +} diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index e2a359b8..1a919567 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -373,4 +373,5 @@ global: ndctl_dimm_smart_inject_supported; ndctl_dimm_get_security_state; ndctl_dimm_set_change_key; + ndctl_dimm_disable_security; } LIBNDCTL_16; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index 663847b6..1ca6cb18 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -661,6 +661,7 @@ struct ndctl_cmd *ndctl_dimm_cmd_new_ack_shutdown_count(struct ndctl_dimm *dimm) int ndctl_dimm_fw_update_supported(struct ndctl_dimm *dimm); int ndctl_dimm_get_security_state(struct ndctl_dimm *dimm, char *state); int ndctl_dimm_set_change_key(struct ndctl_dimm *dimm); +int ndctl_dimm_disable_security(struct ndctl_dimm *dimm); #ifdef __cplusplus } /* extern "C" */ diff --git a/ndctl/ndctl.c b/ndctl/ndctl.c index 81987e81..eeef41da 100644 --- a/ndctl/ndctl.c +++ b/ndctl/ndctl.c @@ -89,6 +89,7 @@ static struct cmd_struct commands[] = { { "wait-scrub", cmd_wait_scrub }, { "start-scrub", cmd_start_scrub }, { "update-security", cmd_update_security }, + { "disable-security", cmd_disable_security }, { "list", cmd_list }, { "help", cmd_help }, #ifdef ENABLE_TEST From patchwork Fri Jul 27 22:02:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10547773 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 B69E213BB for ; Fri, 27 Jul 2018 22:02:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6C082C768 for ; Fri, 27 Jul 2018 22:02:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A50102C77A; Fri, 27 Jul 2018 22:02:23 +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 33F3D2C768 for ; Fri, 27 Jul 2018 22:02:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2EB35210C42A3; Fri, 27 Jul 2018 15:02:23 -0700 (PDT) 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 D2A25210C0CE5 for ; Fri, 27 Jul 2018 15:02:21 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2018 15:02:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,411,1526367600"; d="scan'208";a="57758304" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by fmsmga007.fm.intel.com with ESMTP; 27 Jul 2018 15:02:20 -0700 Subject: [PATCH v2 4/6] ndctl: add support for freeze security From: Dave Jiang To: vishal.l.verma@intel.com Date: Fri, 27 Jul 2018 15:02:20 -0700 Message-ID: <153272894049.12034.10759311443620519377.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <153272888859.12034.12514972515977309760.stgit@djiang5-desk3.ch.intel.com> References: <153272888859.12034.12514972515977309760.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.27 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 freeze security to libndctl and also command line option of "freeze-security" for ndctl. This will lock the ability to make changes to the NVDIMM security. Signed-off-by: Dave Jiang --- Documentation/ndctl/Makefile.am | 1 + Documentation/ndctl/ndctl-freeze-security.txt | 21 +++++++++++++++++++++ builtin.h | 1 + ndctl/dimm.c | 22 ++++++++++++++++++++++ ndctl/lib/dimm.c | 5 +++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 1 + ndctl/ndctl.c | 1 + 8 files changed, 53 insertions(+) create mode 100644 Documentation/ndctl/ndctl-freeze-security.txt diff --git a/Documentation/ndctl/Makefile.am b/Documentation/ndctl/Makefile.am index b1cb3b5b..98348178 100644 --- a/Documentation/ndctl/Makefile.am +++ b/Documentation/ndctl/Makefile.am @@ -48,6 +48,7 @@ man1_MANS = \ ndctl-update-firmware.1 \ ndctl-update-security.1 \ ndctl-disable-security.1 \ + ndctl-freeze-security.1 \ ndctl-list.1 CLEANFILES = $(man1_MANS) diff --git a/Documentation/ndctl/ndctl-freeze-security.txt b/Documentation/ndctl/ndctl-freeze-security.txt new file mode 100644 index 00000000..343bb019 --- /dev/null +++ b/Documentation/ndctl/ndctl-freeze-security.txt @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 + +ndctl-freeze-security(1) +======================== + +NAME +---- +ndctl-freeze-security - enabling or freeze the security for an NVDIMM + +SYNOPSIS +-------- +[verse] +'ndctl freeze-security' + +DESCRIPTION +----------- +Provide a generic interface to freeze the security for NVDIMM. The use of this +depends on support from the underlying libndctl, kernel, as well as the +platform itself. + +include::../copyright.txt[] diff --git a/builtin.h b/builtin.h index e8ba9aee..6e6ae069 100644 --- a/builtin.h +++ b/builtin.h @@ -49,4 +49,5 @@ int cmd_update_firmware(int argc, const char **argv, void *ctx); int cmd_inject_smart(int argc, const char **argv, void *ctx); int cmd_update_security(int argc, const char **argv, void *ctx); int cmd_disable_security(int argc, const char **argv, void *ctx); +int cmd_freeze_security(int argc, const char **argv, void *ctx); #endif /* _NDCTL_BUILTIN_H_ */ diff --git a/ndctl/dimm.c b/ndctl/dimm.c index e64f6717..49097cff 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -845,6 +845,18 @@ static int action_security_disable(struct ndctl_dimm *dimm, return rc; } +static int action_security_freeze(struct ndctl_dimm *dimm, + struct action_context *actx) +{ + int rc; + + rc = ndctl_dimm_freeze_security(dimm); + if (rc < 0) + error("Failed to freeze security for %s\n", + ndctl_dimm_get_devname(dimm)); + return rc; +} + static struct parameters { const char *bus; const char *outfile; @@ -1222,3 +1234,13 @@ int cmd_disable_security(int argc, const char **argv, void *ctx) count > 1 ? "s" : ""); return count >= 0 ? 0 : EXIT_FAILURE; } + +int cmd_freeze_security(int argc, const char **argv, void *ctx) +{ + int count = dimm_action(argc, argv, ctx, action_security_freeze, base_options, + "ndctl freeze-security [..] []"); + + fprintf(stderr, "security freezed %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 13c2806c..2ff68daa 100644 --- a/ndctl/lib/dimm.c +++ b/ndctl/lib/dimm.c @@ -620,3 +620,8 @@ NDCTL_EXPORT int ndctl_dimm_disable_security(struct ndctl_dimm *dimm) { return ndctl_dimm_write_security(dimm, "disable"); } + +NDCTL_EXPORT int ndctl_dimm_freeze_security(struct ndctl_dimm *dimm) +{ + return ndctl_dimm_write_security(dimm, "freeze"); +} diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index 1a919567..613d9bb2 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -374,4 +374,5 @@ global: ndctl_dimm_get_security_state; ndctl_dimm_set_change_key; ndctl_dimm_disable_security; + ndctl_dimm_freeze_security; } LIBNDCTL_16; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index 1ca6cb18..4615ba09 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -662,6 +662,7 @@ int ndctl_dimm_fw_update_supported(struct ndctl_dimm *dimm); int ndctl_dimm_get_security_state(struct ndctl_dimm *dimm, char *state); int ndctl_dimm_set_change_key(struct ndctl_dimm *dimm); int ndctl_dimm_disable_security(struct ndctl_dimm *dimm); +int ndctl_dimm_freeze_security(struct ndctl_dimm *dimm); #ifdef __cplusplus } /* extern "C" */ diff --git a/ndctl/ndctl.c b/ndctl/ndctl.c index eeef41da..5a1a81e4 100644 --- a/ndctl/ndctl.c +++ b/ndctl/ndctl.c @@ -90,6 +90,7 @@ static struct cmd_struct commands[] = { { "start-scrub", cmd_start_scrub }, { "update-security", cmd_update_security }, { "disable-security", cmd_disable_security }, + { "freeze-security", cmd_freeze_security }, { "list", cmd_list }, { "help", cmd_help }, #ifdef ENABLE_TEST From patchwork Fri Jul 27 22:02:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10547777 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 2BF90139A for ; Fri, 27 Jul 2018 22:02:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B4542C4BC for ; Fri, 27 Jul 2018 22:02:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FB472C725; Fri, 27 Jul 2018 22:02:50 +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 6935F2C4BC for ; Fri, 27 Jul 2018 22:02:49 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 60C0F210C42A0; Fri, 27 Jul 2018 15:02:49 -0700 (PDT) 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=192.55.52.88; helo=mga01.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 9696A210C0CE5 for ; Fri, 27 Jul 2018 15:02:47 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2018 15:02:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,411,1526367600"; d="scan'208";a="58494541" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by fmsmga008.fm.intel.com with ESMTP; 27 Jul 2018 15:02:26 -0700 Subject: [PATCH v2 5/6] ndctl: add support for secure erase From: Dave Jiang To: vishal.l.verma@intel.com Date: Fri, 27 Jul 2018 15:02:25 -0700 Message-ID: <153272894594.12034.14402321529232089624.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <153272888859.12034.12514972515977309760.stgit@djiang5-desk3.ch.intel.com> References: <153272888859.12034.12514972515977309760.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.27 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 secure erase to libndctl and also command line option of "secure-erase" for ndctl. This will initiate the request to securely erase a DIMM. ndctl does not actually handle the verification of the security. That is handled by the kernel and the key upcall mechanism. Signed-off-by: Dave Jiang --- Documentation/ndctl/Makefile.am | 1 + Documentation/ndctl/ndctl-secure-erase.txt | 21 +++++++++++++++++++++ builtin.h | 1 + ndctl/dimm.c | 21 +++++++++++++++++++++ ndctl/lib/dimm.c | 5 +++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 1 + ndctl/ndctl.c | 1 + 8 files changed, 52 insertions(+) create mode 100644 Documentation/ndctl/ndctl-secure-erase.txt diff --git a/Documentation/ndctl/Makefile.am b/Documentation/ndctl/Makefile.am index 98348178..8a84c11c 100644 --- a/Documentation/ndctl/Makefile.am +++ b/Documentation/ndctl/Makefile.am @@ -49,6 +49,7 @@ man1_MANS = \ ndctl-update-security.1 \ ndctl-disable-security.1 \ ndctl-freeze-security.1 \ + ndctl-secure-erase.1 \ ndctl-list.1 CLEANFILES = $(man1_MANS) diff --git a/Documentation/ndctl/ndctl-secure-erase.txt b/Documentation/ndctl/ndctl-secure-erase.txt new file mode 100644 index 00000000..8f82248a --- /dev/null +++ b/Documentation/ndctl/ndctl-secure-erase.txt @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 + +ndctl-secure-erase(1) +===================== + +NAME +---- +ndctl-secure-erase - securely erasing the user data on the NVDIMM + +SYNOPSIS +-------- +[verse] +'ndctl secure-erase' + +DESCRIPTION +----------- +Provide a generic interface to securely erase NVDIMM. This does not change +the label storage area. The use of this depends on support from the underlying +libndctl, kernel, as well as the platform itself. + +include::../copyright.txt[] diff --git a/builtin.h b/builtin.h index 6e6ae069..a9b6443e 100644 --- a/builtin.h +++ b/builtin.h @@ -50,4 +50,5 @@ int cmd_inject_smart(int argc, const char **argv, void *ctx); int cmd_update_security(int argc, const char **argv, void *ctx); int cmd_disable_security(int argc, const char **argv, void *ctx); int cmd_freeze_security(int argc, const char **argv, void *ctx); +int cmd_secure_erase(int argc, const char **argv, void *ctx); #endif /* _NDCTL_BUILTIN_H_ */ diff --git a/ndctl/dimm.c b/ndctl/dimm.c index 49097cff..45c9efce 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -857,6 +857,17 @@ static int action_security_freeze(struct ndctl_dimm *dimm, return rc; } +static int action_secure_erase(struct ndctl_dimm *dimm, + struct action_context *actx) +{ + int rc; + + rc = ndctl_dimm_secure_erase(dimm); + if (rc < 0) + error("Failed to secure erase for %s\n", + ndctl_dimm_get_devname(dimm)); + return rc; +} static struct parameters { const char *bus; const char *outfile; @@ -1244,3 +1255,13 @@ int cmd_freeze_security(int argc, const char **argv, void *ctx) count > 1 ? "s" : ""); return count >= 0 ? 0 : EXIT_FAILURE; } + +int cmd_secure_erase(int argc, const char **argv, void *ctx) +{ + int count = dimm_action(argc, argv, ctx, action_secure_erase, base_options, + "ndctl secure-erase [..] []"); + + fprintf(stderr, "secure erased %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 2ff68daa..bb896d21 100644 --- a/ndctl/lib/dimm.c +++ b/ndctl/lib/dimm.c @@ -625,3 +625,8 @@ NDCTL_EXPORT int ndctl_dimm_freeze_security(struct ndctl_dimm *dimm) { return ndctl_dimm_write_security(dimm, "freeze"); } + +NDCTL_EXPORT int ndctl_dimm_secure_erase(struct ndctl_dimm *dimm) +{ + return ndctl_dimm_write_security(dimm, "erase"); +} diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index 613d9bb2..08727f94 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -375,4 +375,5 @@ global: ndctl_dimm_set_change_key; ndctl_dimm_disable_security; ndctl_dimm_freeze_security; + ndctl_dimm_secure_erase; } LIBNDCTL_16; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index 4615ba09..88ba8a29 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -663,6 +663,7 @@ int ndctl_dimm_get_security_state(struct ndctl_dimm *dimm, char *state); int ndctl_dimm_set_change_key(struct ndctl_dimm *dimm); int ndctl_dimm_disable_security(struct ndctl_dimm *dimm); int ndctl_dimm_freeze_security(struct ndctl_dimm *dimm); +int ndctl_dimm_secure_erase(struct ndctl_dimm *dimm); #ifdef __cplusplus } /* extern "C" */ diff --git a/ndctl/ndctl.c b/ndctl/ndctl.c index 5a1a81e4..b1a91033 100644 --- a/ndctl/ndctl.c +++ b/ndctl/ndctl.c @@ -91,6 +91,7 @@ static struct cmd_struct commands[] = { { "update-security", cmd_update_security }, { "disable-security", cmd_disable_security }, { "freeze-security", cmd_freeze_security }, + { "secure-erase", cmd_secure_erase }, { "list", cmd_list }, { "help", cmd_help }, #ifdef ENABLE_TEST From patchwork Fri Jul 27 22:02:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10547775 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 F0249139A for ; Fri, 27 Jul 2018 22:02:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFAB52C712 for ; Fri, 27 Jul 2018 22:02:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3CD42C725; Fri, 27 Jul 2018 22:02:35 +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 4EC632C712 for ; Fri, 27 Jul 2018 22:02:35 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 46ED5210C2D9C; Fri, 27 Jul 2018 15:02:35 -0700 (PDT) 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=192.55.52.115; helo=mga14.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 E1A4A210C0CE5 for ; Fri, 27 Jul 2018 15:02:33 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2018 15:02:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,411,1526367600"; d="scan'208";a="57758343" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by fmsmga007.fm.intel.com with ESMTP; 27 Jul 2018 15:02:31 -0700 Subject: [PATCH v2 6/6] ndctl: add request-key upcall reference app From: Dave Jiang To: vishal.l.verma@intel.com Date: Fri, 27 Jul 2018 15:02:31 -0700 Message-ID: <153272895127.12034.14914040322261561207.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <153272888859.12034.12514972515977309760.stgit@djiang5-desk3.ch.intel.com> References: <153272888859.12034.12514972515977309760.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.27 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 Adding a reference upcall helper for request-key in order to retrieve the security passphrase from userspace to provide to the kernel. The reference app uses keyutils API to respond to the upcall from the kernel and is invoked by /sbin/request-key of the keyutils. Signed-off-by: Dave Jiang --- Documentation/ndctl/Makefile.am | 3 - Documentation/ndctl/nvdimm-upcall.txt | 33 ++++++++ configure.ac | 1 ndctl.spec.in | 2 ndctl/Makefile.am | 5 + ndctl/nvdimm-upcall.c | 138 +++++++++++++++++++++++++++++++++ 6 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 Documentation/ndctl/nvdimm-upcall.txt create mode 100644 ndctl/nvdimm-upcall.c diff --git a/Documentation/ndctl/Makefile.am b/Documentation/ndctl/Makefile.am index 8a84c11c..d61e5f9a 100644 --- a/Documentation/ndctl/Makefile.am +++ b/Documentation/ndctl/Makefile.am @@ -50,7 +50,8 @@ man1_MANS = \ ndctl-disable-security.1 \ ndctl-freeze-security.1 \ ndctl-secure-erase.1 \ - ndctl-list.1 + ndctl-list.1 \ + nvdimm-upcall.1 CLEANFILES = $(man1_MANS) diff --git a/Documentation/ndctl/nvdimm-upcall.txt b/Documentation/ndctl/nvdimm-upcall.txt new file mode 100644 index 00000000..bbf52fd1 --- /dev/null +++ b/Documentation/ndctl/nvdimm-upcall.txt @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 + +nvdimm-upcall(1) +================ + +NAME +---- +nvdimm-upcall - upcall helper for keyutils + +SYNOPSIS +-------- +[verse] +'nvdimm-upcall' [key_id] + +DESCRIPTION +----------- +nvdimm-upcall is called by request-key from keyutils and not meant to be used +directly by the user. It expects to read from /etc/nvdimm.passwd to retrieve +the description and passphrase for the NVDIMM key. + +The nvdimm.passwd is formatted as: +: +cdab-0a-07e0-feffffff:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + +In order for this util to be called, /etc/request-key.conf must be appended +with the following line: +create logon nvdimm* * /usr/sbin/nvdimm-upcall %k + +include::../copyright.txt[] + +SEE ALSO +-------- +http://pmem.io/documents/NVDIMM_DSM_Interface-V1.7.pdf diff --git a/configure.ac b/configure.ac index cf442607..4b125919 100644 --- a/configure.ac +++ b/configure.ac @@ -114,6 +114,7 @@ PKG_CHECK_MODULES([KMOD], [libkmod]) PKG_CHECK_MODULES([UDEV], [libudev]) PKG_CHECK_MODULES([UUID], [uuid]) PKG_CHECK_MODULES([JSON], [json-c]) +PKG_CHECK_MODULES([KEYUTILS], [keyutils]) AC_ARG_WITH([bash-completion-dir], AS_HELP_STRING([--with-bash-completion-dir[=PATH]], diff --git a/ndctl.spec.in b/ndctl.spec.in index e2c879ca..342f01d7 100644 --- a/ndctl.spec.in +++ b/ndctl.spec.in @@ -20,6 +20,7 @@ BuildRequires: pkgconfig(libudev) BuildRequires: pkgconfig(uuid) BuildRequires: pkgconfig(json-c) BuildRequires: pkgconfig(bash-completion) +BuildRequires: pkgconfig(keyutils) %description Utility library for managing the "libnvdimm" subsystem. The "libnvdimm" @@ -116,6 +117,7 @@ make check %{_bindir}/ndctl %{_mandir}/man1/ndctl* %{bashcompdir}/ +%{_sbindir}/nvdimm-upcall %files -n daxctl %defattr(-,root,root) diff --git a/ndctl/Makefile.am b/ndctl/Makefile.am index 0f568719..d6401df9 100644 --- a/ndctl/Makefile.am +++ b/ndctl/Makefile.am @@ -1,6 +1,7 @@ include $(top_srcdir)/Makefile.am.in bin_PROGRAMS = ndctl +sbin_PROGRAMS = nvdimm-upcall ndctl_SOURCES = ndctl.c \ bus.c \ @@ -41,3 +42,7 @@ ndctl_SOURCES += ../test/libndctl.c \ ../test/core.c \ test.c endif + +nvdimm_upcall_SOURCES = nvdimm-upcall.c + +nvdimm_upcall_LDADD = $(KEYUTILS_LIBS) diff --git a/ndctl/nvdimm-upcall.c b/ndctl/nvdimm-upcall.c new file mode 100644 index 00000000..9406b23a --- /dev/null +++ b/ndctl/nvdimm-upcall.c @@ -0,0 +1,138 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright(c) 2018 Intel Corporation. All rights reserved. */ + +/* + * Used by /sbin/request-key for handling nvdimm upcall of key requests + * for security DSMs. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PASSPHRASE_SIZE 32 +#define PASS_PATH "/etc/nvdimm.passwd" + +static FILE *fp; + +static int get_passphrase_from_id(const char *id, char *pass, int *psize) +{ + ssize_t rc = 0; + size_t size; + char *line = NULL; + char *tmp, *id_tok, *secret; + int found = 0; + + fp = fopen(PASS_PATH, "r+"); + if (!fp) { + syslog(LOG_ERR, "fopen: %s\n", strerror(errno)); + return -errno; + } + + while ((rc = getline(&line, &size, fp)) != -1) { + id_tok = strtok_r(line, ":", &tmp); + if (!id_tok) + break; + if (strcmp(id_tok, id) == 0) { + secret = tmp; + found = 1; + rc = 0; + break; + } + } + + if (rc == 0 && found && secret) { + memset(pass, 0, PASSPHRASE_SIZE*2+1); + size = MIN(strlen(secret), (PASSPHRASE_SIZE*2+1)); + memcpy(pass, secret, size); + *psize = size-1; + } else + rc = -ENXIO; + + free(line); + fclose(fp); + return rc; +} + +static char *get_key_desc(char *buf) +{ + char *tmp = &buf[0]; + int count = 0; + + while (*tmp != '\0') { + if (*tmp == ';') + count++; + if (count == 4) { + tmp++; + return tmp; + } + tmp++; + } + + return NULL; +} + +int main(int argc, const char **argv) +{ + key_serial_t key; + int rc; + char *buf, *desc, *dimm_id, *tmp; + char pass[PASSPHRASE_SIZE * 2 + 1]; + int size = 0; + + if (argc < 2) { + syslog(LOG_ERR, "Incorrect number of arguments\n"); + return -EINVAL; + } + + syslog(LOG_DEBUG, "key passed in: %s\n", argv[1]); + key = strtol(argv[1], NULL, 10); + if (key < 0) { + syslog(LOG_ERR, "Invalid key format: %s\n", strerror(errno)); + return -errno; + } + + rc = keyctl_describe_alloc(key, &buf); + if (rc < 0) { + syslog(LOG_ERR, "keyctl_describe_alloc failed: %s\n", + strerror(errno)); + rc = -errno; + goto out; + } + + desc = get_key_desc(buf); + if (!desc) { + syslog(LOG_ERR, "Can't find key description\n"); + rc = -EINVAL; + goto out; + } + + tmp = strtok_r(desc, ":", &dimm_id); + rc = get_passphrase_from_id(dimm_id, pass, &size); + if (rc < 0) { + syslog(LOG_ERR, "failed to retrieve passphrase\n"); + goto out; + } + + rc = keyctl_instantiate(key, pass, size, 0); + if (rc < 0) { + syslog(LOG_ERR, "keyctl_instantiate failed: %s\n", + strerror(errno)); + rc = -errno; + goto out; + } + + out: + if (rc < 0) + keyctl_negate(key, 1, KEY_REQKEY_DEFL_DEFAULT); + + return rc; +}