Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1908478pxu; Tue, 24 Nov 2020 11:47:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwC6O3z10hD4psjcr3elYtAa6/uGSdMOmShHdkjpZ8Q+KZFj42egSU8jkc7o5eSxsWxV1qw X-Received: by 2002:a05:6402:656:: with SMTP id u22mr81382edx.199.1606247275110; Tue, 24 Nov 2020 11:47:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606247275; cv=none; d=google.com; s=arc-20160816; b=Hb/Yw7agqRY3RtW+NZvuu1njmePkt5xPyPti9f2uFYDXrXsYCTUJ0RSz8emutzMjiz hQyWAIBumFOdgL4PAhJazIp8DFoqgCon5jERTXKUq+COZgKnjoghMyw1omTO3y6O3mnk OyEKPGgNbE36Gt+BvUVkCzlV+00wLN0nNUTHqGwW4NfYGfJUqVsqGn3Cn/4+w6ovHhe8 UoT5M38GrlRRc1BTiG/+CMi5LRjnaB4PhZa+Zy32Mm82cm5mcSV35suISkMhFEuTiRBE YA2GY7YtpM9qi9u5ooeFeJReQkhgBTB6IoneCGIN5pdJ5aH89i07eUkdXA2U6mnV3tkD ra3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:date:cc:to:from:subject:ironport-sdr :ironport-sdr; bh=I+6kCEUvBkPJTNt+ISLR1eMS5Oo23lCR2PgPEgkvub0=; b=ZEPEHW7QLHqMIf/ElTZqVC4CCJbaxpndGsvhcrQaLQ6i83FoauEVmIZhHBWm2RpYFG OGnizywT+TrwXJw3gtDk/wy7S11Ro/TGHqvo6LAPROUDXRLdUFSQe1ZLTv/odJilQkV1 xKDcO7tAj8Os7TOfjkpnZjdKRiThzs3RCp4DZFO5a7MQMvTfli3vCJn2vfhm6ifJyRDu 0UxQ7EyWEDLVxKZdJf0ohBF5A6/v47VLNwlIu4t8xR+bsanpu8YvTfGcq38ZNdBOxksk JG/r3IbB0vUawiEuagfQr5r07B8XWF6Q4o9o66QtWQrXHgfGHizsqY5zA81w6DvskVm/ vyCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id bt1si6383980edb.267.2020.11.24.11.47.32; Tue, 24 Nov 2020 11:47:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727440AbgKXF1n (ORCPT + 99 others); Tue, 24 Nov 2020 00:27:43 -0500 Received: from mga14.intel.com ([192.55.52.115]:48669 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725616AbgKXF1n (ORCPT ); Tue, 24 Nov 2020 00:27:43 -0500 IronPort-SDR: 4glW/VM9wevnqIbOO5fZaaF/yv5iqcERsxlZp88COaA9ko6qVbmH2PBSxalvN7w9aWhZKAmSm0 WocJ4+mgLVHA== X-IronPort-AV: E=McAfee;i="6000,8403,9814"; a="171111795" X-IronPort-AV: E=Sophos;i="5.78,365,1599548400"; d="scan'208";a="171111795" 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/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2020 21:27:43 -0800 IronPort-SDR: slVFfxUjVUc5hAVhYANK4q6P8xaOpwCaklMmE441hegdvLl6m4iEchBe6uUU5YnIo5WSePVbu7 MrTpzDEzBqGg== X-IronPort-AV: E=Sophos;i="5.78,365,1599548400"; d="scan'208";a="332439281" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.25]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2020 21:27:42 -0800 Subject: [PATCH] ACPI: NFIT: Fix input validation of bus-family From: Dan Williams To: linux-nvdimm@lists.01.org Cc: Dan Carpenter , stable@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org Date: Mon, 23 Nov 2020 21:27:42 -0800 Message-ID: <160619566216.201177.9354229595539334957.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dan reports that smatch thinks userspace can craft an out-of-bound bus family number. However, nd_cmd_clear_to_send() blocks all non-zero values of bus-family since only the kernel can initiate these commands. However, in the speculation path, family is a user controlled array index value so mask it for speculation safety. Also, since the nd_cmd_clear_to_send() safety is non-obvious and possibly may change in the future include input validation is if userspace could get past the nd_cmd_clear_to_send() gatekeeper. Link: http://lore.kernel.org/r/20201111113000.GA1237157@mwanda Reported-by: Dan Carpenter Fixes: 6450ddbd5d8e ("ACPI: NFIT: Define runtime firmware activation commands") Cc: Signed-off-by: Dan Williams --- drivers/acpi/nfit/core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index cda7b6c52504..b11b08a60684 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -479,8 +480,11 @@ int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm, cmd_mask = nd_desc->cmd_mask; if (cmd == ND_CMD_CALL && call_pkg->nd_family) { family = call_pkg->nd_family; - if (!test_bit(family, &nd_desc->bus_family_mask)) + if (family > NVDIMM_BUS_FAMILY_MAX || + !test_bit(family, &nd_desc->bus_family_mask)) return -EINVAL; + family = array_index_nospec(family, + NVDIMM_BUS_FAMILY_MAX + 1); dsm_mask = acpi_desc->family_dsm_mask[family]; guid = to_nfit_bus_uuid(family); } else {