linux-stable/net
Florian Westphal e3b887a9c1 netfilter: nft_set_pipapo: do not free live element
[ Upstream commit 3cfc9ec039 ]

Pablo reports a crash with large batches of elements with a
back-to-back add/remove pattern.  Quoting Pablo:

  add_elem("00000000") timeout 100 ms
  ...
  add_elem("0000000X") timeout 100 ms
  del_elem("0000000X") <---------------- delete one that was just added
  ...
  add_elem("00005000") timeout 100 ms

  1) nft_pipapo_remove() removes element 0000000X
  Then, KASAN shows a splat.

Looking at the remove function there is a chance that we will drop a
rule that maps to a non-deactivated element.

Removal happens in two steps, first we do a lookup for key k and return the
to-be-removed element and mark it as inactive in the next generation.
Then, in a second step, the element gets removed from the set/map.

The _remove function does not work correctly if we have more than one
element that share the same key.

This can happen if we insert an element into a set when the set already
holds an element with same key, but the element mapping to the existing
key has timed out or is not active in the next generation.

In such case its possible that removal will unmap the wrong element.
If this happens, we will leak the non-deactivated element, it becomes
unreachable.

The element that got deactivated (and will be freed later) will
remain reachable in the set data structure, this can result in
a crash when such an element is retrieved during lookup (stale
pointer).

Add a check that the fully matching key does in fact map to the element
that we have marked as inactive in the deactivation step.
If not, we need to continue searching.

Add a bug/warn trap at the end of the function as well, the remove
function must not ever be called with an invisible/unreachable/non-existent
element.

v2: avoid uneeded temporary variable (Stefano)

Fixes: 3c4287f620 ("nf_tables: Add set type for arbitrary concatenation of ranges")
Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-05-02 16:23:36 +02:00
..
6lowpan
9p 9p/net: fix possible memory leak in p9_check_errors() 2024-01-05 15:12:29 +01:00
802
8021q vlan: skip nested type that is not IFLA_VLAN_QOS_MAPPING 2024-02-23 08:41:55 +01:00
appletalk appletalk: Fix Use-After-Free in atalk_ioctl 2023-12-20 15:44:29 +01:00
atm atm: Fix Use-After-Free in do_vcc_ioctl 2023-12-20 15:44:28 +01:00
ax25
batman-adv batman-adv: Avoid infinite loop trying to resize local TT 2024-05-02 16:23:33 +02:00
bluetooth Bluetooth: SCO: Fix not validating setsockopt user input 2024-05-02 16:23:34 +02:00
bpf
bpfilter
bridge netfilter: validate user input for expected length 2024-04-13 12:59:25 +02:00
caif
can can: j1939: Fix UAF in j1939_sk_match_filter during setsockopt(SO_J1939_FILTER) 2024-02-23 08:42:29 +01:00
ceph
core bpf, sockmap: Prevent lock inversion deadlock in map delete elem 2024-04-13 12:59:25 +02:00
dcb
dccp
decnet
dns_resolver keys, dns: Fix size check of V1 server-list header 2024-01-25 14:37:50 -08:00
dsa
ethernet
ethtool ethtool: netlink: Add missing ethnl_ops_begin/complete 2024-01-25 14:37:56 -08:00
hsr hsr: Handle failures in module init 2024-03-26 18:22:03 -04:00
ieee802154
ife net: sched: ife: fix potential use-after-free 2024-01-05 15:12:24 +01:00
ipv4 netfilter: complete validation of user input 2024-05-02 16:23:34 +02:00
ipv6 netfilter: complete validation of user input 2024-05-02 16:23:34 +02:00
iucv net/iucv: fix the allocation size of iucv_path_table array 2024-03-26 18:21:46 -04:00
kcm net: kcm: fix incorrect parameter validation in the kcm_getsockopt) function 2024-03-26 18:21:54 -04:00
key
l2tp l2tp: fix incorrect parameter validation in the pppol2tp_getsockopt() function 2024-03-26 18:21:53 -04:00
l3mdev
lapb
llc llc: call sock_orphan() at release time 2024-02-23 08:42:17 +01:00
mac80211 wifi: mac80211: check/clear fast rx for non-4addr sta VLAN changes 2024-04-13 12:59:03 +02:00
mac802154 mac802154: fix llsec key resources release in mac802154_llsec_key_del 2024-04-13 12:58:25 +02:00
mpls
mptcp mptcp: don't account accept() of non-MPC client as fallback to TCP 2024-04-13 12:59:38 +02:00
ncsi net/ncsi: Fix netlink major/minor version numbers 2024-01-25 14:37:44 -08:00
netfilter netfilter: nft_set_pipapo: do not free live element 2024-05-02 16:23:36 +02:00
netlabel calipso: fix memory leak in netlbl_calipso_add_pass() 2024-01-25 14:37:40 -08:00
netlink netlink: Fix kernel-infoleak-after-free in __skb_datagram_iter 2024-03-06 14:37:48 +00:00
netrom netrom: Fix data-races around sysctl_net_busy_read 2024-03-15 10:48:17 -04:00
nfc nfc: nci: Fix uninit-value in nci_dev_up and nci_ntf_packet 2024-04-13 12:59:14 +02:00
nsh
openvswitch net: openvswitch: fix unwanted error log on timeout policy probing 2024-05-02 16:23:33 +02:00
packet packet: annotate data-races around ignore_outgoing 2024-03-26 18:22:03 -04:00
phonet
psample psample: Require 'CAP_NET_ADMIN' when joining "packets" group 2023-12-13 18:27:06 +01:00
qrtr net: qrtr: ns: Return 0 if server port is not present 2024-01-25 14:37:38 -08:00
rds net/rds: fix possible cp null dereference 2024-04-13 12:59:19 +02:00
rfkill net: rfkill: gpio: set GPIO direction 2024-01-05 15:12:28 +01:00
rose net/rose: fix races in rose_kill_by_device() 2024-01-05 15:12:24 +01:00
rxrpc rxrpc: Fix response to PING RESPONSE ACKs to a dead call 2024-02-23 08:42:20 +01:00
sched net/sched: act_skbmod: prevent kernel-infoleak 2024-04-13 12:59:26 +02:00
sctp
smc net/smc: reduce rtnl pressure in smc_pnet_create_pnetids_list() 2024-04-13 12:59:43 +02:00
strparser
sunrpc net: sunrpc: Fix an off by one in rpc_sockaddr2uaddr() 2024-03-26 18:22:01 -04:00
switchdev
tipc tipc: Check the bearer type before calling tipc_udp_nl_bearer_add() 2024-02-23 08:42:20 +01:00
tls tls: stop recv() if initial process_rx_list gave us non-DATA 2024-03-01 13:16:51 +01:00
unix af_unix: Fix garbage collector racing against connect() 2024-05-02 16:23:34 +02:00
vmw_vsock virtio/vsock: fix logic which reduces credit update messages 2024-01-25 14:37:45 -08:00
wimax
wireless wifi: nl80211: reject iftype change with mesh ID change 2024-03-06 14:37:49 +00:00
x25 net/x25: fix incorrect parameter validation in the x25_getsockopt() function 2024-03-26 18:21:54 -04:00
xdp xsk: validate user input for XDP_{UMEM|COMPLETION}_FILL_RING 2024-05-02 16:23:33 +02:00
xfrm xfrm: Avoid clang fortify warning in copy_to_user_tmpl() 2024-04-13 12:58:49 +02:00
compat.c
devres.c
Kconfig
Makefile
socket.c net: Save and restore msg_namelen in sock_sendmsg 2024-01-15 18:48:04 +01:00
sysctl_net.c