lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20200729175957.011642f1@xhacker.debian>
Date:   Wed, 29 Jul 2020 18:02:46 +0800
From:   Jisheng Zhang <Jisheng.Zhang@...aptics.com>
To:     Lu Wei <luwei32@...wei.com>
Cc:     <ulli.kroll@...glemail.com>, <linus.walleij@...aro.org>,
        <davem@...emloft.net>, <kuba@...nel.org>,
        <mirq-linux@...e.qmqm.pl>, <linux-arm-kernel@...ts.infradead.org>,
        <netdev@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] net: ethernet: fix potential memory leak in
 gemini_ethernet_port_probe()

On Wed, 29 Jul 2020 11:46:06 +0800 Lu Wei wrote:


> 
> 
> If some processes in gemini_ethernet_port_probe() fail,
> free_netdev(dev) needs to be called to avoid a memory leak.

Using devm_alloc_etherdev_mqs() would be much simpler

> 
> Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet")
> Reported-by: Hulk Robot <hulkci@...wei.com>
> Signed-off-by: Lu Wei <luwei32@...wei.com>
> ---
>  drivers/net/ethernet/cortina/gemini.c | 24 +++++++++++++++++++-----
>  1 file changed, 19 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 8d13ea370db1..5e93a1a570b6 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c
> @@ -2407,37 +2407,48 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
>         dmares = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>         if (!dmares) {
>                 dev_err(dev, "no DMA resource\n");
> +               free_netdev(netdev);
>                 return -ENODEV;
>         }
>         port->dma_base = devm_ioremap_resource(dev, dmares);
> -       if (IS_ERR(port->dma_base))
> +       if (IS_ERR(port->dma_base)) {
> +               free_netdev(netdev);
>                 return PTR_ERR(port->dma_base);
> +       }
> 
>         /* GMAC config memory */
>         gmacres = platform_get_resource(pdev, IORESOURCE_MEM, 1);
>         if (!gmacres) {
>                 dev_err(dev, "no GMAC resource\n");
> +               free_netdev(netdev);
>                 return -ENODEV;
>         }
>         port->gmac_base = devm_ioremap_resource(dev, gmacres);
> -       if (IS_ERR(port->gmac_base))
> +       if (IS_ERR(port->gmac_base)) {
> +               free_netdev(netdev);
>                 return PTR_ERR(port->gmac_base);
> +       }
> 
>         /* Interrupt */
>         irq = platform_get_irq(pdev, 0);
> -       if (irq <= 0)
> +       if (irq <= 0) {
> +               free_netdev(netdev);
>                 return irq ? irq : -ENODEV;
> +       }
>         port->irq = irq;
> 
>         /* Clock the port */
>         port->pclk = devm_clk_get(dev, "PCLK");
>         if (IS_ERR(port->pclk)) {
>                 dev_err(dev, "no PCLK\n");
> +               free_netdev(netdev);
>                 return PTR_ERR(port->pclk);
>         }
>         ret = clk_prepare_enable(port->pclk);
> -       if (ret)
> +       if (ret) {
> +               free_netdev(netdev);
>                 return ret;
> +       }
> 
>         /* Maybe there is a nice ethernet address we should use */
>         gemini_port_save_mac_addr(port);
> @@ -2446,6 +2457,7 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
>         port->reset = devm_reset_control_get_exclusive(dev, NULL);
>         if (IS_ERR(port->reset)) {
>                 dev_err(dev, "no reset\n");
> +               free_netdev(netdev);
>                 return PTR_ERR(port->reset);
>         }
>         reset_control_reset(port->reset);
> @@ -2501,8 +2513,10 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
>                                         IRQF_SHARED,
>                                         port_names[port->id],
>                                         port);
> -       if (ret)
> +       if (ret) {
> +               free_netdev(netdev);
>                 return ret;
> +       }
> 
>         ret = register_netdev(netdev);
>         if (!ret) {
> --
> 2.17.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@...ts.infradead.org
> https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.infradead.org_mailman_listinfo_linux-2Darm-2Dkernel&d=DwICAg&c=7dfBJ8cXbWjhc0BhImu8wQ&r=wlaKTGoVCDxOzHc2QUzpzGEf9oY3eidXlAe3OF1omvo&m=56ruRjtNY-BIzquRyoO0KSbrR7UBB81VfqotT_rfFus&s=Axiqv0SZYKFXgMc1zJLilZCk9wbRAt4LkKtW6VjKTgw&e=

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ