android_kernel_samsung_sm8650/net
Florian Westphal d5e04556d4 UPSTREAM: netfilter: nft_set_pipapo: do not free live element
[ Upstream commit 3cfc9ec039af60dbd8965ae085b2c2ccdcfbe1cc ]

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)

Bug: 336735501
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>
(cherry picked from commit ebf7c9746f073035ee26209e38c3a1170f7b349a)
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: Ic9a48ac9ac0f9960fea9e066d9a0a9fb93f7b633
2024-05-07 13:49:00 +00:00
..
6lowpan
9p Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
802
8021q Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
appletalk Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
atm Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
ax25
batman-adv Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
bluetooth Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
bpf Revert "bpf, test_run: fix &xdp_frame misplacement for LIVE_FRAMES" 2023-03-17 08:50:32 +01:00
bpfilter
bridge Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
caif net: caif: Fix use-after-free in cfusbl_device_notify() 2023-03-17 08:50:24 +01:00
can Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
ceph UPSTREAM: libceph: harden msgr2.1 frame segment length checks 2023-10-24 17:39:17 +00:00
core Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
dcb net: dcb: choose correct policy to parse DCB_ATTR_BCN 2023-08-11 12:08:17 +02:00
dccp This is the 6.1.63 stable release 2023-11-27 16:59:46 +00:00
devlink devlink: remove reload failed checks in params get/set callbacks 2023-09-23 11:11:01 +02:00
dns_resolver Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
dsa net: dsa: sja1105: always enable the send_meta options 2023-07-19 16:22:06 +02:00
ethernet
ethtool Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
hsr hsr: Prevent use after free in prp_create_tagged_frame() 2023-11-20 11:52:15 +01:00
ieee802154
ife Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
ipv4 Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
ipv6 Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
iucv net/iucv: Fix size of interrupt data 2023-03-22 13:33:50 +01:00
kcm kcm: Fix error handling for SOCK_DGRAM in kcm_sendmsg(). 2023-09-19 12:28:10 +02:00
key net: af_key: fix sadb_x_filter validation 2023-08-23 17:52:32 +02:00
l2tp Revert "udp: annotate data-races around udp->encap_type" 2024-01-15 11:39:07 +00:00
l3mdev
lapb
llc llc: verify mac len before reading mac header 2023-11-20 11:52:15 +01:00
mac80211 Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
mac802154
mctp mctp: perform route lookups under a RCU read-side lock 2023-10-19 23:08:57 +02:00
mpls net: mpls: fix stale pointer if allocation fails during device rename 2023-02-22 12:59:53 +01:00
mptcp Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
ncsi Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
netfilter UPSTREAM: netfilter: nft_set_pipapo: do not free live element 2024-05-07 13:49:00 +00:00
netlabel Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
netlink Revert "drop_monitor: Require 'CAP_SYS_ADMIN' when joining "events" group" 2024-01-05 13:53:07 +00:00
netrom netrom: Deny concurrent connect(). 2023-09-13 09:42:35 +02:00
nfc Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
nsh net: nsh: Use correct mac_offset to unwind gso skb in nsh_gso_segment() 2023-05-24 17:32:45 +01:00
openvswitch Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
packet packet: Move reference count in packet_sock to atomic_long_t 2023-12-13 18:39:20 +01:00
phonet
psample psample: Require 'CAP_NET_ADMIN' when joining "packets" group 2023-12-13 18:39:11 +01:00
qrtr Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
rds net: prevent address rewrite in kernel_bind() 2023-10-19 23:08:50 +02:00
rfkill Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
rose Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
rxrpc rxrpc: Fix hard call timeout units 2023-05-17 11:53:35 +02:00
sched Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
sctp Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
smc Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
strparser
sunrpc Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
switchdev
tipc tipc: Fix kernel-infoleak due to uninitialized TLV value 2023-11-28 17:07:05 +00:00
tls UPSTREAM: net: tls: handle backlogging of crypto requests 2024-05-07 13:40:59 +00:00
unix UPSTREAM: af_unix: Fix garbage collector racing against connect() 2024-04-22 16:23:05 -07:00
vmw_vsock Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
wireless Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
x25 net/x25: Fix to not accept on connected socket 2023-02-09 11:28:13 +01:00
xdp xsk: Skip polling event check for unbound socket 2023-12-13 18:39:08 +01:00
xfrm Revert "xfrm: fix a data-race in xfrm_gen_index()" 2023-11-06 14:50:01 +00:00
compat.c use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
devres.c
Kconfig
Kconfig.debug
Makefile devlink: move code to a dedicated directory 2023-08-30 16:11:00 +02:00
socket.c Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
sysctl_net.c
TEST_MAPPING