[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230607100902.4df2bc27@xps-13>
Date: Wed, 7 Jun 2023 10:09:02 +0200
From: Miquel Raynal <miquel.raynal@...tlin.com>
To: William Zhang <william.zhang@...adcom.com>
Cc: Broadcom Kernel List <bcm-kernel-feedback-list@...adcom.com>,
Linux MTD List <linux-mtd@...ts.infradead.org>,
f.fainelli@...il.com, rafal@...ecki.pl, kursad.oney@...adcom.com,
joel.peshkin@...adcom.com, computersforpeace@...il.com,
anand.gore@...adcom.com, dregan@...l.com, kamal.dasu@...adcom.com,
tomer.yacoby@...adcom.com, dan.beygelman@...adcom.com,
Florian Fainelli <florian.fainelli@...adcom.com>,
linux-kernel@...r.kernel.org,
Vignesh Raghavendra <vigneshr@...com>,
Richard Weinberger <richard@....at>,
Kamal Dasu <kdasu.kdev@...il.com>
Subject: Re: [PATCH 04/12] mtd: rawnand: brcmnand: Fix potential
out-of-bounds access in oob write
Hi William,
william.zhang@...adcom.com wrote on Tue, 6 Jun 2023 16:12:44 -0700:
> When the oob buffer length is not in multiple of words, the oob write
> function does out-of-bounds read on the oob source buffer at the last
> iteration. Fix that by always checking length limit on the oob buffer
> read and fill with 0xff when reaching the end of the buffer to the oob
> registers.
>
> Fixes: 27c5b17cd1b1 ("mtd: nand: add NAND driver "library" for Broadcom STB NAND controller")
> Signed-off-by: William Zhang <william.zhang@...adcom.com>
> Reviewed-by: Florian Fainelli <florian.fainelli@...adcom.com>
> ---
>
> drivers/mtd/nand/raw/brcmnand/brcmnand.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> index 20832857c4aa..d920e88c7f5b 100644
> --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> @@ -1486,10 +1486,10 @@ static int write_oob_to_regs(struct brcmnand_controller *ctrl, int i,
>
> for (j = 0; j < tbytes; j += 4)
> oob_reg_write(ctrl, j,
> - (oob[j + 0] << 24) |
> - (oob[j + 1] << 16) |
> - (oob[j + 2] << 8) |
> - (oob[j + 3] << 0));
> + (((j < tbytes) ? oob[j] : 0xff) << 24) |
> + (((j + 1 < tbytes) ? oob[j + 1] : 0xff) << 16) |
> + (((j + 2 < tbytes) ? oob[j + 2] : 0xff) << 8) |
> + ((j + 3 < tbytes) ? oob[j + 3] : 0xff));
This is a lot of additional operations which most of the time are not
relevant. I would instead got for one less iteration in the for loop
when there is unaligned data, and then dedicated if/else to fill the
missing bytes.
> return tbytes;
> }
>
Thanks,
Miquèl
Powered by blists - more mailing lists