sh_eth: fix NULL pointer dereference in sh_eth_ring_format()
authorSergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Mon, 7 Mar 2016 22:36:28 +0000 (01:36 +0300)
committerWilly Tarreau <w@1wt.eu>
Tue, 7 Jun 2016 08:42:49 +0000 (10:42 +0200)
commit c1b7fca65070bfadca94dd53a4e6b71cd4f69715 upstream.

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.

Reported-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
drivers/net/ethernet/renesas/sh_eth.c

index b93a0fb17236fd9ea0d9444d42ff3bfcbf34bde7..93b652516a94195151435f16a9de5633bf5d83b2 100644 (file)
@@ -1161,7 +1161,8 @@ static void sh_eth_ring_format(struct net_device *ndev)
        mdp->dirty_rx = (u32) (i - mdp->num_rx_ring);
 
        /* Mark the last entry as wrapping the ring. */
-       rxdesc->status |= cpu_to_edmac(mdp, RD_RDEL);
+       if (rxdesc)
+               rxdesc->status |= cpu_to_edmac(mdp, RD_RDEL);
 
        memset(mdp->tx_ring, 0, tx_ringsize);