Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3217182yba; Tue, 16 Apr 2019 07:05:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKQHuYn38LavX7lc84CIZuviHq8+wzptpvts3PGLB+GfMqx3EV8ul9hsWZC6/ufD2+8NK7 X-Received: by 2002:a62:209c:: with SMTP id m28mr80934281pfj.233.1555423534040; Tue, 16 Apr 2019 07:05:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555423534; cv=none; d=google.com; s=arc-20160816; b=ioT2lUmK8N6dxw3NGpYPFcmjxgHBI3qT5jE5/D+pBNre8E00CamQycbgExV1lqzFbT jRR51J5EOnXmkW0CW1wnhQ7LtFZlFW6pLeQGNDylLmT1p4qL6Mh7FQoFEhcZX5vHepaM 4mUhruhJs25YdrHV43zpml+UxNwkOh+kivwhHcq92zY1jqK/1cLC532+2uKFr8lkQCUu Vjo46ELYtYDGO6k3MLCVttTFG5x2XmgX8/trq/FODr1twsm37X1PImsnh3rD3WFUNH4P OHEJPD52Sz3qHwegYEldWLg7LsYTomPpZJ6OD4407jCByJ3yktcHSsX1M5JZ3mdQc6nQ yJBQ== 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=iwjMijP3+qu6tm9Ocaym7EnWSSoP8/7s8H9M+zp/o04=; b=GNEjXPvNVX1uwGrTuktfIyjQvnKdZwUj3lhL1kLDTcPBkIFX9DQMyH6IYG+675ROJ3 UDiSE+fcQ+nDoiTpDvtBbtHF2ARVEWb0mfqxY5EpF9UbQzJBs/iK7kPJVZW53xMc9M2o gv0exD/kOZeaWTC4xvSzkl6vsYgN4dTaGr2czXyTL8wn2TA8GCUbwMc1y5PocxXP0tuj VNeOpf0022NBkk79iy1nHLpjlp107SNPQeTj9bw80YArqIXqtar00a97kHIYx9rdTHzB xqwyP1qyezL4AaJ1pPERPdVFC7SlXH7T0N+9vAIaIYAp7BnxWt4Y3muwOiyX1Z/h0G58 RqMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umn.edu header.s=google header.b=pH4l246J; 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 t22si47640136plo.74.2019.04.16.07.05.17; Tue, 16 Apr 2019 07:05: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=pass header.i=@umn.edu header.s=google header.b=pH4l246J; 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 S1726500AbfDPOCB (ORCPT + 99 others); Tue, 16 Apr 2019 10:02:01 -0400 Received: from mta-p6.oit.umn.edu ([134.84.196.206]:47830 "EHLO mta-p6.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725981AbfDPOCB (ORCPT ); Tue, 16 Apr 2019 10:02:01 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-p6.oit.umn.edu (Postfix) with ESMTP id 91AF3C2E for ; Tue, 16 Apr 2019 14:01:59 +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 Er-uHCAYC37z for ; Tue, 16 Apr 2019 09:01:59 -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 67486A99 for ; Tue, 16 Apr 2019 09:01:59 -0500 (CDT) Received: by mail-io1-f69.google.com with SMTP id y18so16621034ior.18 for ; Tue, 16 Apr 2019 07:01:59 -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=iwjMijP3+qu6tm9Ocaym7EnWSSoP8/7s8H9M+zp/o04=; b=pH4l246JQa7gqqHTnkvh/2qqqxnoKjbpdrSf7IcXCYV5RfBTK2/o/oB32m/e7Mhamb RKzevpkRs+mKB11gq4VNFtfQNiteam507U6Q3vYPveE0301V5O4w79/fAWaXtEODsMcO 5G3s1FFyhWFoB9jz5w0iRBuGdL0JRT1kWxT4J8Tou53UmCR48Yj3bIjepRbmd6BuH0J6 QChDp0cYmzKyXeBOXk2magzcfnXeJIssCtUVgcMouF3iNUQgfqgTOM/bdg+uVqrkpUAy dM3avtUc2iOWAhO2gm7nvmvmak+LG7gKt20kGd5qjxDynZsDorvoXg57dFzSNh8A4o2T nyQg== 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=iwjMijP3+qu6tm9Ocaym7EnWSSoP8/7s8H9M+zp/o04=; b=n2SYKVxRXP8jVpZryaKz68Ss2D9Otp1ievD3eWsTFqJC/4H5R5kMGd7wSVVPiD+d5q e46rl/dH3lZ4cWDwx75KKkvZJpCLcQLlDPt+o4tWXGocOLRK+dA7boWDjeHFdCz6Fso5 WrcXs03GSlUFazP2FYvXCfM43OQzeuormOC3+U8Ih3Aeqj/nC0kLt3cvmkImDYJtN/i3 YA2oiX8XJAyRpV9MeYdNzL3b6aX4HzyZks0o4SC+64A/1yuU/uAnJ1jPsbwM8+ZGuyaF XsG82dTc9LvDdjDcdK8xNAGE5/t9NNsASp2KTVYeB+RygBybCoFTiqc4XyufCzzfJCUS t7Pw== X-Gm-Message-State: APjAAAUHs2owk3duTodb+f+WSi0U+0K/+e8H/AmXNV4sSHwhjtjzflZw JgYwRfxEAqOWhTQikhGcluBGE4hOKq8tlafpJ1dcHBjQPwoUyDtdQpS2t4jMOCk8IgzwyMGoIzW 7gP9CDepPNBMeoG2fRyP9b0kU3Osf X-Received: by 2002:a24:d643:: with SMTP id o64mr29154579itg.148.1555423318965; Tue, 16 Apr 2019 07:01:58 -0700 (PDT) X-Received: by 2002:a24:d643:: with SMTP id o64mr29154491itg.148.1555423318246; Tue, 16 Apr 2019 07:01:58 -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 m6sm19496152ioj.36.2019.04.16.07.01.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Apr 2019 07:01:57 -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 v2] x86/PCI: fix a memory leak bug Date: Tue, 16 Apr 2019 09:01:38 -0500 Message-Id: <1555423298-6677-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..d3a73f9 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 *rtable = 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(); + rtable = 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(rtable); pirq_table = NULL; + } } x86_init.pci.fixup_irqs(); -- 2.7.4