]>
Commit | Line | Data |
---|---|---|
1d34c510 SL |
1 | From b7cdf3e9c0f7bb62aec449dc3bd51e4b65d5c547 Mon Sep 17 00:00:00 2001 |
2 | From: Sasha Levin <sashal@kernel.org> | |
3 | Date: Tue, 7 May 2024 16:31:45 +0000 | |
4 | Subject: ipv6: fib6_rules: avoid possible NULL dereference in | |
5 | fib6_rule_action() | |
6 | ||
7 | From: Eric Dumazet <edumazet@google.com> | |
8 | ||
9 | [ Upstream commit d101291b2681e5ab938554e3e323f7a7ee33e3aa ] | |
10 | ||
11 | syzbot is able to trigger the following crash [1], | |
12 | caused by unsafe ip6_dst_idev() use. | |
13 | ||
14 | Indeed ip6_dst_idev() can return NULL, and must always be checked. | |
15 | ||
16 | [1] | |
17 | ||
18 | Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN PTI | |
19 | KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] | |
20 | CPU: 0 PID: 31648 Comm: syz-executor.0 Not tainted 6.9.0-rc4-next-20240417-syzkaller #0 | |
21 | Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024 | |
22 | RIP: 0010:__fib6_rule_action net/ipv6/fib6_rules.c:237 [inline] | |
23 | RIP: 0010:fib6_rule_action+0x241/0x7b0 net/ipv6/fib6_rules.c:267 | |
24 | Code: 02 00 00 49 8d 9f d8 00 00 00 48 89 d8 48 c1 e8 03 42 80 3c 20 00 74 08 48 89 df e8 f9 32 bf f7 48 8b 1b 48 89 d8 48 c1 e8 03 <42> 80 3c 20 00 74 08 48 89 df e8 e0 32 bf f7 4c 8b 03 48 89 ef 4c | |
25 | RSP: 0018:ffffc9000fc1f2f0 EFLAGS: 00010246 | |
26 | RAX: 0000000000000000 RBX: 0000000000000000 RCX: 1a772f98c8186700 | |
27 | RDX: 0000000000000003 RSI: ffffffff8bcac4e0 RDI: ffffffff8c1f9760 | |
28 | RBP: ffff8880673fb980 R08: ffffffff8fac15ef R09: 1ffffffff1f582bd | |
29 | R10: dffffc0000000000 R11: fffffbfff1f582be R12: dffffc0000000000 | |
30 | R13: 0000000000000080 R14: ffff888076509000 R15: ffff88807a029a00 | |
31 | FS: 00007f55e82ca6c0(0000) GS:ffff8880b9400000(0000) knlGS:0000000000000000 | |
32 | CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 | |
33 | CR2: 0000001b31d23000 CR3: 0000000022b66000 CR4: 00000000003506f0 | |
34 | DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 | |
35 | DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 | |
36 | Call Trace: | |
37 | <TASK> | |
38 | fib_rules_lookup+0x62c/0xdb0 net/core/fib_rules.c:317 | |
39 | fib6_rule_lookup+0x1fd/0x790 net/ipv6/fib6_rules.c:108 | |
40 | ip6_route_output_flags_noref net/ipv6/route.c:2637 [inline] | |
41 | ip6_route_output_flags+0x38e/0x610 net/ipv6/route.c:2649 | |
42 | ip6_route_output include/net/ip6_route.h:93 [inline] | |
43 | ip6_dst_lookup_tail+0x189/0x11a0 net/ipv6/ip6_output.c:1120 | |
44 | ip6_dst_lookup_flow+0xb9/0x180 net/ipv6/ip6_output.c:1250 | |
45 | sctp_v6_get_dst+0x792/0x1e20 net/sctp/ipv6.c:326 | |
46 | sctp_transport_route+0x12c/0x2e0 net/sctp/transport.c:455 | |
47 | sctp_assoc_add_peer+0x614/0x15c0 net/sctp/associola.c:662 | |
48 | sctp_connect_new_asoc+0x31d/0x6c0 net/sctp/socket.c:1099 | |
49 | __sctp_connect+0x66d/0xe30 net/sctp/socket.c:1197 | |
50 | sctp_connect net/sctp/socket.c:4819 [inline] | |
51 | sctp_inet_connect+0x149/0x1f0 net/sctp/socket.c:4834 | |
52 | __sys_connect_file net/socket.c:2048 [inline] | |
53 | __sys_connect+0x2df/0x310 net/socket.c:2065 | |
54 | __do_sys_connect net/socket.c:2075 [inline] | |
55 | __se_sys_connect net/socket.c:2072 [inline] | |
56 | __x64_sys_connect+0x7a/0x90 net/socket.c:2072 | |
57 | do_syscall_x64 arch/x86/entry/common.c:52 [inline] | |
58 | do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83 | |
59 | entry_SYSCALL_64_after_hwframe+0x77/0x7f | |
60 | ||
61 | Fixes: 5e5f3f0f8013 ("[IPV6] ADDRCONF: Convert ipv6_get_saddr() to ipv6_dev_get_saddr().") | |
62 | Signed-off-by: Eric Dumazet <edumazet@google.com> | |
63 | Reviewed-by: Simon Horman <horms@kernel.org> | |
64 | Reviewed-by: David Ahern <dsahern@kernel.org> | |
65 | Link: https://lore.kernel.org/r/20240507163145.835254-1-edumazet@google.com | |
66 | Signed-off-by: Jakub Kicinski <kuba@kernel.org> | |
67 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
68 | --- | |
69 | net/ipv6/fib6_rules.c | 6 +++++- | |
70 | 1 file changed, 5 insertions(+), 1 deletion(-) | |
71 | ||
72 | diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c | |
73 | index 55cd23b7a9357..cf9a44fb8243d 100644 | |
74 | --- a/net/ipv6/fib6_rules.c | |
75 | +++ b/net/ipv6/fib6_rules.c | |
76 | @@ -232,8 +232,12 @@ static int __fib6_rule_action(struct fib_rule *rule, struct flowi *flp, | |
77 | rt = pol_lookup_func(lookup, | |
78 | net, table, flp6, arg->lookup_data, flags); | |
79 | if (rt != net->ipv6.ip6_null_entry) { | |
80 | + struct inet6_dev *idev = ip6_dst_idev(&rt->dst); | |
81 | + | |
82 | + if (!idev) | |
83 | + goto again; | |
84 | err = fib6_rule_saddr(net, rule, flags, flp6, | |
85 | - ip6_dst_idev(&rt->dst)->dev); | |
86 | + idev->dev); | |
87 | ||
88 | if (err == -EAGAIN) | |
89 | goto again; | |
90 | -- | |
91 | 2.43.0 | |
92 |