From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Kuniyuki Iwashima <kuniyu@amazon.com>, willemdebruijn.kernel@gmail.com
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
kuni1840@gmail.com, kuniyu@amazon.com, netdev@vger.kernel.org,
pabeni@redhat.com, syzkaller@googlegroups.com,
willemb@google.com
Subject: Re: [PATCH v2 net] tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.
Date: Thu, 20 Apr 2023 09:14:58 -0400 [thread overview]
Message-ID: <64413ad24900e_303b5294c8@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <20230420033013.45693-1-kuniyu@amazon.com>
> > > > Actually, the skb_clone in __skb_tstamp_tx should already release
> > > > the reference on the ubuf.
> > > >
> > > > With the same mechanism that we rely on for packet sockets, e.g.,
> > > > in dev_queue_xmit_nit.
> > > >
> > > > skb_clone calls skb_orphan_frags calls skb_copy_ubufs for zerocopy
> > > > skbs. Which creates a copy of the data and calls skb_zcopy_clear.
> > > >
> > > > The skb that gets queued onto the error queue should not have a
> > > > reference on an ubuf: skb_zcopy(skb) should return NULL.
> > >
> > > Exactly, so how about this ?
> > >
> > > ---8<---
> > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> > > index 768f9d04911f..0fa0b2ac7071 100644
> > > --- a/net/core/skbuff.c
> > > +++ b/net/core/skbuff.c
> > > @@ -5166,6 +5166,9 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
> > > if (!skb)
> > > return;
> > >
> > > + if (skb_zcopy(skb) && skb_copy_ubufs(skb, GFP_ATOMIC))
> > > + return;
> > > +
> > > if (tsonly) {
> > > skb_shinfo(skb)->tx_flags |= skb_shinfo(orig_skb)->tx_flags &
> > > SKBTX_ANY_TSTAMP;
> > > ---8<---
> > >
> >
> > What I meant was that given this I don't understand how a packet
> > with ubuf references gets queued at all.
> >
> > __skb_tstamp_tx does not queue orig_skb. It either allocates a new
> > skb or calls skb = skb_clone(orig_skb).
> >
> > That existing call internally calls skb_orphan_frags and
> > skb_copy_ubufs.
>
> No, skb_orphan_frags() does not call skb_copy_ubufs() here because
> msg_zerocopy_alloc() sets SKBFL_DONT_ORPHAN for orig_skb.
>
> So, we need to call skb_copy_ubufs() explicitly if skb_zcopy(skb).
>
> >
> > So the extra test should not be needed. Indeed I would be surprised if
> > this triggers:
>
> And this actually triggers.
Oh right, I confused skb_orphan_frags and skb_orphan_frags_rx.
We need to add a call to that, the same approach used for looping in
__netif_receive_skb_core and packet sockets in deliver_skb and
dev_queue_xmit_nit.
@@ -5160,6 +5160,9 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
skb = alloc_skb(0, GFP_ATOMIC);
} else {
skb = skb_clone(orig_skb, GFP_ATOMIC);
+
+ if (skb_orphan_frags_rx(skb, GFP_ATOMIC))
+ return;
}
if (!skb)
return;
next prev parent reply other threads:[~2023-04-20 13:15 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-18 18:08 [PATCH v2 net] tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp Kuniyuki Iwashima
2023-04-18 18:33 ` Eric Dumazet
2023-04-18 18:44 ` Kuniyuki Iwashima
2023-04-18 19:04 ` Eric Dumazet
2023-04-18 19:25 ` Kuniyuki Iwashima
2023-04-19 9:34 ` Eric Dumazet
2023-04-19 14:16 ` Willem de Bruijn
2023-04-19 17:07 ` Kuniyuki Iwashima
2023-04-19 17:50 ` Willem de Bruijn
2023-04-19 22:43 ` Kuniyuki Iwashima
2023-04-20 2:20 ` Willem de Bruijn
2023-04-20 3:30 ` Kuniyuki Iwashima
2023-04-20 13:14 ` Willem de Bruijn [this message]
2023-04-20 16:46 ` Kuniyuki Iwashima
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=64413ad24900e_303b5294c8@willemb.c.googlers.com.notmuch \
--to=willemdebruijn.kernel@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=kuniyu@amazon.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=syzkaller@googlegroups.com \
--cc=willemb@google.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