netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cong Wang <xiyou.wangcong@gmail.com>
To: wangyufen <wangyufen@huawei.com>
Cc: john.fastabend@gmail.com, daniel@iogearbox.net,
	jakub@cloudflare.com, lmb@cloudflare.com, davem@davemloft.net,
	bpf@vger.kernel.org, edumazet@google.com,
	yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org,
	ast@kernel.org, andrii@kernel.org, kafai@fb.com,
	songliubraving@fb.com, yhs@fb.com, kpsingh@kernel.org,
	netdev@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/4] bpf, sockmap: Fix memleak in sk_psock_queue_msg
Date: Wed, 2 Mar 2022 16:31:12 -0800	[thread overview]
Message-ID: <YiAMUECNKtephFSh@pop-os.localdomain> (raw)
In-Reply-To: <43776e3f-08c0-5d1a-1c2b-dd6084a6de33@huawei.com>

On Tue, Mar 01, 2022 at 09:49:12AM +0800, wangyufen wrote:
> 
> 在 2022/2/28 3:21, Cong Wang 写道:
> > On Fri, Feb 25, 2022 at 09:49:26AM +0800, Wang Yufen wrote:
> > > If tcp_bpf_sendmsg is running during a tear down operation we may enqueue
> > > data on the ingress msg queue while tear down is trying to free it.
> > > 
> > >   sk1 (redirect sk2)                         sk2
> > >   -------------------                      ---------------
> > > tcp_bpf_sendmsg()
> > >   tcp_bpf_send_verdict()
> > >    tcp_bpf_sendmsg_redir()
> > >     bpf_tcp_ingress()
> > >                                            sock_map_close()
> > >                                             lock_sock()
> > >      lock_sock() ... blocking
> > >                                             sk_psock_stop
> > >                                              sk_psock_clear_state(psock, SK_PSOCK_TX_ENABLED);
> > >                                             release_sock(sk);
> > >      lock_sock()	
> > >      sk_mem_charge()
> > >      get_page()
> > >      sk_psock_queue_msg()
> > >       sk_psock_test_state(psock, SK_PSOCK_TX_ENABLED);
> > >        drop_sk_msg()
> > >      release_sock()
> > > 
> > > While drop_sk_msg(), the msg has charged memory form sk by sk_mem_charge
> > > and has sg pages need to put. To fix we use sk_msg_free() and then kfee()
> > > msg.
> > > 
> > What about the other code path? That is, sk_psock_skb_ingress_enqueue().
> > I don't see skmsg is charged there.
> 
> sk_psock_skb_ingress_self() | sk_psock_skb_ingress()
>    skb_set_owner_r()
>       sk_mem_charge()
>    sk_psock_skb_ingress_enqueue()
> 
> The other code path skmsg is charged by skb_set_owner_r()->sk_mem_charge()
> 

skb_set_owner_r() charges skb, I was asking skmsg. ;) In
sk_psock_skb_ingress_enqueue(), the skmsg was initialized but not
actually charged, hence I was asking... From a second look, it seems
sk_mem_uncharge() is not called for sk_psock_skb_ingress_enqueue() where
msg->skb is clearly not NULL.

Also, you introduce an unnecessary sk_msg_init() from __sk_msg_free(),
because you call kfree(msg) after it.

Thanks.

  parent reply	other threads:[~2022-03-03  0:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-25  1:49 [PATCH bpf-next 0/4] bpf, sockmap: Fix memleaks and issues of mem charge/uncharge Wang Yufen
2022-02-25  1:49 ` [PATCH bpf-next 1/4] bpf, sockmap: Fix memleak in sk_psock_queue_msg Wang Yufen
2022-02-27 19:21   ` Cong Wang
2022-03-01  1:49     ` wangyufen
2022-03-01  3:44       ` John Fastabend
2022-03-03  0:31       ` Cong Wang [this message]
2022-02-25  1:49 ` [PATCH bpf-next 2/4] bpf, sockmap: Fix memleak in tcp_bpf_sendmsg while sk msg is full Wang Yufen
2022-03-01  4:02   ` John Fastabend
2022-03-01  7:05     ` wangyufen
2022-02-25  1:49 ` [PATCH bpf-next 3/4] bpf, sockmap: Fix more uncharged while msg has more_data Wang Yufen
2022-03-01  4:20   ` John Fastabend
2022-02-25  1:49 ` [PATCH bpf-next 4/4] bpf, sockmap: Fix double uncharge the mem of sk_msg Wang Yufen
2022-03-01  4:11   ` John Fastabend
2022-03-01  7:24     ` wangyufen

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=YiAMUECNKtephFSh@pop-os.localdomain \
    --to=xiyou.wangcong@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=jakub@cloudflare.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=lmb@cloudflare.com \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=wangyufen@huawei.com \
    --cc=yhs@fb.com \
    --cc=yoshfuji@linux-ipv6.org \
    /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;
as well as URLs for NNTP newsgroup(s).