From: John Fastabend <john.fastabend@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>,
John Fastabend <john.fastabend@gmail.com>,
bpf <bpf@vger.kernel.org>
Cc: Kashyap Sanidhya <sanidhya.kashyap@epfl.ch>,
rishabh.iyer@berkley.edu,
Daniel Borkmann <daniel@iogearbox.net>,
Jakub Sitnicki <jakub@cloudflare.com>
Subject: RE: [Bug Report] Packet drops after trimming skb using bpf_skb_adjust_room
Date: Thu, 04 Apr 2024 21:52:15 -0700 [thread overview]
Message-ID: <660f837f9e83a_50b8720828@john.notmuch> (raw)
In-Reply-To: <CAP01T74=OChcu8V2u3bSMas=Lh-y72Y+7my1djn-uSKygBoX+w@mail.gmail.com>
Kumar Kartikeya Dwivedi wrote:
> Hello John,
>
> For background, I have a sk_skb program where for certain flows, a
> subset of request handling logic (on Rx) that is typically done in
> user space is handed over to a BPF program for doing it in-kernel.
>
> Since the protocol is over TCP, I'm using sk_skb programs to handle
> these requests and generate responses from within the kernel. The user
> space application will decide which flow should be added to the
> sockmap on socket accept and then let it be handled in the kernel for
> some of the request types.
>
> However, when generating replies and trimming away extra bytes in the
> packet by using bpf_skb_adjust_room, I see packet drops because the
> strp_msg->full_len is not updated unless tls_sw_has_ctx_rx is true for
> the socket. Removing that condition makes everything work, but I am
> not sure that is the right fix.
>
> My understanding so far is that in sk_psock_backlog,
> sk_psock_handle_skb returns an error since the stm->full_len is not
> correct (and passed into it as len), and SK_PSOCK_TX_ENABLED gets
> cleared due to this error. Then, on the redirect side
> (sk_psock_skb_redirect), it does sock_drop because the test for the
> SK_PSOCK_TX_ENABLED flag fails, which does kfree_skb.
>
> I have attached a patch with a selftest (skb_adjust_room) that you can
> run to verify the problem. It should basically hang on the second read
> as the packet would be dropped by the kernel. The first read goes
> through fine. Applying the diff below allows the selftest to pass.
>
> I am not familiar with the code to know whether the fix below is
> correct, but it seems to resolve the problem for me (and I carried it
> for a while and ran my stuff on it until I got around to reporting
> this now).
>
> In case gmail screws up the formatting, I'm just removing the
> tls_sw_has_ctx_rx(skb->sk) conditional on the strp_msg->full_len
> update in sk_skb_adjust_room.
I think your analysis is correct and patch looks good. I'll study
a bit more tomorrow. It looks like I just messed it up there and
didn't consider the case of redirect in non-TLS case.
Gmail did fine pushing code through.
>
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 524adf1fa6d0..e3009d0f3352 100644
>
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -3622,11 +3622,7 @@ BPF_CALL_4(sk_skb_adjust_room, struct sk_buff
> *, skb, s32, len_diff,
>
> return -ENOMEM;
>
> __skb_pull(skb, len_diff_abs);
>
> }
>
> - if (tls_sw_has_ctx_rx(skb->sk)) {
> - struct strp_msg *rxm = strp_msg(skb);
> -
> - rxm->full_len += len_diff;
> - }
> + strp_msg(skb)->full_len += len_diff;
> return ret;
> }
>
> --
>
> Thanks!
next prev parent reply other threads:[~2024-04-05 4:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-04 0:22 [Bug Report] Packet drops after trimming skb using bpf_skb_adjust_room Kumar Kartikeya Dwivedi
2024-04-05 4:52 ` John Fastabend [this message]
2024-04-05 22:08 ` Kumar Kartikeya Dwivedi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=660f837f9e83a_50b8720828@john.notmuch \
--to=john.fastabend@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jakub@cloudflare.com \
--cc=memxor@gmail.com \
--cc=rishabh.iyer@berkley.edu \
--cc=sanidhya.kashyap@epfl.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox