linux-stable/include/net
Fedor Pchelkin e8a1e58345 mac802154: fix llsec key resources release in mac802154_llsec_key_del
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>
2024-03-06 21:01:26 +01:00
..
9p
bluetooth Bluetooth: Make handle of hci_conn be unique 2023-10-23 11:03:20 -07:00
caif net: caif: Remove unused declaration cfsrvl_ctrlcmd() 2023-08-10 18:24:48 -07:00
iucv
mana Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2023-10-05 13:16:47 -07:00
netfilter net/sched: act_ct: Always fill offloading tuple iifidx 2023-11-08 17:47:08 -08:00
netns netfilter: conntrack: switch connlabels to atomic_t 2023-10-24 13:16:30 +02:00
nfc
page_pool page_pool: update document about fragment API 2023-10-23 19:14:49 -07:00
phonet
sctp sctp: Remove unused declaration sctp_backlog_migrate() 2023-08-10 19:31:52 -07:00
tc_act sched: act_ct: switch to per-action label counting 2023-10-25 10:24:04 +01:00
6lowpan.h
Space.h net: appletalk: remove cops support 2023-10-04 11:49:20 -07:00
act_api.h
addrconf.h
af_ieee802154.h
af_rxrpc.h
af_unix.h
af_vsock.h vsock: check for MSG_ZEROCOPY support on send 2023-10-15 13:19:42 +01:00
ah.h
amt.h
arp.h
atmclip.h
ax25.h
ax88796.h
bareudp.h
bond_3ad.h bonding: 3ad: Remove unused declaration bond_3ad_update_lacp_active() 2023-07-28 18:06:30 -07:00
bond_alb.h
bond_options.h
bonding.h bonding: fix macvlan over alb bond support 2023-08-24 10:07:13 +02:00
bpf_sk_storage.h
busy_poll.h net: invert the netdevice.h vs xdp.h dependency 2023-08-03 08:38:07 -07:00
calipso.h
cfg80211-wext.h
cfg80211.h wifi: cfg80211: Allow AP/P2PGO to indicate port authorization to peer STA/P2PClient 2023-10-23 12:50:44 +02:00
cfg802154.h mac802154: fix llsec key resources release in mac802154_llsec_key_del 2024-03-06 21:01:26 +01:00
checksum.h
cipso_ipv4.h
cls_cgroup.h
codel.h
codel_impl.h
codel_qdisc.h
compat.h
datalink.h
dcbevent.h
dcbnl.h
devlink.h devlink: convert most of devlink_fmsg_*() to return void 2023-10-20 11:34:51 +01:00
dropreason-core.h net/tcp: Add TCP-AO segments counters 2023-10-27 10:35:45 +01:00
dropreason.h net: openvswitch: add last-action drop reason 2023-08-14 08:01:06 +01:00
dsa.h net: dsa: Use conduit and user terms 2023-10-24 13:08:14 -07:00
dsa_stubs.h net: dsa: Use conduit and user terms 2023-10-24 13:08:14 -07:00
dsfield.h
dst.h ipv6: drop feature RTAX_FEATURE_ALLFRAG 2023-10-25 18:04:29 -07:00
dst_cache.h
dst_metadata.h
dst_ops.h net: remove unnecessary input parameter 'how' in ifdown function 2023-08-22 13:19:02 +02:00
erspan.h
esp.h
espintcp.h
ethoc.h
failover.h
fib_notifier.h
fib_rules.h
firewire.h
flow.h inet: shrink struct flowi_common 2023-11-02 09:31:02 +01:00
flow_dissector.h net: flow_dissector: Add IPSEC dissector 2023-08-02 10:09:31 +01:00
flow_offload.h flow_offload: Annotate struct flow_action_entry with __counted_by 2023-10-06 11:37:02 +01:00
fou.h
fq.h net: fq: Remove unused typedef fq_flow_get_default_t 2023-08-08 15:58:23 -07:00
fq_impl.h
garp.h
gen_stats.h
genetlink.h genetlink: add genlmsg_iput() API 2023-08-15 15:01:03 -07:00
geneve.h
gre.h
gro.h xfrm: Support GRO for IPv4 ESP in UDP encapsulation 2023-10-06 07:30:40 +02:00
gro_cells.h
gso.h
gtp.h
gue.h
handshake.h net/handshake: Add helpers for parsing incoming TLS Alerts 2023-07-28 14:07:59 -07:00
hwbm.h
icmp.h
ieee80211_radiotap.h wifi: radiotap: add bandwidth definition of EHT U-SIG 2023-10-12 15:14:27 +03:00
ieee802154_netdev.h mac802154: Handle association requests from peers 2023-11-20 11:43:03 +01:00
if_inet6.h ipv6: Annotate struct ip6_sf_socklist with __counted_by 2023-10-02 11:24:52 -07:00
ife.h
inet6_connection_sock.h
inet6_hashtables.h net: Fix slab-out-of-bounds in inet[6]_steal_sock 2023-08-15 13:57:51 -07:00
inet_common.h net: factor out __inet_listen_sk() helper 2023-08-14 07:06:13 +01:00
inet_connection_sock.h ipv6: drop feature RTAX_FEATURE_ALLFRAG 2023-10-25 18:04:29 -07:00
inet_dscp.h
inet_ecn.h
inet_frag.h
inet_hashtables.h net: Fix slab-out-of-bounds in inet[6]_steal_sock 2023-08-15 13:57:51 -07:00
inet_sock.h ipv6: drop feature RTAX_FEATURE_ALLFRAG 2023-10-25 18:04:29 -07:00
inet_timewait_sock.h tcp: add support for usec resolution in TCP TS values 2023-10-23 09:35:01 +01:00
inetpeer.h
ioam6.h
ip.h inet: lock the socket in ip_sock_set_tos() 2023-10-19 13:13:13 +02:00
ip6_checksum.h
ip6_fib.h net: fib: avoid warn splat in flow dissector 2023-08-31 12:33:03 +02:00
ip6_route.h ipv6: lockless IPV6_ADDR_PREFERENCES implementation 2023-09-19 18:21:44 +02:00
ip6_tunnel.h
ip_fib.h Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2023-10-05 13:16:47 -07:00
ip_tunnels.h ip_tunnels: use DEV_STATS_INC() 2023-09-06 06:05:59 +01:00
ip_vs.h
ipcomp.h
ipconfig.h
ipv6.h ipv6: rename and move ip6_dst_lookup_tunnel() 2023-10-23 08:48:57 +01:00
ipv6_frag.h
ipv6_stubs.h ipsec-next-2023-10-28 2023-10-30 14:36:57 -07:00
iw_handler.h wifi: wext: Remove unused declaration dev_get_wireless_info() 2023-08-22 21:40:40 +02:00
kcm.h
l3mdev.h
lag.h
lapb.h
lib80211.h
llc.h
llc_c_ac.h net: llc: Remove unused function declarations 2023-08-04 15:33:17 -07:00
llc_c_ev.h net: llc: Remove unused function declarations 2023-08-04 15:33:17 -07:00
llc_c_st.h
llc_conn.h
llc_if.h
llc_pdu.h
llc_s_ac.h
llc_s_ev.h
llc_s_st.h
llc_sap.h
lwtunnel.h lwt: Check LWTUNNEL_XMIT_CONTINUE strictly 2023-08-18 16:05:26 +02:00
mac80211.h wifi: mac80211: rename ieee80211_tx_status() to ieee80211_tx_status_skb() 2023-10-23 12:26:51 +02:00
mac802154.h
macsec.h net: macsec: indicate next pn update when offloading 2023-10-10 10:30:30 +02:00
mctp.h
mctpdevice.h
mip6.h
mld.h
mpls.h
mpls_iptunnel.h
mptcp.h mptcp: add struct mptcp_sched_ops 2023-08-22 17:31:18 -07:00
mrp.h
ncsi.h
ndisc.h ndisc: Remove unused ndisc_ifinfo_sysctl_strategy() declaration 2023-08-07 08:53:55 +01:00
neighbour.h neighbour: fix data-races around n->output 2023-10-01 17:14:37 +01:00
net_debug.h
net_failover.h
net_namespace.h net: treat possible_net_t net pointer as an RCU one and add read_pnet_rcu() 2023-10-18 09:23:01 +01:00
net_ratelimit.h
net_trackers.h
netdev_queues.h
netdev_rx_queue.h net: move struct netdev_rx_queue out of netdevice.h 2023-08-03 08:38:07 -07:00
netevent.h
netkit.h netkit, bpf: Add bpf programmable net device 2023-10-24 16:06:03 -07:00
netlabel.h
netlink.h netlink: make range pointers in policies const 2023-10-26 16:24:09 -07:00
netprio_cgroup.h
netrom.h
nexthop.h nexthop: Annotate struct nh_group with __counted_by 2023-10-06 10:50:34 +01:00
nl802154.h ieee802154: Give the user the association list 2023-11-20 11:43:45 +01:00
nsh.h
p8022.h net: 802: Remove unused function declarations 2023-08-04 15:33:50 -07:00
pie.h
ping.h
pkt_cls.h net, sched: Make tc-related drop reason more flexible 2023-10-16 10:07:36 -07:00
pkt_sched.h net_sched: constify qdisc_priv() 2023-10-01 13:20:36 +01:00
pptp.h
protocol.h
psample.h
psnap.h
raw.h
rawv6.h
red.h
regulatory.h wifi: cfg80211: save power spectral density(psd) of regulatory rule 2023-09-18 09:44:05 +02:00
request_sock.h
rose.h
route.h ipv4: rename and move ip_route_output_tunnel() 2023-10-16 09:57:52 +01:00
rpl.h
rsi_91x.h
rtnetlink.h net: validate veth and vxcan peer ifindexes 2023-08-20 11:40:03 +01:00
rtnh.h
sch_generic.h net, sched: Make tc-related drop reason more flexible 2023-10-16 10:07:36 -07:00
scm.h af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT. 2023-09-04 11:00:17 +01:00
secure_seq.h
seg6.h
seg6_hmac.h
seg6_local.h
selftests.h
slhc_vj.h
smc.h
snmp.h
sock.h for-6.7/io_uring-sockopt-2023-10-30 2023-11-01 11:16:34 -10:00
sock_reuseport.h
stp.h
strparser.h
switchdev.h net: switchdev: Remove unused declaration switchdev_port_fwd_mark_set() 2023-08-09 13:12:15 -07:00
tc_wrapper.h
tcp.h net/tcp: Wire up l3index to TCP-AO 2023-10-27 10:35:46 +01:00
tcp_ao.h net/tcp: fix possible out-of-bounds reads in tcp_hash_fail() 2023-11-03 11:38:14 +00:00
tcp_states.h
tcx.h bpf, tcx: Get rid of tcx_link_const 2023-10-23 15:01:53 -07:00
timewait_sock.h
tipc.h
tls.h tls: use fixed size for tls_offload_context_{tx,rx}.driver_state 2023-10-13 11:26:10 +01:00
tls_prot.h net/tls: Add TLS Alert definitions 2023-07-28 14:07:59 -07:00
tls_toe.h
transp_v6.h inet6: Remove unused function declaration udpv6_connect() 2023-08-01 15:06:27 -07:00
tso.h
tun_proto.h
udp.h udp/udplite: Remove unused function declarations udp{,lite}_get_port() 2023-08-07 08:53:55 +01:00
udp_tunnel.h ipv6: add new arguments to udp_tunnel6_dst_lookup() 2023-10-23 08:48:57 +01:00
udplite.h udplite: fix various data-races 2023-09-14 16:16:36 +02:00
vsock_addr.h
vxlan.h vxlan: Fix nexthop hash size 2023-08-02 10:58:26 +01:00
wext.h
x25.h
x25device.h
xdp.h bpf: expose information about supported xdp metadata kfunc 2023-09-15 11:26:58 -07:00
xdp_priv.h
xdp_sock.h xsk: Avoid starving the xsk further down the list 2023-10-24 11:55:36 +02:00
xdp_sock_drv.h
xfrm.h xfrm: pass struct net to xfrm_decode_session wrappers 2023-10-06 08:31:53 +02:00
xsk_buff_pool.h