Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp267280pxb; Thu, 31 Mar 2022 05:07:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzy96MgegwN4kBdg7dzZpYXTdwTd7fWMtpYQ2dinaQ+M0vFEzU2bCjUUY9HMsiEdlEWqicZ X-Received: by 2002:aa7:d947:0:b0:419:3e8d:3e37 with SMTP id l7-20020aa7d947000000b004193e8d3e37mr16097252eds.247.1648728446932; Thu, 31 Mar 2022 05:07:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648728446; cv=none; d=google.com; s=arc-20160816; b=fsDMCKLJ24FSD0uH8vPbZ621GLRI8DX7j30PYGP5sFSPQ+mvI9wE1wy1yJdyRb+iYF eYOrlJB/UzSwjx6oIBcBYpY1sIGNSZpePpvjNKQCIwSEe5h+EhC85iGWhREUtk3Z9a/s /3DidEG6xIC1tchxBUGI8JwvTQ6Um4A2MPZ1VKeRWZ7sJpk3bKhrX2urHv5pejvPaYtO TvRbNPc8gvSpG7mkIWYyvusq3XwZZAt/QUW6cTWRBK3wft6O/Jm5MdzVJ0qpWVduMiTg N+GIunWQJkQoHnixUw/PvI+RpaZdTDwPInKfP8QMw64dNwPUeW9ELHrTvoAaMa10BilP /Izw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date; bh=H2CXdrtewnw1PeYticAR4hcQS8qOqbwJeDd1rSes8HY=; b=NRE4+wjc0qJSyO9JxdUr8l77wZtnV8Ww3fR094mQUPbXK7S7mNT8Z06Q6AicC7UUIn ctLs0PzBtniykL63SxqNm3jVhLAjyWVk7+5DUl5uHhDlW1XsrQNaDYbGimR/XmpvHPew Vsn+w4TqIvCa8IThuoVJBmmE2ljE9L28FvM0GAKN1qnptYp1gXFkLdtD6tUVyNB2OlSh DnRnGfBdgxBqtFBMXzap1h+yT7iJwG/b1u4TMcpfJ+sQK8n3pCSTLenXrpBSaqSxX56L /D1T7fGgIxbOlkm3jp88gj5RGMF7uz/9m9xr/YebY6MlvbuejUISQpMDxiCZZ+FdChdX NWXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i26-20020a17090671da00b006df76385e94si22482921ejk.820.2022.03.31.05.06.59; Thu, 31 Mar 2022 05:07:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231826AbiCaHNU (ORCPT + 99 others); Thu, 31 Mar 2022 03:13:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231945AbiCaHM4 (ORCPT ); Thu, 31 Mar 2022 03:12:56 -0400 Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4F4CEC624F; Thu, 31 Mar 2022 00:10:56 -0700 (PDT) Received: by angie.orcam.me.uk (Postfix, from userid 500) id 091BD92009D; Thu, 31 Mar 2022 09:10:56 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 01B0B92009B; Thu, 31 Mar 2022 08:10:55 +0100 (BST) Date: Thu, 31 Mar 2022 08:10:55 +0100 (BST) From: "Maciej W. Rozycki" To: Bjorn Helgaas , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" cc: Arnd Bergmann , Nikolai Zhubr , Michal Necasek , Dmitry Osipenko , Linus Torvalds , x86@kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/5] x86/PCI: Add PIRQ routing table range checks In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Verify that the PCI IRQ Routing Table header as well as individual slot entries are all wholly contained within the BIOS memory area. Do not even call the checksum calculator if the header would overrun the area and then bail out early if any slot would. Signed-off-by: Maciej W. Rozycki --- New change in v4. --- arch/x86/pci/irq.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) linux-x86-pirq-range-check.diff Index: linux-macro/arch/x86/pci/irq.c =================================================================== --- linux-macro.orig/arch/x86/pci/irq.c +++ linux-macro/arch/x86/pci/irq.c @@ -68,7 +68,8 @@ void (*pcibios_disable_irq)(struct pci_d * and perform checksum verification. */ -static inline struct irq_routing_table *pirq_check_routing_table(u8 *addr) +static inline struct irq_routing_table *pirq_check_routing_table(u8 *addr, + u8 *limit) { struct irq_routing_table *rt; int i; @@ -78,7 +79,8 @@ static inline struct irq_routing_table * if (rt->signature != PIRQ_SIGNATURE || rt->version != PIRQ_VERSION || rt->size % 16 || - rt->size < sizeof(struct irq_routing_table)) + rt->size < sizeof(struct irq_routing_table) || + (limit && rt->size > limit - addr)) return NULL; sum = 0; for (i = 0; i < rt->size; i++) @@ -99,17 +101,22 @@ static inline struct irq_routing_table * static struct irq_routing_table * __init pirq_find_routing_table(void) { + u8 * const bios_start = (u8 *)__va(0xf0000); + u8 * const bios_end = (u8 *)__va(0x100000); u8 *addr; struct irq_routing_table *rt; if (pirq_table_addr) { - rt = pirq_check_routing_table((u8 *) __va(pirq_table_addr)); + rt = pirq_check_routing_table((u8 *)__va(pirq_table_addr), + NULL); if (rt) return rt; printk(KERN_WARNING "PCI: PIRQ table NOT found at pirqaddr\n"); } - for (addr = (u8 *) __va(0xf0000); addr < (u8 *) __va(0x100000); addr += 16) { - rt = pirq_check_routing_table(addr); + for (addr = bios_start; + addr < bios_end - sizeof(struct irq_routing_table); + addr += 16) { + rt = pirq_check_routing_table(addr, bios_end); if (rt) return rt; }