mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 04:37:32 -04:00
wifi: cfg80211: validate rx/tx MLME callback frame lengths before access
cfg80211_rx_mlme_mgmt() and cfg80211_tx_mlme_mgmt() call tracepoints before rejecting frames shorter than the frame-control field. After that, they only require len >= 2 before dispatching into subtype handlers that assume their fixed fields are present. The frames that trip this are not shorter than 2 bytes; they are short relative to their subtype. mwifiex is a concrete in-tree example on the length side: mwifiex_process_mgmt_packet() only requires a 4-address ieee80211_hdr plus the 2-byte firmware length prefix before handing the frame to cfg80211_rx_mlme_mgmt(). After stripping the length prefix and removing addr4, pkt_len can be exactly 24: a bare 3-address management header with no reason-code body. The existing WARN_ON(len < 2) does not fire on such a frame, and cfg80211_process_deauth() then reads u.deauth.reason_code as a two-byte access starting at offset 24, immediately past the 24-byte buffer. Add a frame-control length gate, then validate each subtype's minimum frame size in an if/else-if chain that mirrors the dispatch logic. Trace only after the frame is known to be well-formed. Side effects of this change: - The WARN_ON(len < 2) is dropped. It only guarded the frame_control read, never the subtype fixed fields, and it does not fire on the frames that actually trigger the out-of-bounds read (which are >= 2). The len >= 2 check is kept as the guard before dereferencing frame_control, but without the warning: these are exported callbacks and a malformed frame from a driver should be dropped silently rather than backtraced. - cfg80211_tx_mlme_mgmt() previously routed every non-deauth subtype through disassociation handling; it now silently ignores unrecognised subtypes. Assisted-by: Codex:gpt-5.5 Assisted-by: Claude:claude-opus-4.8 Signed-off-by: Zhao Li <enderaoelyther@gmail.com> Link: https://patch.msgid.link/20260707025336.22557-1-enderaoelyther@gmail.com Signed-off-by: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
@@ -151,19 +151,35 @@ void cfg80211_rx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len)
|
||||
{
|
||||
struct wireless_dev *wdev = dev->ieee80211_ptr;
|
||||
struct ieee80211_mgmt *mgmt = (void *)buf;
|
||||
__le16 fc;
|
||||
|
||||
lockdep_assert_wiphy(wdev->wiphy);
|
||||
|
||||
trace_cfg80211_rx_mlme_mgmt(dev, buf, len);
|
||||
|
||||
if (WARN_ON(len < 2))
|
||||
if (len < sizeof(fc))
|
||||
return;
|
||||
|
||||
if (ieee80211_is_auth(mgmt->frame_control))
|
||||
fc = mgmt->frame_control;
|
||||
|
||||
if (ieee80211_is_auth(fc)) {
|
||||
if (len < offsetofend(struct ieee80211_mgmt, u.auth.status_code))
|
||||
return;
|
||||
} else if (ieee80211_is_deauth(fc)) {
|
||||
if (len < offsetofend(struct ieee80211_mgmt, u.deauth.reason_code))
|
||||
return;
|
||||
} else if (ieee80211_is_disassoc(fc)) {
|
||||
if (len < offsetofend(struct ieee80211_mgmt, u.disassoc.reason_code))
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
trace_cfg80211_rx_mlme_mgmt(dev, buf, len);
|
||||
|
||||
if (ieee80211_is_auth(fc))
|
||||
cfg80211_process_auth(wdev, buf, len);
|
||||
else if (ieee80211_is_deauth(mgmt->frame_control))
|
||||
else if (ieee80211_is_deauth(fc))
|
||||
cfg80211_process_deauth(wdev, buf, len, false);
|
||||
else if (ieee80211_is_disassoc(mgmt->frame_control))
|
||||
else
|
||||
cfg80211_process_disassoc(wdev, buf, len, false);
|
||||
}
|
||||
EXPORT_SYMBOL(cfg80211_rx_mlme_mgmt);
|
||||
@@ -216,15 +232,28 @@ void cfg80211_tx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len,
|
||||
{
|
||||
struct wireless_dev *wdev = dev->ieee80211_ptr;
|
||||
struct ieee80211_mgmt *mgmt = (void *)buf;
|
||||
__le16 fc;
|
||||
|
||||
lockdep_assert_wiphy(wdev->wiphy);
|
||||
|
||||
trace_cfg80211_tx_mlme_mgmt(dev, buf, len, reconnect);
|
||||
|
||||
if (WARN_ON(len < 2))
|
||||
if (len < sizeof(fc))
|
||||
return;
|
||||
|
||||
if (ieee80211_is_deauth(mgmt->frame_control))
|
||||
fc = mgmt->frame_control;
|
||||
|
||||
if (ieee80211_is_deauth(fc)) {
|
||||
if (len < offsetofend(struct ieee80211_mgmt, u.deauth.reason_code))
|
||||
return;
|
||||
} else if (ieee80211_is_disassoc(fc)) {
|
||||
if (len < offsetofend(struct ieee80211_mgmt, u.disassoc.reason_code))
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
trace_cfg80211_tx_mlme_mgmt(dev, buf, len, reconnect);
|
||||
|
||||
if (ieee80211_is_deauth(fc))
|
||||
cfg80211_process_deauth(wdev, buf, len, reconnect);
|
||||
else
|
||||
cfg80211_process_disassoc(wdev, buf, len, reconnect);
|
||||
|
||||
Reference in New Issue
Block a user