lineage_android_kernel_xiao.../net
Liping Zhang 5170d210ef netfilter: nf_ct_ext: fix possible panic after nf_ct_extend_unregister
commit 9c3f3794926a997b1cab6c42480ff300efa2d162 upstream.

If one cpu is doing nf_ct_extend_unregister while another cpu is doing
__nf_ct_ext_add_length, then we may hit BUG_ON(t == NULL). Moreover,
there's no synchronize_rcu invocation after set nf_ct_ext_types[id] to
NULL, so it's possible that we may access invalid pointer.

But actually, most of the ct extends are built-in, so the problem listed
above will not happen. However, there are two exceptions: NF_CT_EXT_NAT
and NF_CT_EXT_SYNPROXY.

For _EXT_NAT, the panic will not happen, since adding the nat extend and
unregistering the nat extend are located in the same file(nf_nat_core.c),
this means that after the nat module is removed, we cannot add the nat
extend too.

For _EXT_SYNPROXY, synproxy extend may be added by init_conntrack, while
synproxy extend unregister will be done by synproxy_core_exit. So after
nf_synproxy_core.ko is removed, we may still try to add the synproxy
extend, then kernel panic may happen.

I know it's very hard to reproduce this issue, but I can play a tricky
game to make it happen very easily :)

Step 1. Enable SYNPROXY for tcp dport 1234 at FORWARD hook:
  # iptables -I FORWARD -p tcp --dport 1234 -j SYNPROXY
Step 2. Queue the syn packet to the userspace at raw table OUTPUT hook.
        Also note, in the userspace we only add a 20s' delay, then
        reinject the syn packet to the kernel:
  # iptables -t raw -I OUTPUT -p tcp --syn -j NFQUEUE --queue-num 1
Step 3. Using "nc 2.2.2.2 1234" to connect the server.
Step 4. Now remove the nf_synproxy_core.ko quickly:
  # iptables -F FORWARD
  # rmmod ipt_SYNPROXY
  # rmmod nf_synproxy_core
Step 5. After 20s' delay, the syn packet is reinjected to the kernel.

Now you will see the panic like this:
  kernel BUG at net/netfilter/nf_conntrack_extend.c:91!
  Call Trace:
   ? __nf_ct_ext_add_length+0x53/0x3c0 [nf_conntrack]
   init_conntrack+0x12b/0x600 [nf_conntrack]
   nf_conntrack_in+0x4cc/0x580 [nf_conntrack]
   ipv4_conntrack_local+0x48/0x50 [nf_conntrack_ipv4]
   nf_reinject+0x104/0x270
   nfqnl_recv_verdict+0x3e1/0x5f9 [nfnetlink_queue]
   ? nfqnl_recv_verdict+0x5/0x5f9 [nfnetlink_queue]
   ? nla_parse+0xa0/0x100
   nfnetlink_rcv_msg+0x175/0x6a9 [nfnetlink]
   [...]

One possible solution is to make NF_CT_EXT_SYNPROXY extend built-in, i.e.
introduce nf_conntrack_synproxy.c and only do ct extend register and
unregister in it, similar to nf_conntrack_timeout.c.

But having such a obscure restriction of nf_ct_extend_unregister is not a
good idea, so we should invoke synchronize_rcu after set nf_ct_ext_types
to NULL, and check the NULL pointer when do __nf_ct_ext_add_length. Then
it will be easier if we add new ct extend in the future.

Last, we use kfree_rcu to free nf_ct_ext, so rcu_barrier() is unnecessary
anymore, remove it too.

Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
Acked-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-08-24 17:12:18 -07:00
..
6lowpan
9p p9_client_readdir() fix 2017-05-03 08:36:38 -07:00
802
8021q net: 8021q: Fix one possible panic caused by BUG_ON in free_netdev 2017-07-05 14:40:16 +02:00
appletalk
atm
ax25
batman-adv
bluetooth Bluetooth: use constant time memory comparison for secret values 2017-07-27 15:07:58 -07:00
bridge bridge: mdb: fix leak on complete_info ptr on fail path 2017-07-21 07:42:17 +02:00
caif net: caif: Fix a sleep-in-atomic bug in cfpkt_create_pfx 2017-07-05 14:40:14 +02:00
can
ceph
core net: avoid skb_warn_bad_offload false positives on UFO 2017-08-12 19:31:22 -07:00
dcb
dccp dccp: fix a memleak for dccp_feat_init err process 2017-08-11 08:49:33 -07:00
decnet decnet: always not take dst->__refcnt when inserting dst into hash table 2017-07-05 14:40:16 +02:00
dns_resolver
dsa net: dsa: Check return value of phy_connect_direct() 2017-07-05 14:40:23 +02:00
ethernet
hsr
ieee802154
ipv4 udp: consistently apply ufo or fragmentation 2017-08-12 19:31:22 -07:00
ipv6 udp: consistently apply ufo or fragmentation 2017-08-12 19:31:22 -07:00
ipx ipx: call ipxitf_put() in ioctl error path 2017-05-25 15:44:41 +02:00
irda
iucv
kcm kcm: return immediately after copy_from_user() failure 2017-05-03 08:36:34 -07:00
key af_key: Add lock to key dump 2017-08-06 18:59:39 -07:00
l2tp l2tp: consider '::' as wildcard address in l2tp_ip6 socket lookup 2017-08-06 18:59:46 -07:00
l3mdev
lapb
llc
mac80211 mac80211: initialize SMPS field in HT capabilities 2017-07-05 14:40:25 +02:00
mac802154
mpls
ncsi
netfilter netfilter: nf_ct_ext: fix possible panic after nf_ct_extend_unregister 2017-08-24 17:12:18 -07:00
netlabel
netlink
netrom
nfc NFC: Add sockaddr length checks before accessing sa_family in bind handlers 2017-07-27 15:07:56 -07:00
openvswitch openvswitch: fix potential out of bound access in parse_ct 2017-08-11 08:49:32 -07:00
packet packet: fix tp_reserve race in packet_set_ring 2017-08-12 19:31:22 -07:00
phonet
qrtr
rds rds: tcp: use sock_create_lite() to create the accept socket 2017-07-21 07:42:19 +02:00
rfkill
rose
rxrpc rxrpc: Fix several cases where a padded len isn't checked in ticket decode 2017-06-29 13:00:31 +02:00
sched net: sched: set xt_tgchk_param par.nft_compat as 0 in ipt_init_target 2017-08-12 19:31:22 -07:00
sctp sctp: check af before verify address in sctp_addr_id2transport 2017-07-05 14:40:27 +02:00
strparser
sunrpc sunrpc: use constant time memory comparison for mac 2017-07-27 15:08:05 -07:00
switchdev
tipc tipc: allocate user memory with GFP_KERNEL flag 2017-07-05 14:40:27 +02:00
unix af_unix: Add sockaddr length checks before accessing sa_family in bind and connect handlers 2017-07-05 14:40:14 +02:00
vmw_vsock
wimax
wireless cfg80211: Check if NAN service ID is of expected size 2017-07-21 07:42:20 +02:00
x25
xfrm xfrm: Don't use sk_family for socket policy lookups 2017-08-06 18:59:48 -07:00
Kconfig
Makefile
compat.c
socket.c
sysctl_net.c