mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <sha@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH master 4/7] net: gianfar: fix out of bounds read of local variable
Date: Tue, 6 Jun 2023 13:31:59 +0200	[thread overview]
Message-ID: <8ede8e80-bcaf-37b8-29a0-ca9181f91a47@pengutronix.de> (raw)
In-Reply-To: <20230606093344.GV18491@pengutronix.de>

On 06.06.23 11:33, Sascha Hauer wrote:
> On Mon, Jun 05, 2023 at 08:29:36AM +0200, Ahmad Fatoum wrote:
>> The MAC address will be written to two 32-bit registers. Because
>> MAC_ADDR_LEN == 6, this meant two bytes out-of-bounds where written to
>> the hardware register. Fix this by having them be in-bound and always
>> initialized to zero.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>>  drivers/net/gianfar.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
>> index 4b374b4a50de..10a95324920b 100644
>> --- a/drivers/net/gianfar.c
>> +++ b/drivers/net/gianfar.c
>> @@ -234,7 +234,7 @@ static int gfar_set_ethaddr(struct eth_device *edev, const unsigned char *mac)
>>  {
>>  	struct gfar_private *priv = edev->priv;
>>  	void __iomem *regs = priv->regs;
>> -	char tmpbuf[MAC_ADDR_LEN];
>> +	char tmpbuf[8] = {};
> 
> I would prefer to adopt the Linux commit fixing this code which apart
> from the out-of-bounds access also has endianess fixes and makes the
> code simpler:
> 
> ---------------------------8<-----------------------------------
> 
> From 35cc52aacd65886a2ae46e68f727cadd09a3e8f2 Mon Sep 17 00:00:00 2001
> From: Sascha Hauer <s.hauer@pengutronix.de>
> Date: Tue, 6 Jun 2023 11:29:51 +0200
> Subject: [PATCH] net: gianfar: make MAC addr setup endian safe, cleanup
> 
> This is an adoption of Linux commit:
> 
> | commit 83bfc3c4765c35ef0dfff8a3d6dedab88f3f50ea
> | Author: Claudiu Manoil <claudiu.manoil@freescale.com>
> | Date:   Tue Oct 7 10:44:33 2014 +0300
> |
> |     gianfar: Make MAC addr setup endian safe, cleanup
> |
> |     Fix the 32-bit memory access that is not endian safe,
> |     i.e. not giving the desired byte layout for a LE CPU:
> |     tempval = *((u32 *) (tmpbuf + 4)), where 'char tmpbuf[]'.
> |
> |     Get rid of rendundant local vars (tmpbuf[] and idx) and
> |     forced casts.  Cleanup comments.
> |
> |     Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
> |     Signed-off-by: David S. Miller <davem@davemloft.net>
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
>  drivers/net/gianfar.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
> index 4b374b4a50..1a07059db4 100644
> --- a/drivers/net/gianfar.c
> +++ b/drivers/net/gianfar.c
> @@ -234,19 +234,13 @@ static int gfar_set_ethaddr(struct eth_device *edev, const unsigned char *mac)
>  {
>  	struct gfar_private *priv = edev->priv;
>  	void __iomem *regs = priv->regs;
> -	char tmpbuf[MAC_ADDR_LEN];
>  	uint tempval;
> -	int ix;
> -
> -	for (ix = 0; ix < MAC_ADDR_LEN; ix++)
> -		tmpbuf[MAC_ADDR_LEN - 1 - ix] = mac[ix];
>  
> -	tempval = (tmpbuf[0] << 24) | (tmpbuf[1] << 16) | (tmpbuf[2] << 8) |
> -		  tmpbuf[3];
> +	tempval = (mac[5] << 24) | (mac[4] << 16) | (mac[3] << 8)  |  mac[2];
>  
>  	out_be32(regs + GFAR_MACSTRADDR1_OFFSET, tempval);
>  
> -	tempval = *((uint *)(tmpbuf + 4));
> +	tempval = (mac[1] << 24) | (mac[0] << 16);
>  
>  	out_be32(regs + GFAR_MACSTRADDR2_OFFSET, tempval);
>  

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




  reply	other threads:[~2023-06-06 11:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-05  6:29 [PATCH master 1/7] ddr: imx8m: align function definition with prototype Ahmad Fatoum
2023-06-05  6:29 ` [PATCH master 2/7] include: bitmask: avoid -Wint-in-bool-context warning Ahmad Fatoum
2023-06-05  6:29 ` [PATCH master 3/7] net: fec_mpc5200: fix false positive -Wmisleading-indentation Ahmad Fatoum
2023-06-05  6:29 ` [PATCH master 4/7] net: gianfar: fix out of bounds read of local variable Ahmad Fatoum
2023-06-06  9:33   ` Sascha Hauer
2023-06-06 11:31     ` Ahmad Fatoum [this message]
2023-06-05  6:29 ` [PATCH master 5/7] MIPS: boot: main_entry: use malloc_end instead of _stext Ahmad Fatoum
2023-06-05  6:29 ` [PATCH master 6/7] MIPS: longsoon: restart: hide access to zero page Ahmad Fatoum
2023-06-05  6:29 ` [PATCH master 7/7] bootm: booti: fix false positive uninitialized variable access Ahmad Fatoum
2023-06-06  9:35 ` [PATCH master 1/7] ddr: imx8m: align function definition with prototype Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8ede8e80-bcaf-37b8-29a0-ca9181f91a47@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=sha@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox