From patchwork Sat Feb 20 23:00:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 8368041 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 52ADBC0553 for ; Sat, 20 Feb 2016 23:00:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 76EF72041F for ; Sat, 20 Feb 2016 23:00:51 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 8ED8D2041C for ; Sat, 20 Feb 2016 23:00:50 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 425221A1EDC; Sat, 20 Feb 2016 15:00:51 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by ml01.01.org (Postfix) with ESMTP id 34E6E1A1EDC for ; Sat, 20 Feb 2016 15:00:50 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP; 20 Feb 2016 15:00:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,478,1449561600"; d="scan'208";a="890746280" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.136]) by orsmga001.jf.intel.com with ESMTP; 20 Feb 2016 15:00:49 -0800 Subject: [ndctl PATCH] ndctl: fix ars_status output buffer sizing From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 20 Feb 2016 15:00:25 -0800 Message-ID: <20160220230025.21083.79247.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The ars_cap command indicates the buffer size we need to prepare for ars_status commands. The kernel reads the ars_status.out_length field to validate how much output buffer space is available. The ndctl_bus_cmd_new_ars_status() helper was neglecting to set that size. It was also misinterpreting the value of ars_cap.max_ars_out. That value is the total output data size of an ars_status command, not incremental to the base size of a ars_status command. Cc: Vishal Verma Signed-off-by: Dan Williams --- lib/libndctl-ars.c | 4 ++-- test/libndctl.c | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/libndctl-ars.c b/lib/libndctl-ars.c index ea3af82ca647..863217dd09aa 100644 --- a/lib/libndctl-ars.c +++ b/lib/libndctl-ars.c @@ -111,8 +111,7 @@ NDCTL_EXPORT struct ndctl_cmd *ndctl_bus_cmd_new_ars_status(struct ndctl_cmd *ar return NULL; } - size = sizeof(*cmd) + sizeof(struct nd_cmd_ars_status) + - ars_cap_cmd->max_ars_out; + size = sizeof(*cmd) + ars_cap_cmd->max_ars_out; cmd = calloc(1, size); if (!cmd) return NULL; @@ -123,6 +122,7 @@ NDCTL_EXPORT struct ndctl_cmd *ndctl_bus_cmd_new_ars_status(struct ndctl_cmd *ar cmd->size = size; cmd->status = 1; cmd->firmware_status = &cmd->ars_status->status; + cmd->ars_status->out_length = ars_cap_cmd->max_ars_out; return cmd; } diff --git a/test/libndctl.c b/test/libndctl.c index 5c26b5fdffc3..b4539b996d6a 100644 --- a/test/libndctl.c +++ b/test/libndctl.c @@ -1607,9 +1607,10 @@ static int check_ars_cap(struct ndctl_bus *bus, struct ndctl_dimm *dimm, return rc; } - if (ndctl_cmd_ars_cap_get_size(cmd) != 256) { - fprintf(stderr, "%s: bus: %s expect size: %d got: %d\n", - __func__, ndctl_bus_get_provider(bus), 256, + if (ndctl_cmd_ars_cap_get_size(cmd) < sizeof(struct nd_cmd_ars_status)) { + fprintf(stderr, "%s: bus: %s expect size >= %zd got: %d\n", + __func__, ndctl_bus_get_provider(bus), + sizeof(struct nd_cmd_ars_status), ndctl_cmd_ars_cap_get_size(cmd)); ndctl_cmd_unref(cmd); return -ENXIO;