Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5650015img; Wed, 27 Mar 2019 12:26:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUynEcIXXpD3j84MUborpNQzlM3ocL/tT4eoSUKSqj2J67QCJ26FlAmWKZOkrr0mA/L1kU X-Received: by 2002:aa7:8282:: with SMTP id s2mr19230014pfm.7.1553714787017; Wed, 27 Mar 2019 12:26:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714787; cv=none; d=google.com; s=arc-20160816; b=ZgUwEHh/5osYXka8kKY1u7WX6+eXV89QkJleny2kh0E3BPft+eQcuyI57LHoHcQ2G6 i2OiN0BZpOUkgltSGVpRnpTryauxzvyNF6saFxLGEzAeD1Cel1Ei+px8J9hd/1cdegfq 6wi2UklFdxmbHa8RVR5KCe4vBtzc8KglDKUzO5iPgR0uFanryKhRiNU1EiEhWN+HJH39 7yHMSbax1mwopT33D7riY/rBmmOmWQ7/qzfQGHlQcQoKxdRZt2Cn6fRqenU/khtLfKNd ea6O1wCHdFeaMP3iT+ErM47SeRIfBkxSAYIVZKvPb7oXzSS/wI1yXbAouYaPSGwP0f1Q UDzg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8Q3dEG2FUOy5UklaQqMwj5TNRimslx2u2XtVqNPjZCY=; b=uGCUiJUYg+1J7tbL+jtCDjN/n5IHhDMly98a++N8ros9LAl6tW/D++EoAgGPFLhUHn 2vV3RWvnoxbeXdI9EXNXP95s6xPqgPOs3ytN+Bn7rlFT/cYr+LmwrZ6ZcaMhmUFBjb+L TYPsdW09LMnieOYsQbjmJWca5M3eD1Dpg+n0ysMOSawxqonF6C0qG/97IREwbTw4UcUu Ueu5GpP4bHA/jzQpcShDDutrvpDei5pZqPO9M/Il/C9Sz25J567rRneJ4hsll0bQD+TI Tq3OHk3TW01838+ZkJpUMMAGkyf309krrueXOI/I/mm5LB8DSPGKCePx9O7nFplKP3ku t49w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NGs1YBcw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 82si19121834pft.35.2019.03.27.12.26.12; Wed, 27 Mar 2019 12:26:27 -0700 (PDT) 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=NGs1YBcw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387957AbfC0TZe (ORCPT + 99 others); Wed, 27 Mar 2019 15:25:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:46344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387634AbfC0SFP (ORCPT ); Wed, 27 Mar 2019 14:05:15 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8A2332063F; Wed, 27 Mar 2019 18:05:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709915; bh=O5LEgMVOmHt8QJYgkL4OQn28TaFUOK0sNvyHudogbus=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NGs1YBcwbTNtHBbPSv48sA9luaJCyyN+pMloTxVLmzDthLuE3wAvAGeSKFrrgEtf4 1k7lfjZh0Ts/Foncl4wwmHGzXYt8vFFWMBaTzbrLCjdK6gvmCqk2qFJyINO/qZMb+O N58VntTkqx8aRKPuCiQNxTU89Yt0JokM1nIaCrpU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ross Lagerwall , "Rafael J . Wysocki" , Sasha Levin , linux-efi@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 110/262] efi: cper: Fix possible out-of-bounds access Date: Wed, 27 Mar 2019 13:59:25 -0400 Message-Id: <20190327180158.10245-110-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ross Lagerwall [ Upstream commit 45b14a4ffcc1e0b5caa246638f942cbe7eaea7ad ] When checking a generic status block, we iterate over all the generic data blocks. The loop condition only checks that the start of the generic data block is valid (within estatus->data_length) but not the whole block. Because the size of data blocks (excluding error data) may vary depending on the revision and the revision is contained within the data block, ensure that enough of the current data block is valid before dereferencing any members otherwise an out-of-bounds access may occur if estatus->data_length is invalid. This relies on the fact that struct acpi_hest_generic_data_v300 is a superset of the earlier version. Also rework the other checks to avoid potential underflow. Signed-off-by: Ross Lagerwall Acked-by: Borislav Petkov Tested-by: Tyler Baicar Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/firmware/efi/cper.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c index a7902fccdcfa..6090d25dce85 100644 --- a/drivers/firmware/efi/cper.c +++ b/drivers/firmware/efi/cper.c @@ -546,19 +546,24 @@ EXPORT_SYMBOL_GPL(cper_estatus_check_header); int cper_estatus_check(const struct acpi_hest_generic_status *estatus) { struct acpi_hest_generic_data *gdata; - unsigned int data_len, gedata_len; + unsigned int data_len, record_size; int rc; rc = cper_estatus_check_header(estatus); if (rc) return rc; + data_len = estatus->data_length; apei_estatus_for_each_section(estatus, gdata) { - gedata_len = acpi_hest_get_error_length(gdata); - if (gedata_len > data_len - acpi_hest_get_size(gdata)) + if (sizeof(struct acpi_hest_generic_data) > data_len) + return -EINVAL; + + record_size = acpi_hest_get_record_size(gdata); + if (record_size > data_len) return -EINVAL; - data_len -= acpi_hest_get_record_size(gdata); + + data_len -= record_size; } if (data_len) return -EINVAL; -- 2.19.1