mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Jiawei Ye <jiawei.ye@foxmail.com>
Cc: edumazet@google.com, davem@davemloft.net, dsahern@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: Fix potential RCU dereference issue in tcp_assign_congestion_control
Date: Fri, 20 Sep 2024 11:35:39 +0200	[thread overview]
Message-ID: <20240920093539.GA8490@breakpoint.cc> (raw)
In-Reply-To: <tencent_2A17499A4FFA4D830F7D2F72A95A4ADAB308@qq.com>

Jiawei Ye <jiawei.ye@foxmail.com> wrote:
> In the `tcp_assign_congestion_control` function, the `ca->flags` is
> accessed after the RCU read-side critical section is unlocked. According
> to RCU usage rules, this is illegal. Reusing this pointer can lead to
> unpredictable behavior, including accessing memory that has been updated
> or causing use-after-free issues.
> 
> This possible bug was identified using a static analysis tool developed
> by myself, specifically designed to detect RCU-related issues.
> 
> To resolve this issue, the `rcu_read_unlock` call has been moved to the
> end of the function.
> 
> Signed-off-by: Jiawei Ye <jiawei.ye@foxmail.com>
> ---
> In another part of the file, `tcp_set_congestion_control` calls
> `tcp_reinit_congestion_control`, ensuring that the congestion control
> reinitialization process is protected by RCU. The
> `tcp_reinit_congestion_control` function contains operations almost
> identical to those in `tcp_assign_congestion_control`, but the former
> operates under full RCU protection, whereas the latter is only partially
> protected. The differing protection strategies between the two may
> warrant further unification.
> ---
>  net/ipv4/tcp_cong.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
> index 0306d257fa64..356a59d316e3 100644
> --- a/net/ipv4/tcp_cong.c
> +++ b/net/ipv4/tcp_cong.c
> @@ -223,13 +223,13 @@ void tcp_assign_congestion_control(struct sock *sk)
>  	if (unlikely(!bpf_try_module_get(ca, ca->owner)))
>  		ca = &tcp_reno;

After this, ca either has module refcount incremented, so it can't
go away anymore, or reno fallback was enabled (always bultin).

>  	icsk->icsk_ca_ops = ca;
> -	rcu_read_unlock();

Therefore its ok to rcu unlock here.

  reply	other threads:[~2024-09-20  9:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-20  9:08 Jiawei Ye
2024-09-20  9:35 ` Florian Westphal [this message]
2024-09-20 14:11   ` Eric Dumazet
2024-09-23  3:09     ` Jiawei Ye
2024-09-23  7:36       ` Eric Dumazet
2024-09-24  3:57         ` Jiawei Ye

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=20240920093539.GA8490@breakpoint.cc \
    --to=fw@strlen.de \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=jiawei.ye@foxmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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

Powered by JetHome