net: fec: Coverity issue: Dereference null return value
Subsystems (3)
[email protected]
maintainerPATCH v2 1/1 net: fec: Coverity issue: Dereference null return value
From: Wei Fang <[email protected]>
The build_skb might return a null pointer but there is no check on the return value in the fec_enet_rx_queue(). So a null pointer dereference might occur. To avoid this, we check the return value of build_skb. If the return value is a null pointer, the driver will recycle the page and update the statistic of ndev. Then jump to rx_processing_done to clear the status flags of the BD so that the hardware can recycle the BD.
---
V2 changes:
1. Remove rx_packets and rx_bytes counters.
2. Use netdev_err_once instead of netdev_err.
--- drivers/net/ethernet/freescale/fec_main.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/ethernet/freescale/fec_main.c +8 -0
@@ -1674,6 +1674,14 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id)* bridging applications. */ skb =build_skb (page_address (page),PAGE_SIZE ); +if (unlikely (!skb)) { +page_pool_recycle_direct (rxq->page_pool, page); + ndev->stats.rx_dropped++; + +netdev_err_once (ndev,"build_skb failed!\n" ); + goto rx_processing_done; + } +skb_reserve (skb, data_start);skb_put (skb, pkt_len - sub_len);skb_mark_for_recycle (skb);
Signature · 1 line
2.25.1
Quoted 29 lines · On Sun, Dec 18, 2022 at 6:31 PM <[email protected]> wrote:
From: Wei Fang <[email protected]>
The
build_skbmight return a null pointer but there is no check on the return value in thefec_enet_rx_queue(). So a null pointer dereference might occur. To avoid this, we check the return value ofbuild_skb. If the return value is a null pointer, the driver will recycle the page and update the statistic of ndev. Then jump torx_processing_doneto clear the status flags of the BD so that the hardware can recycle the BD.Signed-off-by Wei Fang <[email protected]>Reviewed-by Shenwei Wang <[email protected]>---
V2 changes:
1. Removerx_packetsandrx_bytescounters.
2. Usenetdev_err_onceinstead ofnetdev_err.--- drivers/net/ethernet/freescale/fec_main.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/net/ethernet/freescale/fec_main.c +1
-0@@ -1674,6 +1674,14 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id)* bridging applications. */ skb =build_skb (page_address (page),PAGE_SIZE ); +if (unlikely (!skb)) {
drivers/net/ethernet/freescale/fec_main.c fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id) · line 1687
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +7
-0+page_pool_recycle_direct (rxq->page_pool, page); + ndev->stats.rx_dropped++; + +netdev_err_once (ndev,"build_skb failed!\n" ); + goto rx_processing_done; + } +skb_reserve (skb, data_start);skb_put (skb, pkt_len - sub_len);skb_mark_for_recycle (skb);
Looks good to me.
Jakub Kicinski
maintainerQuoted 8 lines · On Mon, 19 Dec 2022 10:27:55 +0800 [email protected] wrote:
From: Wei Fang <[email protected]>
The
build_skbmight return a null pointer but there is no check on the return value in thefec_enet_rx_queue(). So a null pointer dereference might occur. To avoid this, we check the return value ofbuild_skb. If the return value is a null pointer, the driver will recycle the page and update the statistic of ndev. Then jump torx_processing_doneto clear the status flags of the BD so that the hardware can recycle the BD.
Applied but I had to change the subject because the subject should describe the change. Mentioning the tool which found the problem belongs in the body of the message.
Wei Fang
maintainerQuoted 22 lines
-----Original Message-----
From: Jakub Kicinski <[email protected]>
Sent: 2022年12月21日 3:36
To: Wei Fang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Clark Wang <[email protected]>; Shenwei Wang <[email protected]>; [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2 net] net: fec: Coverity issue: Dereference null return valueQuoted 8 lines · On Mon, 19 Dec 2022 10:27:55 +0800 [email protected] wrote:
From: Wei Fang <[email protected]>
The
build_skbmight return a null pointer but there is no check on the return value in thefec_enet_rx_queue(). So a null pointer dereference might occur. To avoid this, we check the return value ofbuild_skb. If the return value is a null pointer, the driver will recycle the page and update the statistic of ndev. Then jump torx_processing_doneto clear the status flags of the BD so that the hardware can recycle the BD.
Quoted 3 lines
Applied but I had to change the subject because the subject should describe the change. Mentioning the tool which found the problem belongs in the body of the message.
Thanks for taking the time to make these changes, I'll keep these things in mind next time.