Skip to content

Commit 6f4d93b

Browse files
ziweixiaokuba-moo
authored andcommitted
gve: Clear napi->skb before dev_kfree_skb_any()
gve_rx_free_skb incorrectly leaves napi->skb referencing an skb after it is freed with dev_kfree_skb_any(). This can result in a subsequent call to napi_get_frags returning a dangling pointer. Fix this by clearing napi->skb before the skb is freed. Fixes: 9b8dd5e ("gve: DQO: Add RX path") Cc: [email protected] Reported-by: Shailend Chand <[email protected]> Signed-off-by: Ziwei Xiao <[email protected]> Reviewed-by: Harshitha Ramamurthy <[email protected]> Reviewed-by: Shailend Chand <[email protected]> Reviewed-by: Praveen Kaligineedi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 79f18a4 commit 6f4d93b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/net/ethernet/google/gve/gve_rx_dqo.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,13 @@ static void gve_rx_skb_hash(struct sk_buff *skb,
647647
skb_set_hash(skb, le32_to_cpu(compl_desc->hash), hash_type);
648648
}
649649

650-
static void gve_rx_free_skb(struct gve_rx_ring *rx)
650+
static void gve_rx_free_skb(struct napi_struct *napi, struct gve_rx_ring *rx)
651651
{
652652
if (!rx->ctx.skb_head)
653653
return;
654654

655+
if (rx->ctx.skb_head == napi->skb)
656+
napi->skb = NULL;
655657
dev_kfree_skb_any(rx->ctx.skb_head);
656658
rx->ctx.skb_head = NULL;
657659
rx->ctx.skb_tail = NULL;
@@ -950,7 +952,7 @@ int gve_rx_poll_dqo(struct gve_notify_block *block, int budget)
950952

951953
err = gve_rx_dqo(napi, rx, compl_desc, complq->head, rx->q_num);
952954
if (err < 0) {
953-
gve_rx_free_skb(rx);
955+
gve_rx_free_skb(napi, rx);
954956
u64_stats_update_begin(&rx->statss);
955957
if (err == -ENOMEM)
956958
rx->rx_skb_alloc_fail++;
@@ -993,7 +995,7 @@ int gve_rx_poll_dqo(struct gve_notify_block *block, int budget)
993995

994996
/* gve_rx_complete_skb() will consume skb if successful */
995997
if (gve_rx_complete_skb(rx, napi, compl_desc, feat) != 0) {
996-
gve_rx_free_skb(rx);
998+
gve_rx_free_skb(napi, rx);
997999
u64_stats_update_begin(&rx->statss);
9981000
rx->rx_desc_err_dropped_pkt++;
9991001
u64_stats_update_end(&rx->statss);

0 commit comments

Comments
 (0)