[PATCH net] qede: confirm skb is allocated before using

Jamie Bainbridge posted 1 patch 4 years, 2 months ago
drivers/net/ethernet/qlogic/qede/qede_fp.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH net] qede: confirm skb is allocated before using
Posted by Jamie Bainbridge 4 years, 2 months ago
qede_build_skb() assumes build_skb() always works and goes straight
to skb_reserve(). However, build_skb() can fail under memory pressure.
This results in a kernel panic because the skb to reserve is NULL.

Add a check in case build_skb() failed to allocate and return NULL.

The NULL return is handled correctly in callers to qede_build_skb().

Fixes: 8a8633978b842 ("qede: Add build_skb() support.")
Signed-off-by: Jamie Bainbridge <jamie.bainbridge@gmail.com>
---
 drivers/net/ethernet/qlogic/qede/qede_fp.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/qlogic/qede/qede_fp.c b/drivers/net/ethernet/qlogic/qede/qede_fp.c
index b242000a77fd8db322672e541df074be9b5ce9ef..b7cc36589f592e995e3a12bb80bc7c8e3af7dc42 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_fp.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_fp.c
@@ -748,6 +748,9 @@ qede_build_skb(struct qede_rx_queue *rxq,
 	buf = page_address(bd->data) + bd->page_offset;
 	skb = build_skb(buf, rxq->rx_buf_seg_size);
 
+	if (unlikely(!skb))
+		return NULL;
+
 	skb_reserve(skb, pad);
 	skb_put(skb, len);
 
-- 
2.35.1
Re: [PATCH net] qede: confirm skb is allocated before using
Posted by patchwork-bot+netdevbpf@kernel.org 4 years, 2 months ago
Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Wed,  6 Apr 2022 21:19:19 +1000 you wrote:
> qede_build_skb() assumes build_skb() always works and goes straight
> to skb_reserve(). However, build_skb() can fail under memory pressure.
> This results in a kernel panic because the skb to reserve is NULL.
> 
> Add a check in case build_skb() failed to allocate and return NULL.
> 
> The NULL return is handled correctly in callers to qede_build_skb().
> 
> [...]

Here is the summary with links:
  - [net] qede: confirm skb is allocated before using
    https://git.kernel.org/netdev/net/c/4e910dbe3650

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Re: [PATCH net] qede: confirm skb is allocated before using
Posted by Jakub Kicinski 4 years, 2 months ago
On Wed,  6 Apr 2022 11:58:09 +1000 Jamie Bainbridge wrote:
> qede_build_skb() assumes build_skb() always works and goes straight
> to skb_reserve(). However, build_skb() can fail under memory pressure.
> This results in a kernel panic because the skb to reserve is NULL.
> 
> Add a check in case build_skb() failed to allocate and return NULL.
> 
> The NULL return is handled correctly in callers to qede_build_skb().
> 
> Fixes: 8a8633978b842 ("qede: Add build_skb() support.")
> Signed-off-by: Jamie Bainbridge <jamie.bainbridge@gmail.com>

FTR commit 4e910dbe3650 ("qede: confirm skb is allocated before using")
in net.