From: John Fastabend <john.fastabend@gmail.com>
To: wangyufen <wangyufen@huawei.com>, Cong Wang <xiyou.wangcong@gmail.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: Mon, 28 Feb 2022 19:44:08 -0800 [thread overview]
Message-ID: <621d96888e266_8c479208da@john.notmuch> (raw)
In-Reply-To: <43776e3f-08c0-5d1a-1c2b-dd6084a6de33@huawei.com>
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()
>
> >
> > Thanks.
> > .
I walked that code and fix LGTM as well.
Acked-by: John Fastabend <john.fastabend@gmail.com>
next prev parent reply other threads:[~2022-03-01 3:44 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 [this message]
2022-03-03 0:31 ` Cong Wang
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=621d96888e266_8c479208da@john.notmuch \
--to=john.fastabend@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=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=xiyou.wangcong@gmail.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).