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: <ee00de10-2970-6e58-601b-4898bfa1c452@microchip.com>
Date:   Fri, 4 Mar 2022 07:34:34 +0000
From:   <Claudiu.Beznea@...rochip.com>
To:     <xiongx18@...an.edu.cn>, <Tudor.Ambarus@...rochip.com>,
        <miquel.raynal@...tlin.com>, <richard@....at>, <vigneshr@...com>,
        <Nicolas.Ferre@...rochip.com>, <alexandre.belloni@...tlin.com>,
        <bbrezillon@...nel.org>, <linux-mtd@...ts.infradead.org>,
        <linux-arm-kernel@...ts.infradead.org>,
        <linux-kernel@...r.kernel.org>
CC:     <yuanxzhang@...an.edu.cn>, <xiyuyang19@...an.edu.cn>,
        <tanxin.ctf@...il.com>
Subject: Re: [PATCH v3] mtd: rawnand: atmel: fix refcount issue in
 atmel_nand_controller_init

On 02.03.2022 15:27, Xin Xiong wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> The reference counting issue happens in several error handling paths
> on a refcounted object "nc->dmac". In these paths, the function simply
> returns the error code, forgetting to balance the reference count of
> "nc->dmac", increased earlier by dma_request_channel(), which may
> cause refcount leaks.
> 
> Fix it by decrementing the refcount of specific object in those error
> paths.
> 
> Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver")
> Co-developed-by: Xiyu Yang <xiyuyang19@...an.edu.cn>
> Signed-off-by: Xiyu Yang <xiyuyang19@...an.edu.cn>
> Co-developed-by: Xin Tan <tanxin.ctf@...il.com>
> Signed-off-by: Xin Tan <tanxin.ctf@...il.com>
> Signed-off-by: Xin Xiong <xiongx18@...an.edu.cn>
> ---
> V2 -> V3: Removed redundant lines
> V1 -> V2: Rewrited the error handling block
> ---
>  drivers/mtd/nand/raw/atmel/nand-controller.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c
> index f3276ee9e4fe..3dc4a4bacde5 100644
> --- a/drivers/mtd/nand/raw/atmel/nand-controller.c
> +++ b/drivers/mtd/nand/raw/atmel/nand-controller.c
> @@ -2060,13 +2060,15 @@ static int atmel_nand_controller_init(struct atmel_nand_controller *nc,
>         nc->mck = of_clk_get(dev->parent->of_node, 0);
>         if (IS_ERR(nc->mck)) {
>                 dev_err(dev, "Failed to retrieve MCK clk\n");
> -               return PTR_ERR(nc->mck);
> +               ret = PTR_ERR(nc->mck);
> +               goto out_release_dma;
>         }
> 
>         np = of_parse_phandle(dev->parent->of_node, "atmel,smc", 0);
>         if (!np) {
>                 dev_err(dev, "Missing or invalid atmel,smc property\n");
> -               return -EINVAL;
> +               ret = -EINVAL;
> +               goto out_release_dma;
>         }
> 
>         nc->smc = syscon_node_to_regmap(np);
> @@ -2074,10 +2076,16 @@ static int atmel_nand_controller_init(struct atmel_nand_controller *nc,
>         if (IS_ERR(nc->smc)) {
>                 ret = PTR_ERR(nc->smc);
>                 dev_err(dev, "Could not get SMC regmap (err = %d)\n", ret);
> -               return ret;
> +               goto out_release_dma;
>         }
> 
>         return 0;
> +
> +out_release_dma:
> +       if (nc->caps->has_dma && !atmel_nand_avoid_dma && nc->dmac)

As Boris also suggested previously, checking nc->dmac should be enough here.

> +               dma_release_channel(nc->dmac);
> +
> +       return ret;
>  }
> 
>  static int
> --
> 2.25.1
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ