]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
tcp: only release congestion control if it has been initialized
authorPengcheng Yang <yangpc@wangsu.com>
Fri, 25 Oct 2024 08:45:44 +0000 (16:45 +0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 1 Nov 2024 01:22:48 +0000 (18:22 -0700)
Currently, when cleaning up congestion control, we always call the
release regardless of whether it has been initialized. There is no
need to release when closing TCP_LISTEN and TCP_CLOSE (close
immediately after socket()).

In this case, tcp_cdg calls kfree(NULL) in release without causing
an exception, but for some customized ca, this could lead to
unexpected exceptions. We need to ensure that init and release are
called in pairs.

Signed-off-by: Pengcheng Yang <yangpc@wangsu.com>
Link: https://patch.msgid.link/1729845944-6003-1-git-send-email-yangpc@wangsu.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/tcp.c
net/ipv4/tcp_cong.c

index 82cc4a5633ceeeb351e52280080a91607752ba7b..0d704bda6c416bd722223eb19bec5667df4e7bb7 100644 (file)
@@ -3336,7 +3336,7 @@ int tcp_disconnect(struct sock *sk, int flags)
        tp->window_clamp = 0;
        tp->delivered = 0;
        tp->delivered_ce = 0;
-       if (icsk->icsk_ca_ops->release)
+       if (icsk->icsk_ca_initialized && icsk->icsk_ca_ops->release)
                icsk->icsk_ca_ops->release(sk);
        memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv));
        icsk->icsk_ca_initialized = 0;
index 0306d257fa6461e1b5e0c3edf0a1173c7d819b4b..df758adbb445f2a8e60fdc56fe9fadbf0b93941b 100644 (file)
@@ -270,8 +270,9 @@ void tcp_cleanup_congestion_control(struct sock *sk)
 {
        struct inet_connection_sock *icsk = inet_csk(sk);
 
-       if (icsk->icsk_ca_ops->release)
+       if (icsk->icsk_ca_initialized && icsk->icsk_ca_ops->release)
                icsk->icsk_ca_ops->release(sk);
+       icsk->icsk_ca_initialized = 0;
        bpf_module_put(icsk->icsk_ca_ops, icsk->icsk_ca_ops->owner);
 }