Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2249847yba; Mon, 15 Apr 2019 07:57:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9r+06GztYmPcMJtxdY115NbDNNk0fbD7aM4wl1zLN1VzFe2tY74DuNy/mDbvBAC3r3+rj X-Received: by 2002:a63:575e:: with SMTP id h30mr9785604pgm.54.1555340267343; Mon, 15 Apr 2019 07:57:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555340267; cv=none; d=google.com; s=arc-20160816; b=wQOygMbsI+6FOMAKOLiVPBZTFXoK2MlxPUm58SZ0Bm2XSGNKV2f0Qu6SzMusVo2KIu OElsMd5LNeYePe82nP9RJlnwAs39S5DZoKkXue3RUb1UAxF0iuEs4kW1hMHHZMogyhmc p2A9lwvdAkzIawNrVcRNA80LVGar7v7KscCOdDzetyN2dMKPP3wIjUNp97xRlNiDToa1 RCYYxZkmA//oW9f3jURGY/KWIt3SmWFYZH9VVyxQsU/55ENQoUZ6/zP0aUOEYw1rQ4pc jXt2KC2lgPnEDcRbrts6iMAfg28SuJwhmbf47EAAXN2mCfIGJmofGyYUVZaspwfwypC7 cIcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=OVfJ2iOS0oUQifj2xXtFvPtDE+Eag0qBqDFOQ3KG+Ek=; b=GPxWs8tFg+OJY+1qd3bGYjvSk55tRPebLMgSvZQqQSfrQtS53HE+6AIxkPd7vxqxQu kj8yzCd70Z/V1mutlinHBmKJMQ6jOOJistGlegg99gSrRkzlZsUL5VfyLfJ3ZWslSop5 Tzs1Ots3W3JBao5TvwggaMaCqym2QFvIlmTyOxmZwZOIVHXCsSITvHePMiBWhbskxMfG 0nsuOukWLVrl3L6vrLaFQMQxCuPylULpMLmeI9WlfjROGfmceK4KtJjYlkdRCskwxjff MMdOrqb5y0Yv8VwU3WuSR0pDMaN6EJyaT+DE3rnHjIsbNLnmEVJSEhkBanqOWRlfy8eE lpDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=V9nQ2s4V; 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=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z2si43422974pgu.437.2019.04.15.07.57.31; Mon, 15 Apr 2019 07:57:47 -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=pass header.i=@umn.edu header.s=google header.b=V9nQ2s4V; 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=pass (p=NONE sp=NONE dis=NONE) header.from=umn.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727825AbfDOO4X (ORCPT + 99 others); Mon, 15 Apr 2019 10:56:23 -0400 Received: from mta-p6.oit.umn.edu ([134.84.196.206]:50726 "EHLO mta-p6.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727608AbfDOO4V (ORCPT ); Mon, 15 Apr 2019 10:56:21 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-p6.oit.umn.edu (Postfix) with ESMTP id 079DACCA for ; Mon, 15 Apr 2019 14:56:20 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p6.oit.umn.edu ([127.0.0.1]) by localhost (mta-p6.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rf3ajMPaPMuo for ; Mon, 15 Apr 2019 09:56:19 -0500 (CDT) Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p6.oit.umn.edu (Postfix) with ESMTPS id C5095B96 for ; Mon, 15 Apr 2019 09:56:03 -0500 (CDT) Received: by mail-io1-f69.google.com with SMTP id b16so14284218iot.5 for ; Mon, 15 Apr 2019 07:56:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id; bh=OVfJ2iOS0oUQifj2xXtFvPtDE+Eag0qBqDFOQ3KG+Ek=; b=V9nQ2s4VSxnEmO050wxtdc0l7cLsNcGgJ0MhWXm/QdX5vWwRYNxg2GTq9q6VbmMdec x3pmUeywriHgPtA0mlxrPmfoJhfuaIiPwABHiHD/hPEQH5wLrCPIhbDr2czJRXHiGDNO zN3tSEom8038DOpOXQeGcHSAQNksqo19VO9FzPvPKx3tZXAedHa9wgYccq+0h248JqlD WP/UtUPbfi9UwkcLotvaOj8sM3OHJeelmfdSqIn2LOd1MzupOcBhVJ4gwUJZTGZJZ9jS fLXoWIFhX00BJ0zr7mI07OJf3ansghuofju8h4elk1xuCNHGRJS0pWZSALbmyRa3vRhN WIjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=OVfJ2iOS0oUQifj2xXtFvPtDE+Eag0qBqDFOQ3KG+Ek=; b=Fl35NGRqtVefvtAO1jcnY7yk5oEStGUs9Esw05Cm4ZRCrJzNwNYuDyTG+61Bt80jMU yaNlM+87Dnan8za1C+rzmizgKUsnK3tS0XsSpgstWnurDf655plYehVmYLBXaaRBrZpE mf9mL1EpQs+eTmUbBia8+JZMTjEk40yb1aPzTXmVNUXUk1nyvoBg6SWz3UaGt8QZK1Be ITBV4DS1yhhPqWYfC6eTDMdfZtaPms8ZBYh9Pw6kMCPxknLKyhSi7xYIUsF6G6nPrl39 wmUGDiqFKk/VOOPEmH86BBFVuzn2ltZgGPZhzq6lMB9Pa8jm06srOrISmI9pK+cg3DNX uHhQ== X-Gm-Message-State: APjAAAVQMxazEXpq34hSSKtd6hnKvI/tBsuBx19HlWLcwAfuSRk+QGXX NOdD84A4zrdcokzoAwE/1/MX0QdWbbitP+z0izlEjRa2TfDWpc75GeILNAX48KP22HXfEB93RCH XhQudAr5GC0FM7Bs3cAj9CS4Cnh5W X-Received: by 2002:a24:9414:: with SMTP id j20mr11773537ite.91.1555340163517; Mon, 15 Apr 2019 07:56:03 -0700 (PDT) X-Received: by 2002:a24:9414:: with SMTP id j20mr11773526ite.91.1555340163359; Mon, 15 Apr 2019 07:56:03 -0700 (PDT) Received: from cs-u-cslp16.dtc.umn.edu (cs-u-cslp16.cs.umn.edu. [128.101.106.40]) by smtp.gmail.com with ESMTPSA id a16sm8085709itc.36.2019.04.15.07.56.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Apr 2019 07:56:02 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Bjorn Helgaas , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-pci@vger.kernel.org (open list:PCI SUBSYSTEM), linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)) Subject: [PATCH] x86/PCI: fix a memory leak bug Date: Mon, 15 Apr 2019 09:54:18 -0500 Message-Id: <1555340058-3065-1-git-send-email-wang6495@umn.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In pcibios_irq_init(), the PCI IRQ routing table 'pirq_table' is firstly found through pirq_find_routing_table(). If the table is not found and 'CONFIG_PCI_BIOS' is defined, the table is then allocated in pcibios_get_irq_routing_table() using kmalloc(). In the following execution, if the I/O APIC is used, this table is actually not used. However, in that case, the allocated table is not freed, which can lead to a memory leak bug. To fix this issue, this patch frees the allocated table if it is not used. Signed-off-by: Wenwen Wang --- arch/x86/pci/irq.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c index 52e5510..d9bcb96 100644 --- a/arch/x86/pci/irq.c +++ b/arch/x86/pci/irq.c @@ -1119,6 +1119,8 @@ static const struct dmi_system_id pciirq_dmi_table[] __initconst = { void __init pcibios_irq_init(void) { + struct irq_routing_table *itable = NULL; + DBG(KERN_DEBUG "PCI: IRQ init\n"); if (raw_pci_ops == NULL) @@ -1129,8 +1131,10 @@ void __init pcibios_irq_init(void) pirq_table = pirq_find_routing_table(); #ifdef CONFIG_PCI_BIOS - if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN)) + if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN)) { pirq_table = pcibios_get_irq_routing_table(); + itable = pirq_table; + } #endif if (pirq_table) { pirq_peer_trick(); @@ -1145,8 +1149,10 @@ void __init pcibios_irq_init(void) * If we're using the I/O APIC, avoid using the PCI IRQ * routing table */ - if (io_apic_assign_pci_irqs) + if (io_apic_assign_pci_irqs) { + kfree(itable); pirq_table = NULL; + } } x86_init.pci.fixup_irqs(); -- 2.7.4