From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 338164A2E35 for ; Tue, 5 May 2026 17:38:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778002711; cv=none; b=bXxQHi8WCwK714FeK8RdbNrbPQvZ2yR/o4aiYIwlvDYYREhhw5H3/jHCT8ezAmDK7dpmG76cMeewPpLjB/iy+XoyXmxU3qFV9oz6lJoVYNN87yOV/ONRtSy1I7eenm1mcJRC02nYvHGz2I0LprJjX7A3fZDUiBZWp1gd0w+76XM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778002711; c=relaxed/simple; bh=2eHvbI1mk/aj/Zi5PxQSpJypU7yoSMe2lKX08aSATJw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ihi3JjP+PA4l9wFUv7vfWTi78wcy73UWaBFaeGZszx26T0rlRZ1d4Hr8zhj7Qj93vHbXK+LLeJ0tDTR98XD6qx78p56FpDGcrXtzSct45tVN8mCdThORVkXBAUl01fDDdxYrhXlXmMEatExsyJcPTZvA+715hCaID6JIs0oWeY8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pfmIFCfm; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pfmIFCfm" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4891f625344so1116465e9.0 for ; Tue, 05 May 2026 10:38:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778002708; x=1778607508; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3HzUgHbapU2iUW6a55uMohE0Ic8YmFRsZ+OhWqMaW50=; b=pfmIFCfmzM72O7XCdpnqQgo3xl6HU9m3N2NsszC6vAzYzvX6hKIbsfVZj6Kc0tvQ71 0u3bjyCyUOu65yh0+1sOi+/UNXLtpItEuTU/DxoeA262rW5x6uIW7xibCJDMXEJtE7xo 4dHwLcH0KvT1v4oSCptG6FemJ4gkuDQRoKV4MrX60NY/OKTiS1rv+qKf1Qfc2liqc/di M+LBMl9ZexnFMxh1niGJVgt/qF1RWANB7Ct/JPcDTwo+RPSAsvlOHYgUQSf/G0dc7CT5 B0KFlkB/NPDDQVsjaeaI19aGl94lx8NUQsfLPcE8yvXPTu/1L84gHYGWxlhfIE/xYsCC 0dKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778002708; x=1778607508; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=3HzUgHbapU2iUW6a55uMohE0Ic8YmFRsZ+OhWqMaW50=; b=N+i7cPMSbxKWCI4vVWQI+D5JAWxTsdHHlusWHFQdygynQNCGvQeflJ/WyL5XKnsyp3 Tr9bj/67v3cE7Krvqi3Sx7sOvzco3VdWKTBik4f0BO8UX8qYZDoZ2txpGW0mehTS6NXL A32hi3owdXI2rnY/O43O13YwnxDOdiwmnV8utRPslm4iMvKIbllRLsTCcnbQqZHlURnM TCAfg6b6812UaQe4B8levz0+UfJENHOhqss+wkSDHLOeC+ZQXLDCP+DCntv35M4zQcUI CdYM/aRYTIBvMALCgLfpCKwzyMMeDnxDFKptKxfnc9/CDe1ToyorV3LEdlnv8zYchDLd kAzw== X-Forwarded-Encrypted: i=1; AFNElJ+VXlZWaQfHN3U8uEZevTgIiOPz7yMkmDtXN4nrT8aCyN6Ntdzv24FPRewXAd1ezB+APnlll5+dklA1FGs=@vger.kernel.org X-Gm-Message-State: AOJu0YyFkv8OIPKPvZVBJuqDjWVvlwfwhnFzFvKpot1DuV6H9aEWu1JB tHqgczBPz+YRN9bi0fWdYfpHcNQ7iG5viXRwQ4Tx55yy1fHvVHMYkpw/FSMlVQ== X-Gm-Gg: AeBDievsRhPlLveRgK7rzLRuOt6ZliAgCD9cwC7pOKL3dWfhpAVozTFeresFA4dWGLL 1FFA2XkrrZr2+8JLeJSIpQ6WpyBeBrzZsY5x1+BAFl2r8tIG3DaWJuzEhiId4HhSlFJrwZwXEjN ezNrGiinBJhUjksz2AEbQbaH/sFlExRPFmIPBceGmcjbyZQRjxWTU/nlakNpA86AdW3wvRdyhS6 uw26QfQo1v5+zNHtrUjaQbzz/PbaAOPcLz/qP1j98hVR/vz8/UaqjUGhlX1qyBVha1N6+eNeMqL 75QNg2Ns67T7RL8G3I7qiPJE04g0HcOwzak5QaXxepNs1uGrMjD+O8mbpLqVDiLBPko7+i5hooT xsCGxSp/4qcW9AkeM8rgyZfq/LQ3JppekpUNQSMI+vRcmHJZcS10RqxD5R09zOC+O41a0WcVs5Y UYneAnpmRGhAX6g1cKpbQERj2xqegoQdgq47AsrHtbsh/Qi0C2Z6N3wt7Cq7rPAmP7edRrWVFIF ERIIgIffBnN9niNn1GkrQLwRzinIlgg+WsgKhNuy4Ox5QF0OjJO49nXKJDo+XE0lT4mftY= X-Received: by 2002:a05:600c:3152:b0:489:1d7a:4537 with SMTP id 5b1f17b1804b1-48d1422bafamr75630445e9.3.1778002707536; Tue, 05 May 2026 10:38:27 -0700 (PDT) Received: from ahossu.localdomain ([82.78.232.184]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a82301ad1sm655473875e9.9.2026.05.05.10.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 10:38:27 -0700 (PDT) From: Alexandru Hossu To: gregkh@linuxfoundation.org Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, error27@gmail.com, luka.gejak@linux.dev, stable@vger.kernel.org Subject: [PATCH v4 2/3] staging: rtl8723bs: fix OOB reads in IE loops in issue_assocreq() and join_cmd_hdl() Date: Tue, 5 May 2026 19:38:17 +0200 Message-ID: <20260505173818.3674164-3-hossu.alexandru@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260505173818.3674164-1-hossu.alexandru@gmail.com> References: <2026050436-italics-clumsy-e83c@gregkh> <20260505173818.3674164-1-hossu.alexandru@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Five out-of-bounds read paths in the IE parsing loops of issue_assocreq() and join_cmd_hdl(): 1. Missing IE header bounds checks (both functions). Both loops advance by pIE->length + 2 per iteration but only guard on i < ie_length. When the buffer ends with a single element_id byte and no length byte, the loop reads pIE->length from one byte past the end of the buffer. Even when both header bytes are in bounds, pIE->length can extend the data window past ie_length, silently passing a truncated IE to handler functions. Add two guards at the top of each loop: break if fewer than sizeof(*pIE) bytes remain, and break if the declared IE payload extends past ie_length. 2. Vendor-specific OUI comparison reads 4 bytes past a possibly short IE payload (both functions). For WLAN_EID_VENDOR_SPECIFIC, the code calls memcmp(pIE->data, OUI, 4) on RTW_WPA_OUI, WMM_OUI, and WPS_OUI without first verifying that pIE->length is at least 4. A short IE at the end of the frame causes the memcmp to read into adjacent frame data. Add pIE->length >= 4 guard before the comparisons. 3. HT Capability IE memcpy reads sizeof(struct HT_caps_element) bytes from an IE that may be shorter (issue_assocreq only). The WLAN_EID_HT_CAPABILITY handler copies: memcpy(&pmlmeinfo->HT_caps, pIE->data, sizeof(struct HT_caps_element)); If pIE->length < sizeof(struct HT_caps_element), the memcpy reads beyond the end of the IE payload into adjacent frame data. Add a minimum length check and skip the IE if it is too short. 4. rtw_set_ie called with untrusted pIE->length for HT Capability (issue_assocreq only). After the memcpy the code passes pIE->length directly to rtw_set_ie() as the IE body length. If pIE->length exceeds sizeof(struct HT_caps_element), rtw_set_ie copies that many bytes from pmlmeinfo->HT_caps, reading past the end of the struct into adjacent fields. Use sizeof(struct HT_caps_element) instead. 5. HT Operation IE accessed without minimum length check (join_cmd_hdl only). The WLAN_EID_HT_OPERATION handler casts pIE->data to struct HT_info_element * and reads pht_info->infos[0] (offset 1) without verifying pIE->length >= sizeof(struct HT_info_element). A zero- or one-byte HT Operation IE causes an out-of-bounds read. Add a minimum length check and break if the IE is too short. Fixes: 554c0a3abf21 ("staging: Add rtl8723bs sdio wifi driver") Cc: stable@vger.kernel.org Signed-off-by: Alexandru Hossu --- Changes in v4: - Add pIE->length >= 4 guard before the 4-byte OUI memcmps in the WLAN_EID_VENDOR_SPECIFIC cases of both functions (sashiko review of v3). - In issue_assocreq() WLAN_EID_HT_CAPABILITY: add minimum length check (pIE->length < sizeof(struct HT_caps_element)) and use sizeof(struct HT_caps_element) instead of pIE->length in rtw_set_ie() to prevent OOB reads past the HT_caps struct (sashiko review of v3). - In join_cmd_hdl() WLAN_EID_HT_OPERATION: add minimum length check (pIE->length < sizeof(struct HT_info_element)) before casting pIE->data to struct HT_info_element * and reading infos[0] (sashiko review of v3). Changes in v3: - No code changes from v2. Changes in v2: - Add IE loop header and payload bounds checks for issue_assocreq() and join_cmd_hdl(). drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c index 5f00fe282d1b..0c130d0f9a48 100644 --- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c @@ -2925,13 +2925,18 @@ void issue_assocreq(struct adapter *padapter) /* vendor specific IE, such as WPA, WMM, WPS */ for (i = sizeof(struct ndis_802_11_fix_ie); i < pmlmeinfo->network.ie_length;) { + if (i + sizeof(*pIE) > pmlmeinfo->network.ie_length) + break; pIE = (struct ndis_80211_var_ie *)(pmlmeinfo->network.ies + i); + if (i + sizeof(*pIE) + pIE->length > pmlmeinfo->network.ie_length) + break; switch (pIE->element_id) { case WLAN_EID_VENDOR_SPECIFIC: - if ((!memcmp(pIE->data, RTW_WPA_OUI, 4)) || + if (pIE->length >= 4 && + ((!memcmp(pIE->data, RTW_WPA_OUI, 4)) || (!memcmp(pIE->data, WMM_OUI, 4)) || - (!memcmp(pIE->data, WPS_OUI, 4))) { + (!memcmp(pIE->data, WPS_OUI, 4)))) { vs_ie_length = pIE->length; if ((!padapter->registrypriv.wifi_spec) && (!memcmp(pIE->data, WPS_OUI, 4))) { /* Commented by Kurt 20110629 @@ -2953,8 +2958,10 @@ void issue_assocreq(struct adapter *padapter) case WLAN_EID_HT_CAPABILITY: if (padapter->mlmepriv.htpriv.ht_option) { if (!(is_ap_in_tkip(padapter))) { + if (pIE->length < sizeof(struct HT_caps_element)) + break; memcpy(&(pmlmeinfo->HT_caps), pIE->data, sizeof(struct HT_caps_element)); - pframe = rtw_set_ie(pframe, WLAN_EID_HT_CAPABILITY, pIE->length, (u8 *)(&(pmlmeinfo->HT_caps)), &(pattrib->pktlen)); + pframe = rtw_set_ie(pframe, WLAN_EID_HT_CAPABILITY, sizeof(struct HT_caps_element), (u8 *)(&(pmlmeinfo->HT_caps)), &(pattrib->pktlen)); } } break; @@ -2967,7 +2974,7 @@ void issue_assocreq(struct adapter *padapter) break; } - i += (pIE->length + 2); + i += sizeof(*pIE) + pIE->length; } if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK) @@ -5318,11 +5325,15 @@ u8 join_cmd_hdl(struct adapter *padapter, u8 *pbuf) /* sizeof(struct ndis_802_11_fix_ie) */ for (i = _FIXED_IE_LENGTH_; i < pnetwork->ie_length;) { + if (i + sizeof(*pIE) > pnetwork->ie_length) + break; pIE = (struct ndis_80211_var_ie *)(pnetwork->ies + i); + if (i + sizeof(*pIE) + pIE->length > pnetwork->ie_length) + break; switch (pIE->element_id) { case WLAN_EID_VENDOR_SPECIFIC:/* Get WMM IE. */ - if (!memcmp(pIE->data, WMM_OUI, 4)) + if (pIE->length >= 4 && !memcmp(pIE->data, WMM_OUI, 4)) WMM_param_handler(padapter, pIE); break; @@ -5335,7 +5346,12 @@ u8 join_cmd_hdl(struct adapter *padapter, u8 *pbuf) /* spec case only for cisco's ap because cisco's ap issue assoc rsp using mcs rate @40MHz or @20MHz */ { - struct HT_info_element *pht_info = (struct HT_info_element *)(pIE->data); + struct HT_info_element *pht_info; + + if (pIE->length < sizeof(struct HT_info_element)) + break; + + pht_info = (struct HT_info_element *)(pIE->data); if (pnetwork->configuration.ds_config <= 14) { if ((pregpriv->bw_mode & 0x0f) > CHANNEL_WIDTH_20) @@ -5366,7 +5382,7 @@ u8 join_cmd_hdl(struct adapter *padapter, u8 *pbuf) break; } - i += (pIE->length + 2); + i += sizeof(*pIE) + pIE->length; } /* check channel, bandwidth, offset and switch */ -- 2.53.0