netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf] xsk: Free skb when TX metadata options are invalid
@ 2024-11-14 11:30 Felix Maurer
  2024-11-14 13:13 ` Toke Høiland-Jørgensen
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Felix Maurer @ 2024-11-14 11:30 UTC (permalink / raw)
  To: bpf
  Cc: bjorn, magnus.karlsson, maciej.fijalkowski, jonathan.lemon, davem,
	edumazet, kuba, pabeni, horms, ast, daniel, hawk, john.fastabend,
	yoong.siang.song, sdf, netdev, Michal Schmidt

When a new skb is allocated for transmitting an xsk descriptor, i.e., for
every non-multibuf descriptor or the first frag of a multibuf descriptor,
but the descriptor is later found to have invalid options set for the TX
metadata, the new skb is never freed. This can leak skbs until the send
buffer is full which makes sending more packets impossible.

Fix this by freeing the skb in the error path if we are currently dealing
with the first frag, i.e., an skb allocated in this iteration of
xsk_build_skb.

Fixes: 48eb03dd2630 ("xsk: Add TX timestamp and TX checksum offload support")
Reported-by: Michal Schmidt <mschmidt@redhat.com>
Signed-off-by: Felix Maurer <fmaurer@redhat.com>
---
 net/xdp/xsk.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 1140b2a120ca..b57d5d2904eb 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -675,6 +675,8 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,
 		len = desc->len;
 
 		if (!skb) {
+			first_frag = true;
+
 			hr = max(NET_SKB_PAD, L1_CACHE_ALIGN(dev->needed_headroom));
 			tr = dev->needed_tailroom;
 			skb = sock_alloc_send_skb(&xs->sk, hr + len + tr, 1, &err);
@@ -685,12 +687,8 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,
 			skb_put(skb, len);
 
 			err = skb_store_bits(skb, 0, buffer, len);
-			if (unlikely(err)) {
-				kfree_skb(skb);
+			if (unlikely(err))
 				goto free_err;
-			}
-
-			first_frag = true;
 		} else {
 			int nr_frags = skb_shinfo(skb)->nr_frags;
 			struct page *page;
@@ -758,6 +756,9 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,
 	return skb;
 
 free_err:
+	if (first_frag && skb)
+		kfree_skb(skb);
+
 	if (err == -EOVERFLOW) {
 		/* Drop the packet */
 		xsk_set_destructor_arg(xs->skb);
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf] xsk: Free skb when TX metadata options are invalid
  2024-11-14 11:30 [PATCH bpf] xsk: Free skb when TX metadata options are invalid Felix Maurer
@ 2024-11-14 13:13 ` Toke Høiland-Jørgensen
  2024-11-14 18:39 ` Stanislav Fomichev
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Toke Høiland-Jørgensen @ 2024-11-14 13:13 UTC (permalink / raw)
  To: Felix Maurer, bpf
  Cc: bjorn, magnus.karlsson, maciej.fijalkowski, jonathan.lemon, davem,
	edumazet, kuba, pabeni, horms, ast, daniel, hawk, john.fastabend,
	yoong.siang.song, sdf, netdev, Michal Schmidt

Felix Maurer <fmaurer@redhat.com> writes:

> When a new skb is allocated for transmitting an xsk descriptor, i.e., for
> every non-multibuf descriptor or the first frag of a multibuf descriptor,
> but the descriptor is later found to have invalid options set for the TX
> metadata, the new skb is never freed. This can leak skbs until the send
> buffer is full which makes sending more packets impossible.
>
> Fix this by freeing the skb in the error path if we are currently dealing
> with the first frag, i.e., an skb allocated in this iteration of
> xsk_build_skb.
>
> Fixes: 48eb03dd2630 ("xsk: Add TX timestamp and TX checksum offload support")
> Reported-by: Michal Schmidt <mschmidt@redhat.com>
> Signed-off-by: Felix Maurer <fmaurer@redhat.com>

Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf] xsk: Free skb when TX metadata options are invalid
  2024-11-14 11:30 [PATCH bpf] xsk: Free skb when TX metadata options are invalid Felix Maurer
  2024-11-14 13:13 ` Toke Høiland-Jørgensen
@ 2024-11-14 18:39 ` Stanislav Fomichev
  2024-11-14 21:43 ` Martin KaFai Lau
  2024-11-15 23:10 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 6+ messages in thread
From: Stanislav Fomichev @ 2024-11-14 18:39 UTC (permalink / raw)
  To: Felix Maurer
  Cc: bpf, bjorn, magnus.karlsson, maciej.fijalkowski, jonathan.lemon,
	davem, edumazet, kuba, pabeni, horms, ast, daniel, hawk,
	john.fastabend, yoong.siang.song, sdf, netdev, Michal Schmidt

On 11/14, Felix Maurer wrote:
> When a new skb is allocated for transmitting an xsk descriptor, i.e., for
> every non-multibuf descriptor or the first frag of a multibuf descriptor,
> but the descriptor is later found to have invalid options set for the TX
> metadata, the new skb is never freed. This can leak skbs until the send
> buffer is full which makes sending more packets impossible.
> 
> Fix this by freeing the skb in the error path if we are currently dealing
> with the first frag, i.e., an skb allocated in this iteration of
> xsk_build_skb.
> 
> Fixes: 48eb03dd2630 ("xsk: Add TX timestamp and TX checksum offload support")
> Reported-by: Michal Schmidt <mschmidt@redhat.com>
> Signed-off-by: Felix Maurer <fmaurer@redhat.com>
> ---

Acked-by: Stanislav Fomichev <sdf@fomichev.me>

Reminds me of the following:
https://lore.kernel.org/netdev/ZNvB9AUzNIzwMW6+@google.com/#t

Maybe I need to try to cleanup this path. Too many corner cases so it's
impossible to get right :-(

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf] xsk: Free skb when TX metadata options are invalid
  2024-11-14 11:30 [PATCH bpf] xsk: Free skb when TX metadata options are invalid Felix Maurer
  2024-11-14 13:13 ` Toke Høiland-Jørgensen
  2024-11-14 18:39 ` Stanislav Fomichev
@ 2024-11-14 21:43 ` Martin KaFai Lau
  2024-11-15  2:22   ` Jakub Kicinski
  2024-11-15 23:10 ` patchwork-bot+netdevbpf
  3 siblings, 1 reply; 6+ messages in thread
From: Martin KaFai Lau @ 2024-11-14 21:43 UTC (permalink / raw)
  To: Felix Maurer, Jakub Kicinski
  Cc: bjorn, magnus.karlsson, maciej.fijalkowski, jonathan.lemon, davem,
	edumazet, kuba, pabeni, horms, ast, daniel, hawk, john.fastabend,
	yoong.siang.song, sdf, netdev, Michal Schmidt, bpf

On 11/14/24 3:30 AM, Felix Maurer wrote:
> When a new skb is allocated for transmitting an xsk descriptor, i.e., for
> every non-multibuf descriptor or the first frag of a multibuf descriptor,
> but the descriptor is later found to have invalid options set for the TX
> metadata, the new skb is never freed. This can leak skbs until the send
> buffer is full which makes sending more packets impossible.
> 
> Fix this by freeing the skb in the error path if we are currently dealing
> with the first frag, i.e., an skb allocated in this iteration of
> xsk_build_skb.

Acked-by: Martin KaFai Lau <martin.lau@kernel.org>

Jakub, can you help to take it directly to the net tree? Thanks!


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf] xsk: Free skb when TX metadata options are invalid
  2024-11-14 21:43 ` Martin KaFai Lau
@ 2024-11-15  2:22   ` Jakub Kicinski
  0 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2024-11-15  2:22 UTC (permalink / raw)
  To: Martin KaFai Lau
  Cc: Felix Maurer, bjorn, magnus.karlsson, maciej.fijalkowski,
	jonathan.lemon, davem, edumazet, pabeni, horms, ast, daniel, hawk,
	john.fastabend, yoong.siang.song, sdf, netdev, Michal Schmidt,
	bpf

On Thu, 14 Nov 2024 13:43:22 -0800 Martin KaFai Lau wrote:
> Jakub, can you help to take it directly to the net tree? Thanks!

Ack, will do!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf] xsk: Free skb when TX metadata options are invalid
  2024-11-14 11:30 [PATCH bpf] xsk: Free skb when TX metadata options are invalid Felix Maurer
                   ` (2 preceding siblings ...)
  2024-11-14 21:43 ` Martin KaFai Lau
@ 2024-11-15 23:10 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-11-15 23:10 UTC (permalink / raw)
  To: Felix Maurer
  Cc: bpf, bjorn, magnus.karlsson, maciej.fijalkowski, jonathan.lemon,
	davem, edumazet, kuba, pabeni, horms, ast, daniel, hawk,
	john.fastabend, yoong.siang.song, sdf, netdev, mschmidt

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 14 Nov 2024 12:30:05 +0100 you wrote:
> When a new skb is allocated for transmitting an xsk descriptor, i.e., for
> every non-multibuf descriptor or the first frag of a multibuf descriptor,
> but the descriptor is later found to have invalid options set for the TX
> metadata, the new skb is never freed. This can leak skbs until the send
> buffer is full which makes sending more packets impossible.
> 
> Fix this by freeing the skb in the error path if we are currently dealing
> with the first frag, i.e., an skb allocated in this iteration of
> xsk_build_skb.
> 
> [...]

Here is the summary with links:
  - [bpf] xsk: Free skb when TX metadata options are invalid
    https://git.kernel.org/netdev/net/c/0c0d0f42ffa6

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-11-15 23:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-14 11:30 [PATCH bpf] xsk: Free skb when TX metadata options are invalid Felix Maurer
2024-11-14 13:13 ` Toke Høiland-Jørgensen
2024-11-14 18:39 ` Stanislav Fomichev
2024-11-14 21:43 ` Martin KaFai Lau
2024-11-15  2:22   ` Jakub Kicinski
2024-11-15 23:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).