Commit acfa08d
ip_tunnel: fix use-after-free in ip_tunnel_lookup()
In the datapath, the ip_tunnel_lookup() is used and it internally uses
fallback tunnel device pointer, which is fb_tunnel_dev.
This pointer is protected by RTNL. It's not enough to be used
in the datapath.
So, this pointer would be used after an interface is deleted.
It eventually results in the use-after-free problem.
In order to avoid the problem, the new tunnel pointer variable is added,
which indicates a fallback tunnel device's tunnel pointer.
This is protected by both RTNL and RCU.
So, it's safe to be used in the datapath.
Test commands:
ip netns add A
ip netns add B
ip link add eth0 type veth peer name eth1
ip link set eth0 netns A
ip link set eth1 netns B
ip netns exec A ip link set lo up
ip netns exec A ip link set eth0 up
ip netns exec A ip link add gre1 type gre local 10.0.0.1 \
remote 10.0.0.2
ip netns exec A ip link set gre1 up
ip netns exec A ip a a 10.0.100.1/24 dev gre1
ip netns exec A ip a a 10.0.0.1/24 dev eth0
ip netns exec B ip link set lo up
ip netns exec B ip link set eth1 up
ip netns exec B ip link add gre1 type gre local 10.0.0.2 \
remote 10.0.0.1
ip netns exec B ip link set gre1 up
ip netns exec B ip a a 10.0.100.2/24 dev gre1
ip netns exec B ip a a 10.0.0.2/24 dev eth1
ip netns exec A hping3 10.0.100.2 -2 --flood -d 60000 &
ip netns del B
Splat looks like:
[ 133.319668][ C3] BUG: KASAN: use-after-free in ip_tunnel_lookup+0x9d6/0xde0
[ 133.343852][ C3] Read of size 4 at addr ffff8880b1701c84 by task hping3/1222
[ 133.344724][ C3]
[ 133.345002][ C3] CPU: 3 PID: 1222 Comm: hping3 Not tainted 5.7.0+ torvalds#591
[ 133.345814][ C3] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
[ 133.373336][ C3] Call Trace:
[ 133.374792][ C3] <IRQ>
[ 133.375205][ C3] dump_stack+0x96/0xdb
[ 133.375789][ C3] print_address_description.constprop.6+0x2cc/0x450
[ 133.376720][ C3] ? ip_tunnel_lookup+0x9d6/0xde0
[ 133.377431][ C3] ? ip_tunnel_lookup+0x9d6/0xde0
[ 133.378130][ C3] ? ip_tunnel_lookup+0x9d6/0xde0
[ 133.378851][ C3] kasan_report+0x154/0x190
[ 133.379494][ C3] ? ip_tunnel_lookup+0x9d6/0xde0
[ 133.380200][ C3] ip_tunnel_lookup+0x9d6/0xde0
[ 133.380894][ C3] __ipgre_rcv+0x1ab/0xaa0 [ip_gre]
[ 133.381630][ C3] ? rcu_read_lock_sched_held+0xc0/0xc0
[ 133.382429][ C3] gre_rcv+0x304/0x1910 [ip_gre]
[ ... ]
Fixes: c544193 ("GRE: Refactor GRE tunneling code.")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>1 parent 96144c5 commit acfa08d
2 files changed
+9
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
166 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
1059 | 1060 | | |
1060 | 1061 | | |
1061 | 1062 | | |
| 1063 | + | |
1062 | 1064 | | |
1063 | 1065 | | |
1064 | 1066 | | |
| |||
1074 | 1076 | | |
1075 | 1077 | | |
1076 | 1078 | | |
1077 | | - | |
1078 | 1079 | | |
| 1080 | + | |
| 1081 | + | |
1079 | 1082 | | |
1080 | 1083 | | |
1081 | 1084 | | |
| |||
1262 | 1265 | | |
1263 | 1266 | | |
1264 | 1267 | | |
| 1268 | + | |
| 1269 | + | |
1265 | 1270 | | |
1266 | 1271 | | |
1267 | 1272 | | |
| |||
0 commit comments