From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6FF0C4360F for ; Tue, 26 Mar 2019 13:01:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AF2D12070B for ; Tue, 26 Mar 2019 13:01:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731489AbfCZNBO (ORCPT ); Tue, 26 Mar 2019 09:01:14 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:35996 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726177AbfCZNBO (ORCPT ); Tue, 26 Mar 2019 09:01:14 -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 6D6A11596; Tue, 26 Mar 2019 06:01:13 -0700 (PDT) Received: from [10.1.196.75] (e110467-lin.cambridge.arm.com [10.1.196.75]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0B4693F59C; Tue, 26 Mar 2019 06:01:11 -0700 (PDT) Subject: Re: [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages To: Aditya Pakki Cc: Lorenzo Pieralisi , linux-pci@vger.kernel.org, kjlu@umn.edu, Michal Simek , linux-kernel@vger.kernel.org, Bjorn Helgaas , linux-arm-kernel@lists.infradead.org References: <20190323210423.8881-1-pakki001@umn.edu> From: Robin Murphy Message-ID: Date: Tue, 26 Mar 2019 13:01:10 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <20190323210423.8881-1-pakki001@umn.edu> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/03/2019 21:04, Aditya Pakki wrote: > In case __get_free_pages fail, the fix returns error upstream > to avoid NULL pointer dereference. Where does msi_pages ever get dereferenced? The logic here might actually still have a chance of working out OK with NULL depending on how the memory maps line up, but even if it doesn't, the problem is certainly not one of dereferencing. Robin. > Signed-off-by: Aditya Pakki > > --- > v1: Return error upstream as suggested by Steven > --- > drivers/pci/controller/pcie-xilinx.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c > index 9bd1a35cd5d8..91d8945bfb0c 100644 > --- a/drivers/pci/controller/pcie-xilinx.c > +++ b/drivers/pci/controller/pcie-xilinx.c > @@ -335,15 +335,19 @@ static const struct irq_domain_ops msi_domain_ops = { > /** > * xilinx_pcie_enable_msi - Enable MSI support > * @port: PCIe port information > + * Return: 0 on success, negative error on failure > */ > -static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port) > +static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port) > { > phys_addr_t msg_addr; > > port->msi_pages = __get_free_pages(GFP_KERNEL, 0); > + if (!port->msi_pages) > + return -ENOMEM; > msg_addr = virt_to_phys((void *)port->msi_pages); > pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1); > pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2); > + return 0; > } > > /* INTx Functions */ > @@ -498,6 +502,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port) > struct device *dev = port->dev; > struct device_node *node = dev->of_node; > struct device_node *pcie_intc_node; > + int ret; > > /* Setup INTx */ > pcie_intc_node = of_get_next_child(node, NULL); > @@ -526,7 +531,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port) > return -ENODEV; > } > > - xilinx_pcie_enable_msi(port); > + ret = xilinx_pcie_enable_msi(port); > + if (ret) > + return ret; > } > > return 0; > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5F2EC43381 for ; Tue, 26 Mar 2019 13:01:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 747A12070B for ; Tue, 26 Mar 2019 13:01:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="S7aoxCnT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 747A12070B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=b1si3UkyBgDmxsuVxgyRPqNoHCvWk1m01pgYNEOpuAI=; b=S7aoxCnTjxmtWa+XFTSPLA6YY JAzxiPPCUUpZpo+c5+aSp0Ltl95Yw+vovvESYGsOzDBkPCYCfrvRYAY4T9ggpimhN6OIBnssGsliT uv9JNMvNb3oyYlmScL+Q4DeQSCQ39L1enTIz7ySsRhLwNl4xkM9bqU9jAimIijS/RsJJmqsSNGC9H 4BxhYnqkuxHez4acp4fHBlFh1N17Azi3/xEPQoMHGGR2Cy8cmZAO+vFzHF6IRIBgOAut3Kyg4tQ3O F1I/nuPlE9IiwdV/PY7JAiLwhdHCbipJnclQ1FId9OhV1gdzvftaRjCSX0+gysKANDJANLNe6LAoJ R/W+SzrDw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8lhp-0000Vj-Vw; Tue, 26 Mar 2019 13:01:29 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8lhk-0000UV-7o for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2019 13:01:28 +0000 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 6D6A11596; Tue, 26 Mar 2019 06:01:13 -0700 (PDT) Received: from [10.1.196.75] (e110467-lin.cambridge.arm.com [10.1.196.75]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0B4693F59C; Tue, 26 Mar 2019 06:01:11 -0700 (PDT) Subject: Re: [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages To: Aditya Pakki References: <20190323210423.8881-1-pakki001@umn.edu> From: Robin Murphy Message-ID: Date: Tue, 26 Mar 2019 13:01:10 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <20190323210423.8881-1-pakki001@umn.edu> Content-Language: en-GB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_060124_292859_60722F57 X-CRM114-Status: GOOD ( 20.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lorenzo Pieralisi , linux-pci@vger.kernel.org, kjlu@umn.edu, Michal Simek , linux-kernel@vger.kernel.org, Bjorn Helgaas , linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 23/03/2019 21:04, Aditya Pakki wrote: > In case __get_free_pages fail, the fix returns error upstream > to avoid NULL pointer dereference. Where does msi_pages ever get dereferenced? The logic here might actually still have a chance of working out OK with NULL depending on how the memory maps line up, but even if it doesn't, the problem is certainly not one of dereferencing. Robin. > Signed-off-by: Aditya Pakki > > --- > v1: Return error upstream as suggested by Steven > --- > drivers/pci/controller/pcie-xilinx.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c > index 9bd1a35cd5d8..91d8945bfb0c 100644 > --- a/drivers/pci/controller/pcie-xilinx.c > +++ b/drivers/pci/controller/pcie-xilinx.c > @@ -335,15 +335,19 @@ static const struct irq_domain_ops msi_domain_ops = { > /** > * xilinx_pcie_enable_msi - Enable MSI support > * @port: PCIe port information > + * Return: 0 on success, negative error on failure > */ > -static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port) > +static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port) > { > phys_addr_t msg_addr; > > port->msi_pages = __get_free_pages(GFP_KERNEL, 0); > + if (!port->msi_pages) > + return -ENOMEM; > msg_addr = virt_to_phys((void *)port->msi_pages); > pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1); > pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2); > + return 0; > } > > /* INTx Functions */ > @@ -498,6 +502,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port) > struct device *dev = port->dev; > struct device_node *node = dev->of_node; > struct device_node *pcie_intc_node; > + int ret; > > /* Setup INTx */ > pcie_intc_node = of_get_next_child(node, NULL); > @@ -526,7 +531,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port) > return -ENODEV; > } > > - xilinx_pcie_enable_msi(port); > + ret = xilinx_pcie_enable_msi(port); > + if (ret) > + return ret; > } > > return 0; > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel