lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 20 Apr 2023 09:14:58 -0400
From:   Willem de Bruijn <willemdebruijn.kernel@...il.com>
To:     Kuniyuki Iwashima <kuniyu@...zon.com>,
        willemdebruijn.kernel@...il.com
Cc:     davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
        kuni1840@...il.com, kuniyu@...zon.com, netdev@...r.kernel.org,
        pabeni@...hat.com, syzkaller@...glegroups.com, willemb@...gle.com
Subject: Re: [PATCH v2 net] tcp/udp: Fix memleaks of sk and zerocopy skbs with
 TX timestamp.

> > > > 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;

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ