From: John Fastabend <john.fastabend@gmail.com>
To: Cong Wang <xiyou.wangcong@gmail.com>,
John Fastabend <john.fastabend@gmail.com>
Cc: Linux Kernel Network Developers <netdev@vger.kernel.org>,
bpf <bpf@vger.kernel.org>, Cong Wang <cong.wang@bytedance.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Jakub Sitnicki <jakub@cloudflare.com>,
Lorenz Bauer <lmb@cloudflare.com>
Subject: Re: [Patch bpf] udp: fix a memory leak in udp_read_sock()
Date: Tue, 18 May 2021 12:56:21 -0700 [thread overview]
Message-ID: <60a41be5629ab_10e7720815@john-XPS-13-9370.notmuch> (raw)
In-Reply-To: <CAM_iQpVCfGEA+TOfWvXYxJ1kk9z_thdbvRmZHxhWpuBMx9x2zg@mail.gmail.com>
Cong Wang wrote:
> On Mon, May 17, 2021 at 10:36 PM John Fastabend
> <john.fastabend@gmail.com> wrote:
> >
> > Cong Wang wrote:
> > > From: Cong Wang <cong.wang@bytedance.com>
> > >
> > > sk_psock_verdict_recv() clones the skb and uses the clone
> > > afterward, so udp_read_sock() should free the original skb after
> > > done using it.
> >
> > The clone only happens if sk_psock_verdict_recv() returns >0.
>
> Sure, in case of error, no one uses the original skb either,
> so still need to free it.
But the data is going to be dropped then. I'm questioning if this
is the best we can do or not. Its simplest sure, but could we
do a bit more work and peek those skbs or requeue them? Otherwise
if you cross memory limits for a bit your likely to drop these
unnecessarily.
>
> >
> > >
> > > Fixes: d7f571188ecf ("udp: Implement ->read_sock() for sockmap")
> > > Cc: John Fastabend <john.fastabend@gmail.com>
> > > Cc: Daniel Borkmann <daniel@iogearbox.net>
> > > Cc: Jakub Sitnicki <jakub@cloudflare.com>
> > > Cc: Lorenz Bauer <lmb@cloudflare.com>
> > > Signed-off-by: Cong Wang <cong.wang@bytedance.com>
> > > ---
> > > net/ipv4/udp.c | 2 ++
> > > 1 file changed, 2 insertions(+)
> > >
> > > diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> > > index 15f5504adf5b..e31d67fd5183 100644
> > > --- a/net/ipv4/udp.c
> > > +++ b/net/ipv4/udp.c
> > > @@ -1798,11 +1798,13 @@ int udp_read_sock(struct sock *sk, read_descriptor_t *desc,
> > > if (used <= 0) {
> > > if (!copied)
> > > copied = used;
> > > + kfree_skb(skb);
> >
> > This case is different from the TCP side, if there is an error
> > the sockmap side will also call kfree_skb(). In TCP side we peek
> > the skb because we don't want to drop it. On UDP side this will
> > just drop data on the floor. Its not super friendly, but its
> > UDP so we are making the assumption this is ok? We've tried
> > to remove all the drop data cases from TCP it would be nice
> > to not drop data on UDP side if we can help it. Could we
> > requeue or peek the UDP skb to avoid this?
>
> TCP is special because it supports splice() where we can
> do a partial read, so it needs to peek the skb, right? UDP only
> supports sockmap, where we always read a whole skb, so we
> do not need to peek here?
Its also about not dropping data. In TCP we should not drop
data at this point in the stack so if we get an error, ENOMEM
or otherwise, we need to ensure we keep the original skb.
>
> Thanks.
next prev parent reply other threads:[~2021-05-18 19:56 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-17 2:23 [Patch bpf] udp: fix a memory leak in udp_read_sock() Cong Wang
2021-05-17 16:22 ` Song Liu
2021-05-18 5:36 ` John Fastabend
2021-05-18 16:54 ` Cong Wang
2021-05-18 19:56 ` John Fastabend [this message]
2021-05-18 21:21 ` Cong Wang
2021-05-19 19:06 ` John Fastabend
2021-05-19 20:17 ` Cong Wang
2021-05-19 21:54 ` John Fastabend
2021-05-19 23:26 ` Cong Wang
2021-05-20 17:42 ` John Fastabend
2021-05-20 20:14 ` Cong Wang
2021-05-21 22:09 ` John Fastabend
2021-05-21 23:39 ` Cong Wang
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=60a41be5629ab_10e7720815@john-XPS-13-9370.notmuch \
--to=john.fastabend@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=cong.wang@bytedance.com \
--cc=daniel@iogearbox.net \
--cc=jakub@cloudflare.com \
--cc=lmb@cloudflare.com \
--cc=netdev@vger.kernel.org \
--cc=xiyou.wangcong@gmail.com \
/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