From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB82D2AF1D for ; Wed, 15 Jul 2026 00:07:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784074062; cv=none; b=I+My3Gli4Jfx7eD2YxJVr8/sbqaJ/RMa/oIA9Nq1fG6bctTNNSauDOr9hOlqJiJQYAiOtT5OKjCyu9WTkN+cMKutUS8+Z9SSJJ2Mp42nSKs5l3lCDWy2YlaDNLFrIqknxaLGjnLa9yCrRyJ6Aa588TuFbm+ruKe3Ci3Rj2tvf2Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784074062; c=relaxed/simple; bh=2oJzpYT/JIm4y1Ink+PWW6ZSNvfjwbKmHRNkzMpDiSU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QF/SuGVeekt29o3n+D8UGLY+0LVZt6OgtM53zdFIyhVTupolXjyiC0JFqVMNhqK8ZTe68/zIC9mQVq1uUuyWMidF2h7Mm+pU3HcmXOO8pp3+dznrhzKzkJa09KNTPGzkWD/N8oy4q8X9R3AW9Vy7AMO1YMKsWyEUcuonaCYgv9E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UoX8D3UO; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UoX8D3UO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDE8A1F00A3A; Wed, 15 Jul 2026 00:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784074060; bh=IepWDl1cnp8hh4hW08lf89dJIVrX12Cymr8FS9H+xpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UoX8D3UOTVdL2TvjwKOjSXsWt5DFoDTdNm7OwmXtCrnwtosRPwRqiUWUNAcWpYAk3 ISkz9wexodwqwAZK3zHwU9GpK0h6feJKebud88azp/TwN7HlL5HUR2+393PRGTUAGt EkuxpED/1mdZjqSYTyL1ZjoZMiH/LaSOF3bjNYN6/R7fevnThcmZZLU3DGZuBJrscU mE7pRf6zpfrJTkSRiMY/uMhpZK5yBGi47j4Uz3v2Ul4Dh6+HuZr/4yeUet+ZF5Q7Um WQXbUcV1lzucJUukTwgaS1wMgMUSDbyL79b1V2eX18x9txgcV0NUchmrzi4qWAIW3u CNraLLdKQ7bgQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Alexandru Hossu , stable , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 6.18.y 3/3] staging: rtl8723bs: fix OOB reads in rtw_get_sec_ie(), rtw_get_wapi_ie(), and rtw_get_wps_attr() Date: Tue, 14 Jul 2026 20:07:36 -0400 Message-ID: <20260715000736.3730201-3-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260715000736.3730201-1-sashal@kernel.org> References: <2026071358-dragging-ricotta-7451@gregkh> <20260715000736.3730201-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Alexandru Hossu [ Upstream commit 1463ca3ec6601cbb097d8d87dbf5dcf1cb86a344 ] Three IE/attribute parsing functions have missing bounds checks. rtw_get_sec_ie() and rtw_get_wapi_ie() iterate over a raw IE buffer without verifying that the header bytes (tag + length) are within the remaining buffer before reading them. Additionally, rtw_get_sec_ie() compares the 4-byte WPA OUI at cnt+2 without checking that at least 6 bytes remain, and rtw_get_wapi_ie() compares a 4-byte WAPI OUI at cnt+6 without checking that at least 10 bytes remain. rtw_get_wps_attr() reads wps_ie[0] and wps_ie+2 unconditionally at entry, before verifying that wps_ielen is large enough to contain the 6-byte WPS IE header (element_id + length + 4-byte OUI). Inside the attribute loop, get_unaligned_be16() is called on attr_ptr and attr_ptr+2 without checking that 4 bytes remain in the buffer. Add a cnt+2 bounds check before each loop body in rtw_get_sec_ie() and rtw_get_wapi_ie(), guard each multi-byte comparison with a minimum IE length requirement, add a wps_ielen < 6 early return in rtw_get_wps_attr(), and add a 4-byte bounds check in its inner loop. Fixes: 554c0a3abf21 ("staging: Add rtl8723bs sdio wifi driver") Cc: stable Signed-off-by: Alexandru Hossu Link: https://patch.msgid.link/20260522004531.1038924-8-hossu.alexandru@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c index 0a8247d9207b93..01ab7fb5e5bc66 100644 --- a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c +++ b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c @@ -585,9 +585,14 @@ int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len) cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_); while (cnt < in_len) { + if (cnt + 2 > in_len) + break; + if (cnt + 2 + in_ie[cnt + 1] > in_len) + break; authmode = in_ie[cnt]; if (authmode == WLAN_EID_BSS_AC_ACCESS_DELAY && + in_ie[cnt + 1] >= 8 && (!memcmp(&in_ie[cnt + 6], wapi_oui1, 4) || !memcmp(&in_ie[cnt + 6], wapi_oui2, 4))) { if (wapi_ie) @@ -620,9 +625,14 @@ void rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_); while (cnt < in_len) { + if (cnt + 2 > in_len) + break; + if (cnt + 2 + in_ie[cnt + 1] > in_len) + break; authmode = in_ie[cnt]; if ((authmode == WLAN_EID_VENDOR_SPECIFIC) && + in_ie[cnt + 1] >= 4 && (!memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4))) { if (wpa_ie) memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt + 1] + 2); @@ -707,6 +717,9 @@ u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_att if (len_attr) *len_attr = 0; + if (wps_ielen < 6) + return attr_ptr; + if ((wps_ie[0] != WLAN_EID_VENDOR_SPECIFIC) || (memcmp(wps_ie + 2, wps_oui, 4))) { return attr_ptr; @@ -717,6 +730,8 @@ u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_att while (attr_ptr - wps_ie < wps_ielen) { /* 4 = 2(Attribute ID) + 2(Length) */ + if (attr_ptr + 4 > wps_ie + wps_ielen) + break; u16 attr_id = get_unaligned_be16(attr_ptr); u16 attr_data_len = get_unaligned_be16(attr_ptr + 2); u16 attr_len = attr_data_len + 4; -- 2.53.0