sst-linux/include/net
Fedor Pchelkin dcd51ab42b mac802154: fix llsec key resources release in mac802154_llsec_key_del
[ Upstream commit e8a1e58345cf40b7b272e08ac7b32328b2543e40 ]

mac802154_llsec_key_del() can free resources of a key directly without
following the RCU rules for waiting before the end of a grace period. This
may lead to use-after-free in case llsec_lookup_key() is traversing the
list of keys in parallel with a key deletion:

refcount_t: addition on 0; use-after-free.
WARNING: CPU: 4 PID: 16000 at lib/refcount.c:25 refcount_warn_saturate+0x162/0x2a0
Modules linked in:
CPU: 4 PID: 16000 Comm: wpan-ping Not tainted 6.7.0 #19
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
RIP: 0010:refcount_warn_saturate+0x162/0x2a0
Call Trace:
 <TASK>
 llsec_lookup_key.isra.0+0x890/0x9e0
 mac802154_llsec_encrypt+0x30c/0x9c0
 ieee802154_subif_start_xmit+0x24/0x1e0
 dev_hard_start_xmit+0x13e/0x690
 sch_direct_xmit+0x2ae/0xbc0
 __dev_queue_xmit+0x11dd/0x3c20
 dgram_sendmsg+0x90b/0xd60
 __sys_sendto+0x466/0x4c0
 __x64_sys_sendto+0xe0/0x1c0
 do_syscall_64+0x45/0xf0
 entry_SYSCALL_64_after_hwframe+0x6e/0x76

Also, ieee802154_llsec_key_entry structures are not freed by
mac802154_llsec_key_del():

unreferenced object 0xffff8880613b6980 (size 64):
  comm "iwpan", pid 2176, jiffies 4294761134 (age 60.475s)
  hex dump (first 32 bytes):
    78 0d 8f 18 80 88 ff ff 22 01 00 00 00 00 ad de  x.......".......
    00 00 00 00 00 00 00 00 03 00 cd ab 00 00 00 00  ................
  backtrace:
    [<ffffffff81dcfa62>] __kmem_cache_alloc_node+0x1e2/0x2d0
    [<ffffffff81c43865>] kmalloc_trace+0x25/0xc0
    [<ffffffff88968b09>] mac802154_llsec_key_add+0xac9/0xcf0
    [<ffffffff8896e41a>] ieee802154_add_llsec_key+0x5a/0x80
    [<ffffffff8892adc6>] nl802154_add_llsec_key+0x426/0x5b0
    [<ffffffff86ff293e>] genl_family_rcv_msg_doit+0x1fe/0x2f0
    [<ffffffff86ff46d1>] genl_rcv_msg+0x531/0x7d0
    [<ffffffff86fee7a9>] netlink_rcv_skb+0x169/0x440
    [<ffffffff86ff1d88>] genl_rcv+0x28/0x40
    [<ffffffff86fec15c>] netlink_unicast+0x53c/0x820
    [<ffffffff86fecd8b>] netlink_sendmsg+0x93b/0xe60
    [<ffffffff86b91b35>] ____sys_sendmsg+0xac5/0xca0
    [<ffffffff86b9c3dd>] ___sys_sendmsg+0x11d/0x1c0
    [<ffffffff86b9c65a>] __sys_sendmsg+0xfa/0x1d0
    [<ffffffff88eadbf5>] do_syscall_64+0x45/0xf0
    [<ffffffff890000ea>] entry_SYSCALL_64_after_hwframe+0x6e/0x76

Handle the proper resource release in the RCU callback function
mac802154_llsec_key_del_rcu().

Note that if llsec_lookup_key() finds a key, it gets a refcount via
llsec_key_get() and locally copies key id from key_entry (which is a
list element). So it's safe to call llsec_key_put() and free the list
entry after the RCU grace period elapses.

Found by Linux Verification Center (linuxtesting.org).

Fixes: 5d637d5aab ("mac802154: add llsec structures and mutators")
Cc: stable@vger.kernel.org
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
Acked-by: Alexander Aring <aahringo@redhat.com>
Message-ID: <20240228163840.6667-1-pchelkin@ispras.ru>
Signed-off-by: Stefan Schmidt <stefan@datenfreihafen.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-04-03 15:19:31 +02:00
..
9p
bluetooth Bluetooth: hci_core: Fix missing instances using HCI_MAX_AD_LENGTH 2024-03-26 18:20:42 -04:00
caif
iucv
netfilter netfilter: let reset rules clean out conntrack entries 2024-03-06 14:45:08 +00:00
netns xfrm: fix a data-race in xfrm_gen_index() 2023-10-25 12:03:06 +02:00
nfc
phonet
sctp
tc_act
6lowpan.h
act_api.h
addrconf.h net: ipv6: support reporting otherwise unknown prefix flags in RTM_NEWPREFIX 2023-12-20 17:00:15 +01:00
af_ieee802154.h
af_rxrpc.h
af_unix.h af_unix: fix lockdep positive in sk_diag_dump_icons() 2024-02-05 20:13:02 +00:00
af_vsock.h
ah.h
amt.h
arp.h neighbour: switch to standard rcu, instead of rcu_bh 2023-10-10 22:00:42 +02:00
atmclip.h
ax25.h
ax88796.h
bareudp.h
bond_3ad.h
bond_alb.h
bond_options.h
bonding.h
bpf_sk_storage.h
busy_poll.h
calipso.h
cfg80211-wext.h
cfg80211.h wifi: cfg80211: fix kernel-doc for wiphy_delayed_work_flush() 2023-11-20 11:52:18 +01:00
cfg802154.h mac802154: fix llsec key resources release in mac802154_llsec_key_del 2024-04-03 15:19:31 +02:00
checksum.h
cipso_ipv4.h
cls_cgroup.h
codel_impl.h
codel_qdisc.h
codel.h
compat.h
datalink.h
dcbevent.h
dcbnl.h
devlink.h
dropreason.h
dsa.h
dsfield.h
dst_cache.h
dst_metadata.h
dst_ops.h ipv6: remove max_size check inline with ipv4 2024-01-15 18:54:51 +01:00
dst.h
erspan.h
esp.h
espintcp.h
ethoc.h
failover.h
fib_notifier.h
fib_rules.h
firewire.h
flow_dissector.h
flow_offload.h
flow.h inet: shrink struct flowi_common 2023-11-20 11:52:15 +01:00
fou.h
fq_impl.h
fq.h
garp.h
gen_stats.h
genetlink.h drop_monitor: Require 'CAP_SYS_ADMIN' when joining "events" group 2023-12-13 18:39:12 +01:00
geneve.h
gre.h
gro_cells.h
gro.h
gtp.h
gue.h
hwbm.h
icmp.h
ieee80211_radiotap.h
ieee802154_netdev.h
if_inet6.h net: ipv6: support reporting otherwise unknown prefix flags in RTM_NEWPREFIX 2023-12-20 17:00:15 +01:00
ife.h
ila.h
inet6_connection_sock.h
inet6_hashtables.h
inet_common.h ipv4, ipv6: Use splice_eof() to flush 2024-01-10 17:10:27 +01:00
inet_connection_sock.h tcp: make sure init the accept_queue's spinlocks once 2024-01-31 16:17:03 -08:00
inet_dscp.h
inet_ecn.h
inet_frag.h
inet_hashtables.h
inet_sock.h udp: fix busy polling 2024-01-31 16:17:04 -08:00
inet_timewait_sock.h
inetpeer.h
ioam6.h
ip6_checksum.h
ip6_fib.h ipv6: Remove in6addr_any alternatives. 2023-09-19 12:28:10 +02:00
ip6_route.h
ip6_tunnel.h
ip_fib.h ipv4/fib: send notify when delete source address routes 2023-10-25 12:03:11 +02:00
ip_tunnels.h ip_tunnels: use DEV_STATS_INC() 2023-09-19 12:28:03 +02:00
ip_vs.h
ip.h ipmr: fix kernel panic when forwarding mcast packets 2024-02-05 20:13:00 +00:00
ipcomp.h
ipconfig.h
ipv6_frag.h
ipv6_stubs.h bpf: Derive source IP addr via bpf_*_fib_lookup() 2024-03-06 14:45:20 +00:00
ipv6.h tcp: Fix bind() regression for v4-mapped-v6 wildcard address. 2023-09-19 12:28:10 +02:00
iw_handler.h
kcm.h
l3mdev.h
lag.h
lapb.h
lib80211.h
llc_c_ac.h
llc_c_ev.h
llc_c_st.h
llc_conn.h
llc_if.h
llc_pdu.h llc: Drop support for ETH_P_TR_802_2. 2024-01-31 16:17:04 -08:00
llc_s_ac.h
llc_s_ev.h
llc_s_st.h
llc_sap.h
llc.h
lwtunnel.h
mac80211.h mac80211: make ieee80211_tx_info padding explicit 2023-09-13 09:42:34 +02:00
mac802154.h
macsec.h net: macsec: indicate next pn update when offloading 2023-10-19 23:08:53 +02:00
mctp.h net: mctp: take ownership of skb in mctp_local_output 2024-03-06 14:45:06 +00:00
mctpdevice.h
mip6.h
mld.h
mpls_iptunnel.h
mpls.h
mptcp.h
mrp.h
ncsi.h
ndisc.h neighbour: switch to standard rcu, instead of rcu_bh 2023-10-10 22:00:42 +02:00
neighbour.h neighbour: fix data-races around n->output 2023-10-10 22:00:42 +02:00
net_debug.h
net_failover.h
net_namespace.h
net_ratelimit.h
net_trackers.h
netevent.h
netlabel.h
netlink.h netlink: split up copies in the ack construction 2023-10-10 22:00:44 +02:00
netprio_cgroup.h
netrom.h
nexthop.h ipv6: remove nexthop_fib6_nh_bh() 2023-10-10 22:00:46 +02:00
nl802154.h
nsh.h
p8022.h
page_pool.h
pie.h
ping.h
pkt_cls.h
pkt_sched.h
pptp.h
protocol.h
psample.h
psnap.h
raw.h
rawv6.h
red.h
regulatory.h
request_sock.h
rose.h
route.h
rpl.h
rsi_91x.h
rtnetlink.h
rtnh.h
sch_generic.h
scm.h
secure_seq.h
seg6_hmac.h
seg6_local.h
seg6.h
selftests.h
slhc_vj.h
smc.h
snmp.h
sock_reuseport.h
sock.h udp: fix busy polling 2024-01-31 16:17:04 -08:00
Space.h
stp.h
strparser.h
switchdev.h net: bridge: switchdev: Skip MDB replays of deferred events on offload 2024-03-01 13:26:35 +01:00
tcp_states.h
tcp.h mptcp: fix lockless access in subflow ULP diag 2024-03-01 13:26:34 +01:00
timewait_sock.h
tipc.h
tls_toe.h
tls.h tls: fix race between async notify and socket close 2024-02-23 09:12:31 +01:00
transp_v6.h
tso.h
tun_proto.h
udp_tunnel.h udp: lockless UDP_ENCAP_L2TPINUDP / UDP_GRO 2024-01-10 17:10:28 +01:00
udp.h ipv4, ipv6: Use splice_eof() to flush 2024-01-10 17:10:27 +01:00
udplite.h
vsock_addr.h
vxlan.h
wext.h
x25.h
x25device.h
xdp_priv.h
xdp_sock_drv.h
xdp_sock.h
xdp.h
xfrm.h
xsk_buff_pool.h