2009-04-20 13:03:50

by jon.lin

[permalink] [raw]
Subject: [PATCH 2.6.29.1 1/1] 8139too: fix HW initial flow

From: Jonathan Lin <[email protected]>

While ifconfig eth0 up kernel calls open() of 8139 driver(8139too.c).
In rtl8139_hw_start() of rtl8139_open(), 8139 driver enable RX before setting up the DMA buffer address. In this interval where RX was enabled and DMA buffer address is not yet set up, any incoming broadcast packet would be send to a strange physical address:
0x003e8800 which is the default value of DMA buffer address.
Unfortunately, this address is used by Linux kernel. So kernel panics.
This patch fix it by setting up DMA buffer address before RX enabled and everything is fine even under broadcast packets attack.

Signed-off-by: Jonathan Lin <[email protected]>

--- linux-2.6.29.1/drivers/net/8139too.c.orig 2009-04-19 17:50:38.000000000 +0800
+++ linux-2.6.29.1/drivers/net/8139too.c 2009-04-19 17:52:51.000000000 +0800
@@ -1382,6 +1382,10 @@ static void rtl8139_hw_start (struct net
RTL_W32_F (MAC0 + 0, le32_to_cpu (*(__le32 *) (dev->dev_addr + 0)));
RTL_W32_F (MAC0 + 4, le16_to_cpu (*(__le16 *) (dev->dev_addr + 4)));

+ tp->cur_rx = 0;
+ /* init Rx ring buffer DMA address BEFORE Rx enabled*/
+ RTL_W32_F (RxBuf, tp->rx_ring_dma);
+
/* Must enable Tx/Rx before setting transfer thresholds! */
RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);

@@ -1389,8 +1393,6 @@ static void rtl8139_hw_start (struct net
RTL_W32 (RxConfig, tp->rx_config);
RTL_W32 (TxConfig, rtl8139_tx_config);

- tp->cur_rx = 0;
-
rtl_check_media (dev, 1);

if (tp->chipset >= CH_8139B) {
@@ -1405,9 +1407,6 @@ static void rtl8139_hw_start (struct net
/* Lock Config[01234] and BMCR register writes */
RTL_W8 (Cfg9346, Cfg9346_Lock);

- /* init Rx ring buffer DMA address */
- RTL_W32_F (RxBuf, tp->rx_ring_dma);
-
/* init Tx buffer DMA addresses */
for (i = 0; i < NUM_TX_DESC; i++)
RTL_W32_F (TxAddr0 + (i * 4), tp->tx_bufs_dma + (tp->tx_buf[i] - tp->tx_bufs));
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?


2009-04-20 13:34:50

by Amos Kong

[permalink] [raw]
Subject: Re: [PATCH 2.6.29.1 1/1] 8139too: fix HW initial flow

On Mon, Apr 20, 2009 at 08:58:01PM +0800, [email protected] wrote:
>From: Jonathan Lin <[email protected]>
>
>While ifconfig eth0 up kernel calls open() of 8139 driver(8139too.c).
>In rtl8139_hw_start() of rtl8139_open(), 8139 driver enable RX before setting up the DMA buffer address. In this interval where RX was enabled and DMA buffer address is not yet set up, any incoming broadcast packet would be send to a strange physical address:
>0x003e8800 which is the default value of DMA buffer address.
>Unfortunately, this address is used by Linux kernel. So kernel panics.
>This patch fix it by setting up DMA buffer address before RX enabled and everything is fine even under broadcast packets attack.
>
>Signed-off-by: Jonathan Lin <[email protected]>

Reviewed-by: Amos Kong <[email protected]>

>--- linux-2.6.29.1/drivers/net/8139too.c.orig 2009-04-19 17:50:38.000000000 +0800
>+++ linux-2.6.29.1/drivers/net/8139too.c 2009-04-19 17:52:51.000000000 +0800
>@@ -1382,6 +1382,10 @@ static void rtl8139_hw_start (struct net
> RTL_W32_F (MAC0 + 0, le32_to_cpu (*(__le32 *) (dev->dev_addr + 0)));
> RTL_W32_F (MAC0 + 4, le16_to_cpu (*(__le16 *) (dev->dev_addr + 4)));
>
>+ tp->cur_rx = 0;
>+ /* init Rx ring buffer DMA address BEFORE Rx enabled*/
>+ RTL_W32_F (RxBuf, tp->rx_ring_dma);
>+
...

2009-04-21 08:53:03

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 2.6.29.1 1/1] 8139too: fix HW initial flow

From: <[email protected]>
Date: Mon, 20 Apr 2009 20:58:01 +0800

> While ifconfig eth0 up kernel calls open() of 8139 driver(8139too.c).
> In rtl8139_hw_start() of rtl8139_open(), 8139 driver enable RX before setting up the DMA buffer address. In this interval where RX was enabled and DMA buffer address is not yet set up, any incoming broadcast packet would be send to a strange physical address:
> 0x003e8800 which is the default value of DMA buffer address.
> Unfortunately, this address is used by Linux kernel. So kernel panics.
> This patch fix it by setting up DMA buffer address before RX enabled and everything is fine even under broadcast packets attack.
>
> Signed-off-by: Jonathan Lin <[email protected]>

This patch does not apply, it was corrupted by your email client.

I even think it has MS-DOS style newlines in it :-(

2009-04-21 09:49:03

by Amos Kong

[permalink] [raw]
Subject: Re: [PATCH 2.6.29.1 1/1] 8139too: fix HW initial flow

...
>> Unfortunately, this address is used by Linux kernel. So kernel panics.
>> This patch fix it by setting up DMA buffer address before RX enabled and everything is fine even under broadcast packets attack.
>>
>> Signed-off-by: Jonathan Lin <[email protected]>
>
>This patch does not apply, it was corrupted by your email client.
>
>I even think it has MS-DOS style newlines in it :-(

Another new patch :)


While ifconfig eth0 up kernel calls open() of 8139 driver(8139too.c).
In rtl8139_hw_start() of rtl8139_open(), 8139 driver enable RX before setting up the DMA
buffer address. In this interval where RX was enabled and DMA buffer address is not yet set
up, any incoming broadcast packet would be send to a strange physical address:
0x003e8800 which is the default value of DMA buffer address.
Unfortunately, this address is used by Linux kernel. So kernel panics.
This patch fix it by setting up DMA buffer address before RX enabled and everything is fine
even under broadcast packets attack.

Signed-off-by: Jonathan Lin <[email protected]>
Signed-off-by: Amos Kong <[email protected]>

---
drivers/net/8139too.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
index 29df398..1fc4543 100644
--- a/drivers/net/8139too.c
+++ b/drivers/net/8139too.c
@@ -1383,6 +1383,11 @@ static void rtl8139_hw_start (struct net_device *dev)
RTL_W32_F (MAC0 + 0, le32_to_cpu (*(__le32 *) (dev->dev_addr + 0)));
RTL_W32_F (MAC0 + 4, le16_to_cpu (*(__le16 *) (dev->dev_addr + 4)));

+ tp->cur_rx = 0;
+
+ /* init Rx ring buffer DMA address */
+ RTL_W32_F (RxBuf, tp->rx_ring_dma);
+
/* Must enable Tx/Rx before setting transfer thresholds! */
RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);

@@ -1390,8 +1395,6 @@ static void rtl8139_hw_start (struct net_device *dev)
RTL_W32 (RxConfig, tp->rx_config);
RTL_W32 (TxConfig, rtl8139_tx_config);

- tp->cur_rx = 0;
-
rtl_check_media (dev, 1);

if (tp->chipset >= CH_8139B) {
@@ -1406,9 +1409,6 @@ static void rtl8139_hw_start (struct net_device *dev)
/* Lock Config[01234] and BMCR register writes */
RTL_W8 (Cfg9346, Cfg9346_Lock);

- /* init Rx ring buffer DMA address */
- RTL_W32_F (RxBuf, tp->rx_ring_dma);
-
/* init Tx buffer DMA addresses */
for (i = 0; i < NUM_TX_DESC; i++)
RTL_W32_F (TxAddr0 + (i * 4), tp->tx_bufs_dma + (tp->tx_buf[i] - tp->tx_bufs));
--
1.5.6.3

2009-04-21 10:10:10

by jon.lin

[permalink] [raw]
Subject: RE: [PATCH 2.6.29.1 1/1] 8139too: fix HW initial flow

Dear Sirs,

I am so sorry for my clumsiness!
It is so embarrassed that I can't submit a valid patch...
Thank you all for your incredible patience.
I will try to use mail command in my Linux box to submit it again.
Sorry for these stupid failures.

Regards
Jonathan


-----Original Message-----
From: Amos Kong [mailto:[email protected]]
Sent: Tuesday, April 21, 2009 5:48 PM
To: David Miller
Cc: Jon.Lin(?L?v?w); [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2.6.29.1 1/1] 8139too: fix HW initial flow

...
>> Unfortunately, this address is used by Linux kernel. So kernel panics.
>> This patch fix it by setting up DMA buffer address before RX enabled and everything is fine even under broadcast packets attack.
>>
>> Signed-off-by: Jonathan Lin <[email protected]>
>
>This patch does not apply, it was corrupted by your email client.
>
>I even think it has MS-DOS style newlines in it :-(

Another new patch :)


While ifconfig eth0 up kernel calls open() of 8139 driver(8139too.c).
In rtl8139_hw_start() of rtl8139_open(), 8139 driver enable RX before setting up the DMA
buffer address. In this interval where RX was enabled and DMA buffer address is not yet set
up, any incoming broadcast packet would be send to a strange physical address:
0x003e8800 which is the default value of DMA buffer address.
Unfortunately, this address is used by Linux kernel. So kernel panics.
This patch fix it by setting up DMA buffer address before RX enabled and everything is fine
even under broadcast packets attack.

Signed-off-by: Jonathan Lin <[email protected]>
Signed-off-by: Amos Kong <[email protected]>

---
drivers/net/8139too.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
index 29df398..1fc4543 100644
--- a/drivers/net/8139too.c
+++ b/drivers/net/8139too.c
@@ -1383,6 +1383,11 @@ static void rtl8139_hw_start (struct net_device *dev)
RTL_W32_F (MAC0 + 0, le32_to_cpu (*(__le32 *) (dev->dev_addr + 0)));
RTL_W32_F (MAC0 + 4, le16_to_cpu (*(__le16 *) (dev->dev_addr + 4)));

+ tp->cur_rx = 0;
+
+ /* init Rx ring buffer DMA address */
+ RTL_W32_F (RxBuf, tp->rx_ring_dma);
+
/* Must enable Tx/Rx before setting transfer thresholds! */
RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);

@@ -1390,8 +1395,6 @@ static void rtl8139_hw_start (struct net_device *dev)
RTL_W32 (RxConfig, tp->rx_config);
RTL_W32 (TxConfig, rtl8139_tx_config);

- tp->cur_rx = 0;
-
rtl_check_media (dev, 1);

if (tp->chipset >= CH_8139B) {
@@ -1406,9 +1409,6 @@ static void rtl8139_hw_start (struct net_device *dev)
/* Lock Config[01234] and BMCR register writes */
RTL_W8 (Cfg9346, Cfg9346_Lock);

- /* init Rx ring buffer DMA address */
- RTL_W32_F (RxBuf, tp->rx_ring_dma);
-
/* init Tx buffer DMA addresses */
for (i = 0; i < NUM_TX_DESC; i++)
RTL_W32_F (TxAddr0 + (i * 4), tp->tx_bufs_dma + (tp->tx_buf[i] - tp->tx_bufs));
--
1.5.6.3


????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?

2009-04-21 10:31:59

by Eric Dumazet

[permalink] [raw]
Subject: Re: [PATCH 2.6.29.1 1/1] 8139too: fix HW initial flow

Amos Kong a ?crit :
> ...
>>> Unfortunately, this address is used by Linux kernel. So kernel panics.
>>> This patch fix it by setting up DMA buffer address before RX enabled and everything is fine even under broadcast packets attack.
>>>
>>> Signed-off-by: Jonathan Lin <[email protected]>
>> This patch does not apply, it was corrupted by your email client.
>>
>> I even think it has MS-DOS style newlines in it :-(
>
> Another new patch :)
>
>
> While ifconfig eth0 up kernel calls open() of 8139 driver(8139too.c).
> In rtl8139_hw_start() of rtl8139_open(), 8139 driver enable RX before setting up the DMA
> buffer address. In this interval where RX was enabled and DMA buffer address is not yet set
> up, any incoming broadcast packet would be send to a strange physical address:
> 0x003e8800 which is the default value of DMA buffer address.
> Unfortunately, this address is used by Linux kernel. So kernel panics.
> This patch fix it by setting up DMA buffer address before RX enabled and everything is fine
> even under broadcast packets attack.
>
> Signed-off-by: Jonathan Lin <[email protected]>
> Signed-off-by: Amos Kong <[email protected]>

Signed-off-by: Eric Dumazet <[email protected]>

Thanks Amos and Jonathan

>
> ---
> drivers/net/8139too.c | 10 +++++-----
> 1 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
> index 29df398..1fc4543 100644
> --- a/drivers/net/8139too.c
> +++ b/drivers/net/8139too.c
> @@ -1383,6 +1383,11 @@ static void rtl8139_hw_start (struct net_device *dev)
> RTL_W32_F (MAC0 + 0, le32_to_cpu (*(__le32 *) (dev->dev_addr + 0)));
> RTL_W32_F (MAC0 + 4, le16_to_cpu (*(__le16 *) (dev->dev_addr + 4)));
>
> + tp->cur_rx = 0;
> +
> + /* init Rx ring buffer DMA address */
> + RTL_W32_F (RxBuf, tp->rx_ring_dma);
> +
> /* Must enable Tx/Rx before setting transfer thresholds! */
> RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb);
>
> @@ -1390,8 +1395,6 @@ static void rtl8139_hw_start (struct net_device *dev)
> RTL_W32 (RxConfig, tp->rx_config);
> RTL_W32 (TxConfig, rtl8139_tx_config);
>
> - tp->cur_rx = 0;
> -
> rtl_check_media (dev, 1);
>
> if (tp->chipset >= CH_8139B) {
> @@ -1406,9 +1409,6 @@ static void rtl8139_hw_start (struct net_device *dev)
> /* Lock Config[01234] and BMCR register writes */
> RTL_W8 (Cfg9346, Cfg9346_Lock);
>
> - /* init Rx ring buffer DMA address */
> - RTL_W32_F (RxBuf, tp->rx_ring_dma);
> -
> /* init Tx buffer DMA addresses */
> for (i = 0; i < NUM_TX_DESC; i++)
> RTL_W32_F (TxAddr0 + (i * 4), tp->tx_bufs_dma + (tp->tx_buf[i] - tp->tx_bufs));

2009-04-21 10:36:16

by Eric Dumazet

[permalink] [raw]
Subject: Re: [PATCH 2.6.29.1 1/1] 8139too: fix HW initial flow

[email protected] a e'crit :
> Dear Sirs,
>
> I am so sorry for my clumsiness!
> It is so embarrassed that I can't submit a valid patch...
> Thank you all for your incredible patience.
> I will try to use mail command in my Linux box to submit it again.
> Sorry for these stupid failures.
>
> Regards
> Jonathan

It happens :(

Next time you want to try, just send your patch to someone
(this could be you or me) that can check patch before you re-submit it to
the lists, this can avoid many iterations.

You did the hard work, finding and fixing the bug, dont forget it !

2009-04-22 07:44:52

by David Miller

[permalink] [raw]
Subject: Re: [PATCH 2.6.29.1 1/1] 8139too: fix HW initial flow

From: Eric Dumazet <[email protected]>
Date: Tue, 21 Apr 2009 12:30:24 +0200

> Amos Kong a ?crit :
>> ...
>> While ifconfig eth0 up kernel calls open() of 8139 driver(8139too.c).
>> In rtl8139_hw_start() of rtl8139_open(), 8139 driver enable RX before setting up the DMA
>> buffer address. In this interval where RX was enabled and DMA buffer address is not yet set
>> up, any incoming broadcast packet would be send to a strange physical address:
>> 0x003e8800 which is the default value of DMA buffer address.
>> Unfortunately, this address is used by Linux kernel. So kernel panics.
>> This patch fix it by setting up DMA buffer address before RX enabled and everything is fine
>> even under broadcast packets attack.
>>
>> Signed-off-by: Jonathan Lin <[email protected]>
>> Signed-off-by: Amos Kong <[email protected]>
>
> Signed-off-by: Eric Dumazet <[email protected]>
>
> Thanks Amos and Jonathan

Applied, thanks everyone.