mac80211: backport the handling of missing tailroom in SW crypto

mac80211_hwsim uploads CCMP and GCMP keys with
IEEE80211_KEY_FLAG_RESERVE_TAILROOM and encrypts each frame in software
from mac80211_hwsim_tx(). __ieee80211_xmit_fast() resizes the frame
without encryption tailroom, so a frame whose tailroom is shorter than
the MIC hits the check in ccmp_encrypt_skb() or gcmp_encrypt_skb() and
is dropped:

  WARNING: net/mac80211/wpa.c:462 at ccmp_encrypt_skb.isra.0+0x298/0x2b0
   ieee80211_crypto_ccmp_encrypt+0x3b/0x60
   ieee80211_encrypt_tx_skb+0x9e/0x130
   mac80211_hwsim_tx+0x7b8/0xb40
   ...
   __ieee80211_xmit_fast+0x237/0x3c0
   ieee80211_xmit_fast+0x181/0x1c0

A locally sent IPv6 UDP datagram keeps only the slack of its allocation
as tailroom, so mDNS over an MLD backhaul station loses datagrams this
way.

Backport commit 94ae426f03b7 ("wifi: mac80211: handle missing tailroom
in SW crypto") from wireless-next: software crypto expands a short tail
instead of dropping the frame. Refresh the context of its ieee80211_i.h
hunk for 7.2, where IEEE80211_ENCRYPT_TAILROOM is 18, and the line
numbers of the later patches that change ieee80211_i.h.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Felix Fietkau committed 2026-11-15 11:17:21 +00:00
1 parent 29278064eb
commit bdd7b094ac
18 files changed
+177 -26

No files matched your search

@@ -0,0 +1,151 @@
From 94ae426f03b7a57d02a514091d810e698158a627 Mon Sep 17 00:00:00 2001
From: Johannes Berg <johannes.berg@intel.com>
Date: Mon, 26 Oct 2026 12:48:35 +0100
Subject: [PATCH] wifi: mac80211: handle missing tailroom in SW crypto
The TX path reserves tailroom if crypto_tx_tailroom_needed_cnt is
non-zero, and key control paths make sure this is always set if
needed. However, this adds quite a bit of complexity and, in most
cases, latency to the key control paths.
In order to remove that latency (which is due to waiting for any
concurrent TX to complete while changing the counter), prepare
the software crypto path to just expand the tailroom if needed.
In most cases, this actually can't hit: new keys will mostly be
offloaded to hardware and then it's not needed, sometimes they
can't actually be used by the TX path at all, etc.
Reviewed-by: Miriam Rachel Korenblit <miriam.rachel.korenblit@intel.com>
Link: https://patch.msgid.link/20261026125145.3c660a7b6c10.I96121b2c2ee72fa9246796e2ed0793cd320dd1e4@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
net/mac80211/ieee80211_i.h | 11 +++++++++++
net/mac80211/wep.c | 4 ++--
net/mac80211/wpa.c | 38 +++++++++++++++++++++++---------------
3 files changed, 36 insertions(+), 17 deletions(-)
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -54,6 +54,17 @@ struct ieee80211_mesh_fast_tx;
#define IEEE80211_ENCRYPT_HEADROOM 8
#define IEEE80211_ENCRYPT_TAILROOM 18
+/* tailroom accounting can race with TX, expand if needed */
+static inline int ieee80211_crypto_tx_tailroom(struct sk_buff *skb, int tail)
+{
+ int tail_need = tail - skb_tailroom(skb);
+
+ if (!tail || likely(tail_need <= 0 && !skb_cloned(skb)))
+ return 0;
+
+ return pskb_expand_head(skb, 0, max(tail_need, 0), GFP_ATOMIC);
+}
+
/* power level hasn't been configured (or set to automatic) */
#define IEEE80211_UNSET_POWER_LEVEL INT_MIN
--- a/net/mac80211/wep.c
+++ b/net/mac80211/wep.c
@@ -3,7 +3,7 @@
* Software WEP encryption implementation
* Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
* Copyright 2003, Instant802 Networks, Inc.
- * Copyright (C) 2023 Intel Corporation
+ * Copyright (C) 2023, 2026 Intel Corporation
*/
#include <linux/netdevice.h>
@@ -137,7 +137,7 @@ int ieee80211_wep_encrypt(struct ieee802
size_t len;
u8 rc4key[3 + WLAN_KEY_LEN_WEP104];
- if (WARN_ON(skb_tailroom(skb) < IEEE80211_WEP_ICV_LEN))
+ if (ieee80211_crypto_tx_tailroom(skb, IEEE80211_WEP_ICV_LEN))
return -1;
iv = ieee80211_wep_add_iv(local, skb, keylen, keyidx);
--- a/net/mac80211/wpa.c
+++ b/net/mac80211/wpa.c
@@ -3,7 +3,7 @@
* Copyright 2002-2004, Instant802 Networks, Inc.
* Copyright 2008, Jouni Malinen <j@w1.fi>
* Copyright (C) 2016-2017 Intel Deutschland GmbH
- * Copyright (C) 2020-2023 Intel Corporation
+ * Copyright (C) 2020-2023, 2026 Intel Corporation
*/
#include <linux/netdevice.h>
@@ -45,9 +45,6 @@ ieee80211_tx_h_michael_mic_add(struct ie
if (skb->len < hdrlen)
return TX_DROP;
- data = skb->data + hdrlen;
- data_len = skb->len - hdrlen;
-
if (unlikely(info->flags & IEEE80211_TX_INTFL_TKIP_MIC_FAILURE)) {
/* Need to use software crypto for the test */
info->control.hw_key = NULL;
@@ -66,13 +63,18 @@ ieee80211_tx_h_michael_mic_add(struct ie
if (!info->control.hw_key)
tail += IEEE80211_TKIP_ICV_LEN;
- if (WARN(skb_tailroom(skb) < tail ||
- skb_headroom(skb) < IEEE80211_TKIP_IV_LEN,
- "mmic: not enough head/tail (%d/%d,%d/%d)\n",
- skb_headroom(skb), IEEE80211_TKIP_IV_LEN,
- skb_tailroom(skb), tail))
+ if (ieee80211_crypto_tx_tailroom(skb, tail))
+ return TX_DROP;
+
+ if (WARN(skb_headroom(skb) < IEEE80211_TKIP_IV_LEN,
+ "mmic: not enough head (%d/%d)\n",
+ skb_headroom(skb), IEEE80211_TKIP_IV_LEN))
return TX_DROP;
+ hdr = (struct ieee80211_hdr *)skb->data;
+ data = skb->data + hdrlen;
+ data_len = skb->len - hdrlen;
+
mic = skb_put(skb, MICHAEL_MIC_LEN);
if (tx->key->conf.flags & IEEE80211_KEY_FLAG_PUT_MIC_SPACE) {
@@ -215,8 +217,10 @@ static int tkip_encrypt_skb(struct ieee8
else
tail = IEEE80211_TKIP_ICV_LEN;
- if (WARN_ON(skb_tailroom(skb) < tail ||
- skb_headroom(skb) < IEEE80211_TKIP_IV_LEN))
+ if (ieee80211_crypto_tx_tailroom(skb, tail))
+ return -1;
+
+ if (WARN_ON(skb_headroom(skb) < IEEE80211_TKIP_IV_LEN))
return -1;
pos = skb_push(skb, IEEE80211_TKIP_IV_LEN);
@@ -459,8 +463,10 @@ static int ccmp_encrypt_skb(struct ieee8
else
tail = mic_len;
- if (WARN_ON(skb_tailroom(skb) < tail ||
- skb_headroom(skb) < IEEE80211_CCMP_HDR_LEN))
+ if (ieee80211_crypto_tx_tailroom(skb, tail))
+ return -1;
+
+ if (WARN_ON(skb_headroom(skb) < IEEE80211_CCMP_HDR_LEN))
return -1;
pos = skb_push(skb, IEEE80211_CCMP_HDR_LEN);
@@ -674,8 +680,10 @@ static int gcmp_encrypt_skb(struct ieee8
else
tail = IEEE80211_GCMP_MIC_LEN;
- if (WARN_ON(skb_tailroom(skb) < tail ||
- skb_headroom(skb) < IEEE80211_GCMP_HDR_LEN))
+ if (ieee80211_crypto_tx_tailroom(skb, tail))
+ return -1;
+
+ if (WARN_ON(skb_headroom(skb) < IEEE80211_GCMP_HDR_LEN))
return -1;
pos = skb_push(skb, IEEE80211_GCMP_HDR_LEN);
@@ -12,7 +12,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -112,6 +112,8 @@ ieee80211_sta_keep_active(struct sta_inf
@@ -123,6 +123,8 @@ ieee80211_sta_keep_active(struct sta_inf
return time_before_eq(jiffies, sta->airtime[ac].last_active + HZ / 10);
}
@@ -70,7 +70,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -1467,10 +1467,12 @@ struct ieee80211_local {
@@ -1478,10 +1478,12 @@ struct ieee80211_local {
spinlock_t handle_wake_tx_queue_lock;
u16 airtime_flags;
@@ -126,7 +126,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
}
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -2944,6 +2944,11 @@ u8 *ieee80211_get_bssid(struct ieee80211
@@ -2955,6 +2955,11 @@ u8 *ieee80211_get_bssid(struct ieee80211
extern const struct ethtool_ops ieee80211_ethtool_ops;
@@ -31,7 +31,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -100,6 +100,7 @@ enum ieee80211_status_data {
@@ -111,6 +111,7 @@ enum ieee80211_status_data {
IEEE80211_STATUS_TYPE_SMPS = 1,
IEEE80211_STATUS_TYPE_NEG_TTLM = 2,
IEEE80211_STATUS_TYPE_UHR_OMP = 3,
@@ -39,7 +39,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
IEEE80211_STATUS_SUBDATA_MASK = 0x1ff0,
};
@@ -578,6 +579,9 @@ struct ieee80211_if_managed {
@@ -589,6 +590,9 @@ struct ieee80211_if_managed {
unsigned int uapsd_max_sp_len;
u8 use_4addr;
@@ -33,7 +33,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
link_conf->enable_beacon = false;
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -2987,6 +2987,8 @@ int ieee80211_mgd_assoc_ml_reconf(struct
@@ -2998,6 +2998,8 @@ int ieee80211_mgd_assoc_ml_reconf(struct
struct cfg80211_ml_reconf_req *req);
void ieee80211_stop_mbssid(struct ieee80211_sub_if_data *sdata);
@@ -74,7 +74,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
}
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -1100,6 +1100,8 @@ struct ieee80211_link_data_ap {
@@ -1111,6 +1111,8 @@ struct ieee80211_link_data_ap {
/* to be used after channel switch. */
struct cfg80211_beacon_data *next_beacon;
@@ -83,7 +83,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
};
struct ieee80211_link_data {
@@ -2872,7 +2874,7 @@ void ieee80211_dfs_radar_detected_work(s
@@ -2883,7 +2885,7 @@ void ieee80211_dfs_radar_detected_work(s
int ieee80211_send_action_csa(struct ieee80211_sub_if_data *sdata,
struct cfg80211_csa_settings *csa_settings);
void ieee80211_recalc_sb_count(struct ieee80211_sub_if_data *sdata, u64 tsf);
@@ -262,7 +262,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
u64 color_bitmap, u8 link_id)
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -288,6 +288,8 @@ struct beacon_data {
@@ -299,6 +299,8 @@ struct beacon_data {
u8 cntdwn_current_counter;
struct cfg80211_mbssid_elems *mbssid_ies;
struct cfg80211_rnr_elems *rnr_ies;
@@ -271,7 +271,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
struct rcu_head rcu_head;
};
@@ -1091,6 +1093,34 @@ struct ieee80211_link_data_managed {
@@ -1102,6 +1104,34 @@ struct ieee80211_link_data_managed {
int mu_edca_last_param_set;
};
@@ -306,7 +306,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
struct ieee80211_link_data_ap {
struct beacon_data __rcu *beacon;
struct probe_resp __rcu *probe_resp;
@@ -1102,6 +1132,9 @@ struct ieee80211_link_data_ap {
@@ -1113,6 +1143,9 @@ struct ieee80211_link_data_ap {
struct cfg80211_beacon_data *next_beacon;
int dtim_count;
@@ -316,7 +316,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
};
struct ieee80211_link_data {
@@ -1128,6 +1161,8 @@ struct ieee80211_link_data {
@@ -1139,6 +1172,8 @@ struct ieee80211_link_data {
struct wiphy_delayed_work color_collision_detect_work;
u64 color_bitmap;
@@ -325,7 +325,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
/* context reservation -- protected with wiphy mutex */
struct ieee80211_chanctx *reserved_chanctx;
struct ieee80211_chan_req reserved;
@@ -2182,6 +2217,12 @@ void ieee80211_color_change_finalize_wor
@@ -2193,6 +2228,12 @@ void ieee80211_color_change_finalize_wor
void ieee80211_color_collision_detection_work(struct wiphy *wiphy,
struct wiphy_work *work);
@@ -291,7 +291,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
struct ieee80211_sub_if_data *sdata,
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -1121,6 +1121,8 @@ static inline u32 ieee80211_crit_update_
@@ -1132,6 +1132,8 @@ static inline u32 ieee80211_crit_update_
return (u64)val >> 32;
}
@@ -300,7 +300,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
struct ieee80211_link_data_ap {
struct beacon_data __rcu *beacon;
struct probe_resp __rcu *probe_resp;
@@ -1135,6 +1137,9 @@ struct ieee80211_link_data_ap {
@@ -1146,6 +1148,9 @@ struct ieee80211_link_data_ap {
/* IEEE80211_CRIT_UPDATE() */
atomic64_t crit_update;
@@ -42,7 +42,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
.del_tx_ts = ieee80211_del_tx_ts,
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -2262,6 +2262,14 @@ void ieee80211_recalc_txpower(struct iee
@@ -2273,6 +2273,14 @@ void ieee80211_recalc_txpower(struct iee
bool update_bss);
void ieee80211_recalc_offload(struct ieee80211_local *local);
@@ -24,7 +24,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -2269,6 +2269,7 @@ int ieee80211_set_scs(struct wiphy *wiph
@@ -2280,6 +2280,7 @@ int ieee80211_set_scs(struct wiphy *wiph
int ieee80211_set_mscs(struct wiphy *wiphy, struct net_device *dev,
const u8 *peer, struct cfg80211_mscs_desc *desc);
void ieee80211_sta_scs_free(struct sta_info *sta);
@@ -32,7 +32,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
/* link handling */
void ieee80211_link_setup(struct ieee80211_link_data *link);
@@ -2321,7 +2322,7 @@ void __ieee80211_xmit_fast(struct ieee80
@@ -2332,7 +2333,7 @@ void __ieee80211_xmit_fast(struct ieee80
struct sta_info *sta,
struct ieee80211_fast_tx *fast_tx,
struct sk_buff *skb, bool ampdu,
@@ -24,7 +24,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -341,6 +341,10 @@ struct ieee80211_if_ap {
@@ -352,6 +352,10 @@ struct ieee80211_if_ap {
bool multicast_to_unicast;
bool active;
@@ -35,7 +35,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
};
struct ieee80211_if_vlan {
@@ -2270,6 +2274,9 @@ int ieee80211_set_mscs(struct wiphy *wip
@@ -2281,6 +2285,9 @@ int ieee80211_set_mscs(struct wiphy *wip
const u8 *peer, struct cfg80211_mscs_desc *desc);
void ieee80211_sta_scs_free(struct sta_info *sta);
bool ieee80211_flow_classify(struct sta_info *sta, struct sk_buff *skb);
@@ -94,7 +94,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
struct ieee80211_sta *sta,
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -2272,6 +2272,7 @@ int ieee80211_set_scs(struct wiphy *wiph
@@ -2283,6 +2283,7 @@ int ieee80211_set_scs(struct wiphy *wiph
struct cfg80211_scs_result *res, u8 n_desc);
int ieee80211_set_mscs(struct wiphy *wiphy, struct net_device *dev,
const u8 *peer, struct cfg80211_mscs_desc *desc);
@@ -82,7 +82,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
struct ieee80211_sta *sta,
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -345,6 +345,7 @@ struct ieee80211_if_ap {
@@ -356,6 +356,7 @@ struct ieee80211_if_ap {
/* learned MSCS entries of every station of this BSS, and its VLANs */
struct rhashtable flow_tbl;
struct wiphy_delayed_work flow_gc_work;
@@ -41,7 +41,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
* @vif: &struct ieee80211_vif pointer from the add_interface callback.
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -1293,6 +1293,10 @@ struct ieee80211_sub_if_data {
@@ -1304,6 +1304,10 @@ struct ieee80211_sub_if_data {
struct wiphy_work activate_links_work;
u16 desired_active_links;
@@ -130,7 +130,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
}
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -2300,6 +2300,9 @@ static inline void ieee80211_vif_clear_l
@@ -2311,6 +2311,9 @@ static inline void ieee80211_vif_clear_l
void ieee80211_apvlan_link_setup(struct ieee80211_sub_if_data *sdata);
void ieee80211_apvlan_link_clear(struct ieee80211_sub_if_data *sdata);
@@ -32,7 +32,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -1768,6 +1768,7 @@ struct ieee80211_local {
@@ -1779,6 +1779,7 @@ struct ieee80211_local {
struct list_head roc_list;
struct wiphy_work hw_roc_start, hw_roc_done;
unsigned long hw_roc_start_time;
@@ -16,7 +16,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -2532,6 +2532,13 @@ static inline int __ieee80211_resume(str
@@ -2543,6 +2543,13 @@ static inline int __ieee80211_resume(str
/* utility functions/constants */
extern const void *const mac80211_wiphy_privid; /* for wiphy privid */