]>
Commit | Line | Data |
---|---|---|
a9fba688 SL |
1 | From 5c23cd9e25e811192c5daca46071464534414aad Mon Sep 17 00:00:00 2001 |
2 | From: Dust Li <dust.li@linux.alibaba.com> | |
3 | Date: Mon, 1 Apr 2019 16:04:53 +0800 | |
4 | Subject: tcp: fix a potential NULL pointer dereference in tcp_sk_exit | |
5 | ||
6 | [ Upstream commit b506bc975f60f06e13e74adb35e708a23dc4e87c ] | |
7 | ||
8 | When tcp_sk_init() failed in inet_ctl_sock_create(), | |
9 | 'net->ipv4.tcp_congestion_control' will be left | |
10 | uninitialized, but tcp_sk_exit() hasn't check for | |
11 | that. | |
12 | ||
13 | This patch add checking on 'net->ipv4.tcp_congestion_control' | |
14 | in tcp_sk_exit() to prevent NULL-ptr dereference. | |
15 | ||
16 | Fixes: 6670e1524477 ("tcp: Namespace-ify sysctl_tcp_default_congestion_control") | |
17 | Signed-off-by: Dust Li <dust.li@linux.alibaba.com> | |
18 | Signed-off-by: Eric Dumazet <edumazet@google.com> | |
19 | Signed-off-by: David S. Miller <davem@davemloft.net> | |
20 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
21 | --- | |
22 | net/ipv4/tcp_ipv4.c | 3 ++- | |
23 | 1 file changed, 2 insertions(+), 1 deletion(-) | |
24 | ||
25 | diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c | |
26 | index 30fdf891940b..11101cf8693b 100644 | |
27 | --- a/net/ipv4/tcp_ipv4.c | |
28 | +++ b/net/ipv4/tcp_ipv4.c | |
29 | @@ -2490,7 +2490,8 @@ static void __net_exit tcp_sk_exit(struct net *net) | |
30 | { | |
31 | int cpu; | |
32 | ||
33 | - module_put(net->ipv4.tcp_congestion_control->owner); | |
34 | + if (net->ipv4.tcp_congestion_control) | |
35 | + module_put(net->ipv4.tcp_congestion_control->owner); | |
36 | ||
37 | for_each_possible_cpu(cpu) | |
38 | inet_ctl_sock_destroy(*per_cpu_ptr(net->ipv4.tcp_sk, cpu)); | |
39 | -- | |
40 | 2.19.1 | |
41 |