sh_eth: fix couple of bugs in sh_eth_ring_format()
Subsystems (3)
cover sh_eth: fix couple of bugs in sh_eth_ring_format()
Hello.
Here's a set of 2 patches against DaveM's 'net.git' repo fixing two bugs
in sh_eth_.ring_format()...
[1/2] sh_eth: fix NULL pointer dereference in sh_eth_ring_format() [2/2] sh_eth: advance 'rxdesc' later in sh_eth_ring_format()
MBR, Sergei
PATCH 1/2 sh_eth: fix NULL pointer dereference in sh_eth_ring_format()
In a low memory situation, if netdev_alloc_skb() fails on a first RX ring loop iteration in sh_eth_ring_format(), 'rxdesc' is still NULL. Avoid kernel oops by adding the 'rxdesc' check after the loop.
--- drivers/net/ethernet/renesas/sh_eth.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/renesas/sh_eth.c +2 -1
@@ -1163,7 +1163,8 @@ static void sh_eth_ring_format(struct ne mdp->dirty_rx = (u32) (i - mdp->num_rx_ring);/* Mark the last entry as wrapping the ring. */ - rxdesc->status |=cpu_to_le32 (RD_RDLE ); +if (rxdesc) + rxdesc->status |=cpu_to_le32 (RD_RDLE );memset (mdp->tx_ring,0 , tx_ringsize);
PATCH 2/2 sh_eth: advance 'rxdesc' later in sh_eth_ring_format()
In reply to Sergei ShtylyovIff dma_map_single() fails, 'rxdesc' should point to the last filled RX descriptor, so that it can be marked as the last one, however the driver would have already advanced it by that time. In order to fix that, only fill an RX descriptor once all the data for it is ready.
--- drivers/net/ethernet/renesas/sh_eth.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/ethernet/renesas/sh_eth.c +4 -3
@@ -1136,11 +1136,8 @@ static void sh_eth_ring_format(struct nebreak ;sh_eth_set_receive_align (skb); -/* RX descriptor */ - rxdesc = &mdp->rx_ring[i];/* The size of the buffer is a multiple of 32 bytes. */ buf_len =ALIGN (mdp->rx_buf_sz,32 ); - rxdesc->len =cpu_to_le32 (buf_len <<16 ); dma_addr =dma_map_single (&ndev->dev, skb->data, buf_len,DMA_FROM_DEVICE );if (dma_mapping_error (&ndev->dev, dma_addr)) {
@@ -1148,6 +1145,10 @@ static void sh_eth_ring_format(struct nebreak ; } mdp->rx_skbuff[i] = skb; + +/* RX descriptor */ + rxdesc = &mdp->rx_ring[i]; + rxdesc->len =cpu_to_le32 (buf_len <<16 ); rxdesc->addr =cpu_to_le32 (dma_addr); rxdesc->status =cpu_to_le32 (RD_RACT |RD_RFP );
David Miller
maintainerFrom: Sergei Shtylyov <[email protected]>
Date: Tue, 08 Mar 2016 01:33:38 +0300
Quoted 5 lines
Here's a set of 2 patches against DaveM's 'net.git' repo fixing two bugs
insh_eth_.ring_format()...[1/2]
sh_eth: fix NULL pointer dereference insh_eth_ring_format()[2/2]sh_eth: advance 'rxdesc' later insh_eth_ring_format()
Since Linus is likely to release today or otherwise very soon I'm not putting things into 'net'.
So I've applied this series to 'net-next', let me know if I should queue it up for stable.
Thanks.
Quoted 11 lines · David Miller
Quoted 5 lines
Here's a set of 2 patches against DaveM's 'net.git' repo fixing two bugs
insh_eth_.ring_format()...[1/2]
sh_eth: fix NULL pointer dereference insh_eth_ring_format()[2/2]sh_eth: advance 'rxdesc' later insh_eth_ring_format()Since Linus is likely to release today or otherwise very soon I'm not putting things into 'net'.
So I've applied this series to 'net-next', let me know if I should queue it up for stable.
If your generally queue the error path fixes, then queue these two please.
Quoted 1 line
Thanks.
My pleasure. :-)
MBR, Sergei
David Miller
maintainerFrom: Sergei Shtylyov <[email protected]>
Date: Fri, 11 Mar 2016 01:01:22 +0300
Quoted 9 lines · David Miller
Quoted 8 lines
Quoted 7 lines
Here's a set of 2 patches against DaveM's 'net.git' repo fixing two bugs
insh_eth_.ring_format()...[1/2]
sh_eth: fix NULL pointer dereference insh_eth_ring_format()[2/2]sh_eth: advance 'rxdesc' later insh_eth_ring_format()
Quoted 8 lines
Quoted 5 lines
Since Linus is likely to release today or otherwise very soon I'm not putting things into 'net'.
So I've applied this series to 'net-next', let me know if I should queue it up for stable.
If your generally queue the error path fixes, then queue these two please.
Done.