Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp871393imm; Tue, 15 May 2018 10:20:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZojRkvxFOwuWDkafkYdHcH66SwdFMEaxjmZlWltrMn1cxTNESMyM7Uu/vvHMKyNPDnr6yPG X-Received: by 2002:a17:902:d891:: with SMTP id b17-v6mr15637787plz.0.1526404833328; Tue, 15 May 2018 10:20:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526404833; cv=none; d=google.com; s=arc-20160816; b=yOlRWAh9WI7vaJCOavKQ5g6/yVkO+5YLptTaEpDBTXmcyCgjKBD8KM+uvZqY2tEY6L UCfu1MG3kZXLPQYLXNJKYnfo40uXXRZtMB5OcPZd7bYTG/Afu20d4BiXq3coeVRzhgTg kbDGryThq3fcm6Adt10B38A6T76JLMt7F5znOvcwiRPPf7IwZaHv03bkWcgyiseoe81G Eu3qp3L+F34NnAxiPXppPa86I6GxpHPv4p6TigrzWZw4AKbMazKXyUIIjZpJUCOuX2hR yuyGuGXZixAW/a0dDnLJ5ONaxFk9tTQ/OzXVKTBoPfEGiouLkvctBnQO7WdoTfRNHehU 3/Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=cUIgnP1rbOkd4juPUk79nHzhJJsq6HuglK7+QWrIYBk=; b=itoXvEz9AcrmneAL10N+8iUA7SElFR74hmbLAkXQy1PP1dPKYh0Ne762DcrXMbuhq2 FvZPOVpwFkb/RWp/QNVZLDffa/LGO6LX9EJms6+HTP4vvDZcMUf/abtP3QvYRGakbl/n eDV01b2TeoN8I5E86FGYipIJkMj7Xgdh4Ekduw7xLPFVIoNoJqIU+zLugUxvjs7lr5aK J48vTturTFu3ILDgfO58emTHYxbIF+cNlNTLKeXtCODC9PAJwObPr7HTi41bE7etFXH5 5bOIhpaHd/c/pz+0bgXCeps6WSbSjPD383a06sWf5d4IMt1+npwcj9RvVkAHymszHts2 GRcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=uxcN3L7N; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u36-v6si390806pgn.213.2018.05.15.10.20.09; Tue, 15 May 2018 10:20:33 -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=fail header.i=@gmail.com header.s=20161025 header.b=uxcN3L7N; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754394AbeEORTn (ORCPT + 99 others); Tue, 15 May 2018 13:19:43 -0400 Received: from mail-ot0-f193.google.com ([74.125.82.193]:37346 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754235AbeEORTm (ORCPT ); Tue, 15 May 2018 13:19:42 -0400 Received: by mail-ot0-f193.google.com with SMTP id 77-v6so1100225otd.4; Tue, 15 May 2018 10:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=cUIgnP1rbOkd4juPUk79nHzhJJsq6HuglK7+QWrIYBk=; b=uxcN3L7NmlrB/z9xzadMI8zeHLMPxxCjeYOLDVSDQCA6wxiXsHLGhjU2gdWkHmtTFn xPIRLHOtQivZwKKTY+F94fMhNfQCOYIcPSuJTO8aKKzmziAlMS+sxZSzmA1mEJHCht4z dVt18f4DA1X29HzmWpcCuf/d09uH7MZQdEYdZdyTfApRKVKCDwDwfzBB/SdjSDHefzZ6 Ci9h42ATow/vZyfvg0M+8ltTEub4Ypffi7x+lelJsEYIDCa68+8Rv6vrOq9RiEPwMdYk HstzwBZF9BuRbLQ4Pt891WNiGHKTqomf1n2tc1UJSrJjEepMrA5pueHnkN8Tqn9zGl8Q eBdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=cUIgnP1rbOkd4juPUk79nHzhJJsq6HuglK7+QWrIYBk=; b=MVVY5bgnuvLd5ojc8lmZHrGxlGUouuG516UUJxsvUxwjB2JNjY07C2xEzWx/dtMQ7n NPw02x4Z21egNnn2Esjszx++DZPnJoRiK7n3Y8L0T/aa3ZXz2MpNVrpTszWinKNUBrzI Zv9mstEgclEPDsQR3A9APd7W9FOEB9JUidqOPAb9hrxHawT3mBqFfLPzqLcqlqwBJGcs NJpa5U4csjWd08qQH5id4PHl2VtXWUUC70yUuT934Ytrxtm1A/stzF+BDm/TqxySB0/7 NYTjj+b7wUKxm4Ve/iT6YZaDbHdxBrdzaNvVoR8Al/S6moL6syRhrWEbKFY80Fudxrnh t7Aw== X-Gm-Message-State: ALKqPwc0d/dCy4lMQ++iiT6vvgGIfSLoZbDhiLF7+NB/mEKjrsI5UcGg NCNecq5C2oyyzyEaYZksOSVx1/yN7ocoyonU4I4= X-Received: by 2002:a9d:5990:: with SMTP id u16-v6mr10626792oth.370.1526404781481; Tue, 15 May 2018 10:19:41 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:1468:0:0:0:0:0 with HTTP; Tue, 15 May 2018 10:19:41 -0700 (PDT) In-Reply-To: <20180501003907.4322-3-ahs3@redhat.com> References: <20180501003907.4322-1-ahs3@redhat.com> <20180501003907.4322-3-ahs3@redhat.com> From: "Rafael J. Wysocki" Date: Tue, 15 May 2018 19:19:41 +0200 X-Google-Sender-Auth: 1fk48B1LtAFEEiHvrPjZwMwX_jk Message-ID: Subject: Re: [PATCH v3 2/3] ACPI: ensure acpi_parse_entries_array() does not access non-existent table data To: Al Stone Cc: ACPI Devel Maling List , Linux Kernel Mailing List , "Rafael J . Wysocki" , Len Brown Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 1, 2018 at 2:39 AM, Al Stone wrote: > 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 4a3410aa6540..82c3e2c52dd9 100644 > --- a/drivers/acpi/tables.c > +++ b/drivers/acpi/tables.c > @@ -274,8 +274,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; > > -- This breaks the CPU enumeration on my Dell XPS13 9360 (possibly among other things), so I'm dropping it. I can send you acpidump output from that machine if need be. Thanks, Rafael