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]
Message-ID: <j5piuelz2xt65bn42bxufmk4nmigvzjotbygwd5tin7t6cvrsj@gpon5o7px7tu>
Date: Mon, 20 Jan 2025 11:35:37 +0800
From: Jiayuan Chen <mrpre@....com>
To: Jakub Sitnicki <jakub@...udflare.com>
Cc: bpf@...r.kernel.org, john.fastabend@...il.com, netdev@...r.kernel.org, 
	martin.lau@...ux.dev, ast@...nel.org, edumazet@...gle.com, davem@...emloft.net, 
	dsahern@...nel.org, kuba@...nel.org, pabeni@...hat.com, linux-kernel@...r.kernel.org, 
	song@...nel.org, andrii@...nel.org, mhal@...x.co, yonghong.song@...ux.dev, 
	daniel@...earbox.net, xiyou.wangcong@...il.com, horms@...nel.org, corbet@....net, 
	eddyz87@...il.com, cong.wang@...edance.com, shuah@...nel.org, mykolal@...com, 
	jolsa@...nel.org, haoluo@...gle.com, sdf@...ichev.me, kpsingh@...nel.org, 
	linux-doc@...r.kernel.org
Subject: Re: [PATCH bpf v7 2/5] bpf: fix wrong copied_seq calculation

On Sat, Jan 18, 2025 at 11:29:04PM +0800, Jiayuan Chen wrote:
> On Sat, Jan 18, 2025 at 03:50:22PM +0100, Jakub Sitnicki wrote:
> > On Thu, Jan 16, 2025 at 10:05 PM +08, Jiayuan Chen wrote:
> > > 'sk->copied_seq' was updated in the tcp_eat_skb() function when the
> > > action of a BPF program was SK_REDIRECT. For other actions, like SK_PASS,
> > > +}
> > > +#endif /* CONFIG_BPF_STREAM_PARSER */
> > > +
> > >  int tcp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore)
> > >  {
> > >  	int family = sk->sk_family == AF_INET6 ? TCP_BPF_IPV6 : TCP_BPF_IPV4;
> > > @@ -681,6 +722,12 @@ int tcp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore)
> > >  
> > >  	/* Pairs with lockless read in sk_clone_lock() */
> > >  	sock_replace_proto(sk, &tcp_bpf_prots[family][config]);
> > > +#if IS_ENABLED(CONFIG_BPF_STREAM_PARSER)
> > > +	if (psock->progs.stream_parser && psock->progs.stream_verdict) {
> > > +		psock->copied_seq = tcp_sk(sk)->copied_seq;
> > > +		psock->read_sock = tcp_bpf_strp_read_sock;
> > 
> > Just directly set psock->strp.cb.read_sock to tcp_bpf_strp_read_sock.
> > Then we don't need this intermediate psock->read_sock callback, which
> > doesn't do anything useful.
> >
> Ok, I will do this.
> (BTW, I intended to avoid bringing "struct strparser" into tcp_bpf.c so I
> added a wrapper function instead in skmsg.c without calling it directly) 
> 
I find that tcp_bpf_update_proto is called before sk_psock_init_strp. Any
assignment of psock->cb.strp will be overwritten in sk_psock_init_strp.

May read_sock still needed. But we can avoid adding wrapper function by
assigning psock->read_sock to cb.read_sock directly like this:

--- a/net/core/skmsg.c
+++ b/net/core/skmsg.c
@@ -1137,10 +1137,11 @@ int sk_psock_init_strp(struct sock *sk, struct sk_psock *psock)
 {
        int ret;

-       static const struct strp_callbacks cb = {
+       struct strp_callbacks cb = {
                .rcv_msg        = sk_psock_strp_read,
                .read_sock_done = sk_psock_strp_read_done,
                .parse_msg      = sk_psock_strp_parse,
+               .read_sock      = psock->read_sock,
        };

        ret = strp_init(&psock->strp, sk, &cb);

---
Thanks


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ