From patchwork Thu Oct 1 15:11:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 54372 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by patches.linaro.org (Postfix) with ESMTPS id CC99B23009 for ; Thu, 1 Oct 2015 15:12:13 +0000 (UTC) Received: by laer8 with SMTP id r8sf37880025lae.2 for ; Thu, 01 Oct 2015 08:12:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=GZ6sJvVy3ULaJDWw5uVA8QAWDJ3X9uS3Cgr7EtxNshI=; b=Rf+YLRdh60puGgfH2CHJxsMKYz+4cfzE0TAESLfKCmnuAPdZz43b9bRC6mex+zIBCL wweJ7kx++GEEOKcTyjv8FUmvwBeVRTNCZ/J938N5YBcQ921LTENzD0/1Gj7pQ9W0U8s2 vA7eDdtxDQbxc6yHHQEsVbEz0CZSqL7qv49IGo/CYj03wBbAgbYUujqOsbqS6c7kyLuF 2JI94+PUxHPhvkaBz3mhcN5c7vb9iFLTCWG7YF7KeJjl0cVQdf+ceHGRRYgt4ZqzuqtW esR1eAIqsLG0V1VASHOQktEYrcQFKNDGuWQccKUXSFXp5jfvExvaPIfk/CLYrifUmrWN yK4Q== X-Gm-Message-State: ALoCoQlm7hwRgVEoXAAxnZU6N74L9jwdGWC1wcY0cfZ851e9Aux85IAFmEc8rK5yFIbe+mx/Z/H6 X-Received: by 10.180.9.104 with SMTP id y8mr576033wia.7.1443712331741; Thu, 01 Oct 2015 08:12:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.79.85 with SMTP id d82ls98990lfb.47.gmail; Thu, 01 Oct 2015 08:12:11 -0700 (PDT) X-Received: by 10.25.80.77 with SMTP id e74mr2042916lfb.11.1443712331462; Thu, 01 Oct 2015 08:12:11 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id jk3si3061363lbc.29.2015.10.01.08.12.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Oct 2015 08:12:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbos8 with SMTP id s8so11159097lbo.0 for ; Thu, 01 Oct 2015 08:12:11 -0700 (PDT) X-Received: by 10.25.211.201 with SMTP id k192mr2105520lfg.32.1443712330770; Thu, 01 Oct 2015 08:12:10 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp671559lbq; Thu, 1 Oct 2015 08:12:08 -0700 (PDT) X-Received: by 10.50.67.179 with SMTP id o19mr3738049igt.63.1443712328593; Thu, 01 Oct 2015 08:12:08 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x75si5226904ioi.11.2015.10.01.08.12.08; Thu, 01 Oct 2015 08:12:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752800AbbJAPMG (ORCPT + 6 others); Thu, 1 Oct 2015 11:12:06 -0400 Received: from foss.arm.com ([217.140.101.70]:36591 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751194AbbJAPME (ORCPT ); Thu, 1 Oct 2015 11:12:04 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5E2EF49; Thu, 1 Oct 2015 08:12:06 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.207.150]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 68EA93F50D; Thu, 1 Oct 2015 08:12:01 -0700 (PDT) From: Sudeep Holla To: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" Cc: Sudeep Holla , Al Stone , Lorenzo Pieralisi Subject: [PATCH v3 1/2] ACPI / tables: simplify acpi_parse_entries Date: Thu, 1 Oct 2015 16:11:51 +0100 Message-Id: <1443712312-9176-1-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1442408287-10410-1-git-send-email-sudeep.holla@arm.com> References: <1442408287-10410-1-git-send-email-sudeep.holla@arm.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: sudeep.holla@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , acpi_parse_entries passes the table end pointer to the sub-table entry handler. acpi_parse_entries itself could validate the end of an entry against the table end using the length in the sub-table entry. This patch adds the validation of the sub-table entry end using the length field.This will help to eliminate the need to pass the table end to the handlers. It also moves the check for zero length entry early so that execution of the handler can be avoided. Cc: "Rafael J. Wysocki" Signed-off-by: Sudeep Holla --- drivers/acpi/tables.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) v2->v3: - Rebased on Rafael's linux-pm/bleeding-edge branch to avoid conflicts v1->v2: - Incorporated Rafael's review comments - Moved zero length entry check early - Added a patch to remove the unused table_end parameter diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index a2ed38a20e7e..24b867e26191 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -476,7 +476,7 @@ acpi_parse_entries_array(char *id, unsigned long table_size, unsigned int max_entries) { struct acpi_subtable_header *entry; - unsigned long table_end; + unsigned long table_end, entry_end; int count = 0; int i; @@ -497,12 +497,20 @@ acpi_parse_entries_array(char *id, unsigned long table_size, table_end = (unsigned long)table_header + table_header->length; /* Parse all entries looking for a match. */ + entry_end = (unsigned long)table_header + table_size; + entry = (struct acpi_subtable_header *)entry_end; + entry_end += entry->length; - entry = (struct acpi_subtable_header *) - ((unsigned long)table_header + table_size); + while (entry_end <= table_end) { + /* + * If entry->length is 0, break from this loop to avoid + * infinite loop. + */ + if (entry->length == 0) { + pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, proc->id); + return -EINVAL; + } - while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) < - table_end) { if (max_entries && count >= max_entries) break; @@ -523,17 +531,8 @@ acpi_parse_entries_array(char *id, unsigned long table_size, if (i != proc_num) count++; - /* - * If entry->length is 0, break from this loop to avoid - * infinite loop. - */ - if (entry->length == 0) { - pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, proc->id); - return -EINVAL; - } - - entry = (struct acpi_subtable_header *) - ((unsigned long)entry + entry->length); + entry = (struct acpi_subtable_header *)entry_end; + entry_end += entry->length; } if (max_entries && count > max_entries) {