From patchwork Wed Sep 16 12:58:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 53734 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 26FE922A0D for ; Wed, 16 Sep 2015 12:58:25 +0000 (UTC) Received: by lamp12 with SMTP id p12sf72726917lam.2 for ; Wed, 16 Sep 2015 05:58:24 -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=SVF7hsIqlqlDXjdibNtQbLmxme16ebgPjpUAoFEtkec=; b=SPaxtG4kKxgwL8pEHebMtYiUBnhfGVfMThl96b6Cfa96O9vy3xjztgZRLV7J8qJD7D lnUmqW11IhikukSRmUieeJyd1W/aV64qh7PpQjf9a9OEAvm9Rp3bDtP35cqi5qZrsZBr wCK+L0Orig4/zCLa334WBOJXvw23hAofYBSyt6qvVvUNS9+5FMNLE2qC88D9Gf+iGv5i +iTruI5ECSSq1xsj0/cXX8MydMcscX5hyd2wxW89hKB0XAg2tXzohvfkQMnsxslFcsQ6 DXIiRs3ZIFR058wQxiomZ4qopAFIcYDsbw4ZyBjsDJ4GcBMfIISal0hHAFlwmgd43mCS R6eA== X-Gm-Message-State: ALoCoQkq6NfIdS6x6ASHp3cJ5075kTW+XgOHXvmn43JN6/iDAyvrPU0CFgC38RA9nIUXK4fh2iYA X-Received: by 10.194.109.233 with SMTP id hv9mr3746212wjb.1.1442408303970; Wed, 16 Sep 2015 05:58:23 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.22.137 with SMTP id d9ls985702laf.42.gmail; Wed, 16 Sep 2015 05:58:23 -0700 (PDT) X-Received: by 10.112.234.199 with SMTP id ug7mr29174699lbc.116.1442408303761; Wed, 16 Sep 2015 05:58:23 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id h9si18115712lab.169.2015.09.16.05.58.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Sep 2015 05:58:23 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by lamp12 with SMTP id p12so127029948lam.0 for ; Wed, 16 Sep 2015 05:58:23 -0700 (PDT) X-Received: by 10.152.18.130 with SMTP id w2mr19589356lad.88.1442408303549; Wed, 16 Sep 2015 05:58:23 -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 w3csp2436847lbq; Wed, 16 Sep 2015 05:58:22 -0700 (PDT) X-Received: by 10.50.142.69 with SMTP id ru5mr15079733igb.1.1442408302243; Wed, 16 Sep 2015 05:58:22 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10si17281159ioe.173.2015.09.16.05.58.21; Wed, 16 Sep 2015 05:58:22 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753434AbbIPM6S (ORCPT + 29 others); Wed, 16 Sep 2015 08:58:18 -0400 Received: from foss.arm.com ([217.140.101.70]:55258 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752226AbbIPM6P (ORCPT ); Wed, 16 Sep 2015 08:58:15 -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 DCE0D56C; Wed, 16 Sep 2015 05:58:30 -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 D1C823F57E; Wed, 16 Sep 2015 05:58:13 -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 v2 1/2] ACPI / tables: simplify acpi_parse_entries Date: Wed, 16 Sep 2015 13:58:06 +0100 Message-Id: <1442408287-10410-1-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1442243686-15845-1-git-send-email-sudeep.holla@arm.com> References: <1442243686-15845-1-git-send-email-sudeep.holla@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@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.215.47 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(-) Hi Rafael, As I mentioned earlier, this needs to be applied after Al's MADT changes are merged. You might get simple conflicts in acpi_parse_entries. Regards, Sudeep v1->v2: - Incorporated Rafael's review comments - Moved zero length entry check early - Added a patch to remove the unused table_end parameter -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index d0716bb6359d..69b9d05f5b96 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -459,7 +459,7 @@ acpi_parse_entries(char *id, unsigned long table_size, { struct acpi_subtable_header *entry; int count = 0; - unsigned long table_end; + unsigned long table_end, entry_end; if (acpi_disabled) return -ENODEV; @@ -478,12 +478,20 @@ acpi_parse_entries(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, entry_id); + return -EINVAL; + } - while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) < - table_end) { if (entry->type == entry_id && (!max_entries || count < max_entries)) { if (!strncmp(id, ACPI_SIG_MADT, 4) && @@ -495,17 +503,8 @@ acpi_parse_entries(char *id, unsigned long table_size, 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, entry_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) {