Received: by 10.213.65.68 with SMTP id h4csp156476imn; Tue, 3 Apr 2018 17:46:15 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+eMbhXMk5WF9ZDAw3h81HnOgzrUM3aShWtOfKdTREVqLT04/nxY8wgUd03eWPKZL73rw/e X-Received: by 10.98.211.211 with SMTP id z80mr12082773pfk.16.1522802775365; Tue, 03 Apr 2018 17:46:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522802775; cv=none; d=google.com; s=arc-20160816; b=TgNVXcJrqQO1KPK4HDDbEPhTLcjWB3BHdogrXfH0GwKlpaAudZ3nQkXsOF+TokWtol z56HoXaPPtd9NM9nyWZtl7X+qYSoAwYeSD9eYGFREowHj14NuxuG8ePxlbEu2kPWkamD m6x1qqOK1rMZnpuDMVta+HQ1YRcjW7eQ6WMuOLLbvhCpCzXx2lBS3Z5J+EK+kUNfovei nRkN3qN6AHXoD+caNHntTNtmWPx8n0FdtosehB4rVFDAo0iFiJfK40pLf3WqV3rYJ56R /rFDc5iboss1e/BAOfBo6i5+ohDgJsCSAWpD17pGlFTJ4UkDEHVIv/UQoIns+IyfcWii NyuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=fJ0a2W5moIWRDSZwdRBoaux2WM3C+mzu7OVw22HCad4=; b=BOglJDXmhJY4BtrnMM6tRoOpeKWPeWKs4cQ4fKtjfPR6oTRMDxqWSbv9d8Ni7TElT+ YklXEQgr9pVncs17ceBILyIPl+GF3AxEcnnVTHmD6pfDPlwVGvDb7rfPp3Vwgk0DwbtT PIcn58QJ9YxazNVA4aG9N1ONwES/OqVJ71+63MMG7xxBcfNjE67cRIoOnSMJUGsHE1sK lBqumsxxQnX5TjTbeg96UGL5rFKaqyrSTi5/PREPem6eUubKNAgRFgeZ3Qi8RV2qwrN+ kbDzp+Bif4R2i43Cl24pyS/hOCsc3hJk23FA3gzrpjoTeG5q+jZ2pJfUHfwHYy/zkRwS Cx6Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g31-v6si1791631pld.714.2018.04.03.17.46.01; Tue, 03 Apr 2018 17:46:15 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754830AbeDDAo4 (ORCPT + 99 others); Tue, 3 Apr 2018 20:44:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47350 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753468AbeDDAmY (ORCPT ); Tue, 3 Apr 2018 20:42:24 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03C307FEA9; Wed, 4 Apr 2018 00:42:24 +0000 (UTC) Received: from fidelio.ahs3.com (ovpn-116-126.phx2.redhat.com [10.3.116.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A15817BA1; Wed, 4 Apr 2018 00:42:23 +0000 (UTC) From: Al Stone To: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Al Stone , "Rafael J . Wysocki" , Len Brown Subject: [PATCH 2/3] ACPI: ensure acpi_parse_entries_array() does not access non-existent table data Date: Tue, 3 Apr 2018 18:42:10 -0600 Message-Id: <20180404004211.6141-3-ahs3@redhat.com> In-Reply-To: <20180404004211.6141-1-ahs3@redhat.com> References: <20180404004211.6141-1-ahs3@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 04 Apr 2018 00:42:24 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For ACPI tables that have subtables, acpi_parse_entries_array() gets used to step through each of the subtables in memory. The primary loop for this was checking that the beginning location of the subtable being examined plus the length of struct acpi_subtable_header was not beyond the end of the complete ACPI table; if it wasn't, the subtable could be examined, but if it was the loop would terminate as it should. In the middle of this subtable loop, a callback is used to examine the subtable in detail. Should the callback function try to examine elements of the subtable that are located past the subtable header, and the ACPI table containing this subtable has an incorrect length, it is possible to access either invalid or protected memory and cause a fault. And, the length of struct acpi_subtable_header will always be smaller than the length of the actual subtable. To fix this, we make the main loop check that the beginning of the subtable being examined plus the actual length of the subtable does not go past the end of the enclosing ACPI table. While this cannot protect us from malicious callback functions, it can prevent us from failing because of some poorly constructed ACPI tables. Found by inspection. There is no functional change to existing code that is known to work when calling acpi_parse_entries_array(). Signed-off-by: Al Stone Cc: Rafael J. Wysocki Cc: Len Brown --- drivers/acpi/tables.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index b6ac8162a2c0..672a1f22c3a5 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -271,8 +271,7 @@ acpi_parse_entries_array(char *id, unsigned long table_size, entry = (struct acpi_subtable_header *) ((unsigned long)table_header + table_size); - while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) < - table_end) { + while (((unsigned long)entry + entry->length) <= table_end) { if (max_entries && count >= max_entries) break; -- 2.14.3