Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4562830imu; Tue, 29 Jan 2019 03:52:02 -0800 (PST) X-Google-Smtp-Source: ALg8bN4+ZCNCkA8PdxTuI9jyTyXwmqUoc5Jhpqgfozl4T6RZ5VCwjvW2M6P5VFB1bXfhstB1DE01 X-Received: by 2002:a62:34c6:: with SMTP id b189mr26481573pfa.229.1548762722931; Tue, 29 Jan 2019 03:52:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548762722; cv=none; d=google.com; s=arc-20160816; b=ddM+bJXKxTEIpcJ8GbYc13eVQE/cciL7vP8h7ACUdOracOdVOjPB0ImMLL+MlMM/JB MVCs3ZH3MjEDOXIiy/JMsJLYKeACTQlTqwkLH5fBzAywd1lVc1NW/nWacwDBClD6tZPk E9wrB/FHWKbHmA6RezyzRWxw5oqxggdYm0S//Ui1OYxBh+AOSP+yJSJvOWLhpgE7GwrA PqgehX31M3D+WNzHVn3L9vsH4ZiiCDSE99fckv7NWF0vqE5k2+2P0MgWbWamdpACcm+W pJwzap8q8+egO3Mn2pmuwQlOSj0t9grOb960WQSvhlTUyy+c26AWwA9stNnuSx+R5Gst 6vKg== 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:subject:cc:to :from:dkim-signature; bh=SXYvBZ8eF+UUTqMpWVy51F5QOqxaupDOPsKTVWoJPrM=; b=L5X3MATqU5GAG+azyLo6cx1qYLXGGhxzOhqC1k/zMUEs5SJDWpzzMJe1cnU4AxQz8K DLzNvPMlWxy0dfQQenTbErItT2mB7Lmem2wdmDazDuYO/XBtXlfd5CYrifAyD5PW2nKr x0Au55GnC+1d2tnvw5SgOqWd5sYVrovTjnftREbtIt+ACphtcfTFZddv6d/5P/YIKjR9 95VttVU2IXd+QUXx2/QVmZH275Zj/sUSZQ7qyRIUZyBsBHgHMxKoaW64gbuRSFi3hexI 1qZC+SY0/z+IwG74zdY2/1UoSw6oqAEnDvDi8VHMOcYQgkDFgTMUOghvdf4L5JUJHkv3 QOvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UrUTX13V; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c13si28977704pgi.531.2019.01.29.03.51.47; Tue, 29 Jan 2019 03:52:02 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=UrUTX13V; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728881AbfA2Lvn (ORCPT + 99 others); Tue, 29 Jan 2019 06:51:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:43196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731402AbfA2Lvj (ORCPT ); Tue, 29 Jan 2019 06:51:39 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 67A6220989; Tue, 29 Jan 2019 11:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548762698; bh=BcfB8XWzX8zWFmgerUr1/At7R2x7oDbOBIz9QX93SHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UrUTX13VXz+4e6gHlPRCim964XmwbPQpioYzdSlgJ7nErdR1I75aZ+4UuWdWvQtJe uoEtI5ErfDOzMCE/xHgGc/xZY9l0Iq6vDvnWg9+vLQ1md3jtDf+z5lP6ZSUjthmdCI /B8DU2SGvVit9qwFqCMumNZDRfk6kF5LQMaweIDI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sujith Pandel , Vishal Verma , Jeff Moyer , Dan Williams Subject: [PATCH 4.9 28/44] acpi/nfit: Fix command-supported detection Date: Tue, 29 Jan 2019 12:36:23 +0100 Message-Id: <20190129113142.163636999@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129113139.826927690@linuxfoundation.org> References: <20190129113139.826927690@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams commit 11189c1089da413aa4b5fd6be4c4d47c78968819 upstream. The _DSM function number validation only happens to succeed when the generic Linux command number translation corresponds with a DSM-family-specific function number. This breaks NVDIMM-N implementations that correctly implement _LSR, _LSW, and _LSI, but do not happen to publish support for DSM function numbers 4, 5, and 6. Recall that the support for _LS{I,R,W} family of methods results in the DIMM being marked as supporting those command numbers at acpi_nfit_register_dimms() time. The DSM function mask is only used for ND_CMD_CALL support of non-NVDIMM_FAMILY_INTEL devices. Fixes: 31eca76ba2fc ("nfit, libnvdimm: limited/whitelisted dimm command...") Cc: Link: https://github.com/pmem/ndctl/issues/78 Reported-by: Sujith Pandel Tested-by: Sujith Pandel Reviewed-by: Vishal Verma Reviewed-by: Jeff Moyer Signed-off-by: Dan Williams Signed-off-by: Greg Kroah-Hartman --- drivers/acpi/nfit/core.c | 50 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -185,6 +185,32 @@ static int xlat_status(struct nvdimm *nv return 0; } +static int cmd_to_func(struct nfit_mem *nfit_mem, unsigned int cmd, + struct nd_cmd_pkg *call_pkg) +{ + if (call_pkg) { + int i; + + if (nfit_mem->family != call_pkg->nd_family) + return -ENOTTY; + + for (i = 0; i < ARRAY_SIZE(call_pkg->nd_reserved2); i++) + if (call_pkg->nd_reserved2[i]) + return -EINVAL; + return call_pkg->nd_command; + } + + /* Linux ND commands == NVDIMM_FAMILY_INTEL function numbers */ + if (nfit_mem->family == NVDIMM_FAMILY_INTEL) + return cmd; + + /* + * Force function number validation to fail since 0 is never + * published as a valid function in dsm_mask. + */ + return 0; +} + int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm, unsigned int cmd, void *buf, unsigned int buf_len, int *cmd_rc) { @@ -197,17 +223,11 @@ int acpi_nfit_ctl(struct nvdimm_bus_desc unsigned long cmd_mask, dsm_mask; u32 offset, fw_status = 0; acpi_handle handle; - unsigned int func; const u8 *uuid; - int rc, i; + int func, rc, i; if (cmd_rc) *cmd_rc = -EINVAL; - func = cmd; - if (cmd == ND_CMD_CALL) { - call_pkg = buf; - func = call_pkg->nd_command; - } if (nvdimm) { struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); @@ -215,9 +235,12 @@ int acpi_nfit_ctl(struct nvdimm_bus_desc if (!adev) return -ENOTTY; - if (call_pkg && nfit_mem->family != call_pkg->nd_family) - return -ENOTTY; + if (cmd == ND_CMD_CALL) + call_pkg = buf; + func = cmd_to_func(nfit_mem, cmd, call_pkg); + if (func < 0) + return func; dimm_name = nvdimm_name(nvdimm); cmd_name = nvdimm_cmd_name(cmd); cmd_mask = nvdimm_cmd_mask(nvdimm); @@ -228,6 +251,7 @@ int acpi_nfit_ctl(struct nvdimm_bus_desc } else { struct acpi_device *adev = to_acpi_dev(acpi_desc); + func = cmd; cmd_name = nvdimm_bus_cmd_name(cmd); cmd_mask = nd_desc->cmd_mask; dsm_mask = cmd_mask; @@ -240,7 +264,13 @@ int acpi_nfit_ctl(struct nvdimm_bus_desc if (!desc || (cmd && (desc->out_num + desc->in_num == 0))) return -ENOTTY; - if (!test_bit(cmd, &cmd_mask) || !test_bit(func, &dsm_mask)) + /* + * Check for a valid command. For ND_CMD_CALL, we also have to + * make sure that the DSM function is supported. + */ + if (cmd == ND_CMD_CALL && !test_bit(func, &dsm_mask)) + return -ENOTTY; + else if (!test_bit(cmd, &cmd_mask)) return -ENOTTY; in_obj.type = ACPI_TYPE_PACKAGE;