Re: [PATCH] net: bmac: Fix stack corruption panic in bmac_probe()

2020-05-19 Thread Benjamin Herrenschmidt
On Tue, 2020-05-19 at 08:59 +0800, Jeremy Kerr wrote:
> Hi Stan,
> 
> > The new kernel compiled and booted with no errors, with these
> > STACKPROTECTOR options in .config (the last two revealed the bug):
> > 
> > CONFIG_HAVE_STACKPROTECTOR=y
> > CONFIG_CC_HAS_STACKPROTECTOR_NONE=y
> > CONFIG_STACKPROTECTOR=y
> > CONFIG_STACKPROTECTOR_STRONG=y
> 
> Brilliant, thanks for testing. I'll send a standalone patch to
> netdev.

Nice catch :-) Lots of people used these machines for years without
noticing :-)  Granted most people used newer generation stuff with
a gmac instead.

Cheers,
Ben.




Re: [PATCH] net: bmac: Fix stack corruption panic in bmac_probe()

2020-05-18 Thread Jeremy Kerr
Hi Stan,

> The new kernel compiled and booted with no errors, with these
> STACKPROTECTOR options in .config (the last two revealed the bug):
> 
> CONFIG_HAVE_STACKPROTECTOR=y
> CONFIG_CC_HAS_STACKPROTECTOR_NONE=y
> CONFIG_STACKPROTECTOR=y
> CONFIG_STACKPROTECTOR_STRONG=y

Brilliant, thanks for testing. I'll send a standalone patch to netdev.

Cheers,


Jeremy



Re: [PATCH] net: bmac: Fix stack corruption panic in bmac_probe()

2020-05-17 Thread Jeremy Kerr
Hi Finn,

> This fixes an old bug recently revealed by CONFIG_STACKPROTECTOR.

Good catch. I'm not sure about the fix though. That variable ('addr')
should be a ethernet hardware address; I'm surprised we're accessing
past the 6th byte. The culprit seems to be this, where 'ea' is the
address buffer:

   static void
   bmac_get_station_address(struct net_device *dev, unsigned char *ea)
   {
int i;
unsigned short data;

for (i = 0; i < 6; i++)
{
reset_and_select_srom(dev);
data = read_srom(dev, i + EnetAddressOffset/2, 
SROMAddressBits);
ea[2*i]   = bitrev8(data & 0x0ff);
ea[2*i+1] = bitrev8((data >> 8) & 0x0ff);
}
   }

- where it looks like the condition on that for-loop is wrong; we're
reading two bytes at a time there.

Can you try the attached patch?

Ben/Paul - any thoughts?

Cheers,


Jeremy

-

>From 141b20bcbdb3ad7c166b83b4ea61f3521d0a0679 Mon Sep 17 00:00:00 2001
From: Jeremy Kerr 
Date: Mon, 18 May 2020 08:54:25 +0800
Subject: [PATCH] net: bmac: Fix read of MAC address from ROM

In bmac_get_station_address, We're reading two bytes at a time from ROM,
but we do that six times, resulting in 12 bytes of read & writes. This
means we will write off the end of the six-byte destination buffer.

This change fixes the for-loop to only read/write six bytes.

Based on a proposed fix from Finn Thain .

Signed-off-by: Jeremy Kerr 
Reported-by: Stan Johnson 
Reported-by: Finn Thain 
---
 drivers/net/ethernet/apple/bmac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/apple/bmac.c 
b/drivers/net/ethernet/apple/bmac.c
index a58185b1d8bf..3e3711b60d01 100644
--- a/drivers/net/ethernet/apple/bmac.c
+++ b/drivers/net/ethernet/apple/bmac.c
@@ -1182,7 +1182,7 @@ bmac_get_station_address(struct net_device *dev, unsigned 
char *ea)
int i;
unsigned short data;
 
-   for (i = 0; i < 6; i++)
+   for (i = 0; i < 3; i++)
{
reset_and_select_srom(dev);
data = read_srom(dev, i + EnetAddressOffset/2, 
SROMAddressBits);
-- 
2.17.1