From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 428F042BC4C for ; Tue, 28 Jul 2026 12:55:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785243316; cv=none; b=jR0AzTukQ9H3Wo8j5BfTWzYT+wSJvA5psmiqV2RSer299xcAUX3zPjH7HD8DMdjEzDa/leDxGJSZn8tAcKV7yVPC03qRkmAARNcJEapEP7ar5cDH0btnFMzAX5t6EaZBxL1fxbkhwzLwECGuxoHJPW1FRm1cwI1iFXW6awquV6g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785243316; c=relaxed/simple; bh=bCImW5FveOgLSFMnd3wYiHnrEIorbTiPRBOU3dDrN38=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fs0rwjIlLpYuKgs6gkzEmE6koyuP32KWrFDtwO9t3DxR9MkRDo8+7uPDU9HOnDRYi42olzl1TZG92BjvghtnaUcU0YzpdVTC9H/JQSVRPW9SPlxG4lyPqNNgf2RlySIYHxmqX1RLegumWgN4A3OYFvrBlHyGW7w834u5Yu60Uic= 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=Qf9Chai5; arc=none smtp.client-ip=209.85.128.50 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="Qf9Chai5" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-49557167508so36140135e9.1 for ; Tue, 28 Jul 2026 05:55:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785243312; x=1785848112; 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:content-type; bh=3K1t70zaHBwvr/zd5QGdCAYVOIE1pLnv+eQf2gzB8Y8=; b=Qf9Chai5CLSPFKHqzb054ngzSh2uKymBymacvVJHABedOsmISR+GNz3q2zQRGnzcLq Y6GD2ymN3zj3xqd9La8T+g/gS+T5I09/7Y8L5N5uTJqDVuJQT4I8iPFaMCq3HyDg6B/A Sg/fdYmOFyKDYhuwPMxPhFgFFpmt5asbDFovUIlVWpkTVOTVMrL8lqPjrQyyTzaVolH7 nSsERi7vHh3/MCjxO1GFqtg6TQRqE+Hsh38HcaW8yn7/4nM0KLq9ijuIKGqa/+rAv1sU 6Ad3hHSCZXuOyQ6BEu6kr34/Am1q8H5n4qjIypeqKVfEjeHYYAv4R7g1qm13j6yFVjEa 29sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785243312; x=1785848112; 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:content-type; bh=3K1t70zaHBwvr/zd5QGdCAYVOIE1pLnv+eQf2gzB8Y8=; b=lLFC9ZxgS8gN6wqvTNs3xQr4nxZ0D1fn7OY8YJLU0M69eWbmEXbmXfoA35cxhtQjNF 1PbFVkpePrU5leD5Nj1oc7zsA/aVNIrI50SFzIWKMc7Sth1R69ah0ldbIwwqqskJbTsZ 568z3ct6W6QR7s0LslT1kLpRx5EPD/PGqanJ0jERRrlpTbPSedh0gfj707Pw9zwKhl1J yhuNG9Ztheo0ShpmvM+dkEN9jqpTs883MeZJq4kjyRTBJaCwaxSRhPICuo5VczgKzFkH Lhhh4tU4hAz5TvabdwG5fVs7IftDw60aLVhzBht/azJzWub3cLTrDFMv+HurRreYKDfl jk6A== X-Forwarded-Encrypted: i=1; AHgh+Rpm0mjgnuMfBW8ppBXt8jC+9HG3KHVzliPWoawL5aVkgoVud2/DNASpqpehkTwlzTfTu21mMBhbEUP1ReE=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9o7bKduIqBOFkHvtf6TaDRyBKxCtx0tq2H2x8y+x2yMHbZO6P ftQFCmhNOzISm7RT8VY7M/926lrUHmFS1TAMhgIaFEqGwza3eXkP2AZc X-Gm-Gg: AR+sD10i6u0XvM+Wsk0ItNpcmHbc4iPiR+sNFeHbcnSgmY/3OyoRGuLKdLEXxAxl3bN 3/9tVeQq4RhyXTQZ/4QUDpTxMamDj+VxdvHsS8jiyFbMaguPMqCAleyGW8r32QkAikQnf73Fb8s XC5L3lHQqtxDxaeVqFGIr85eYQbPdHcgzRkmeeUcvUfctgGQr4/a5/+zBoZgFeGHep7lXzmOuP0 TKwQ7TSIx7rVnQODilFvyjSjjabj8GMOzzMmyhLgF5s/pu8QsKErMf4gxM+3kuG+FwGbSMr5Wnt xA4d0UiTaoDC5Ek3HCrQxhgA9IVVMjkergksKqe5un4KKBkM2ec22FvuS0bWH92ZrR0SGz4jxrN Ie/qyTZe7A8A4v8IXuTtRYEmzx3tJ7yaLDpxz4MqZGyWiERmcNgV8TlTj7xmeJ6j+XGEXI79TMc 2m6pPzHCq0xmNpXQak+5oIwpFAXL7HzUndufpqS4fF3gOqZw2jK2VCwbI9O0E2L/fVfw== X-Received: by 2002:a05:600c:4744:b0:495:40f0:e77 with SMTP id 5b1f17b1804b1-496c6415054mr25043505e9.5.1785243312169; Tue, 28 Jul 2026 05:55:12 -0700 (PDT) Received: from fedora ([202.47.63.86]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-496c444304esm74096505e9.0.2026.07.28.05.55.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2026 05:55:11 -0700 (PDT) From: Muhammad Bilal To: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, stable@vger.kernel.org, Muhammad Bilal Subject: [PATCH v2 1/3] staging: rtl8723bs: fix OOB read / stack overflow in rtw_get_wps_attr() Date: Tue, 28 Jul 2026 17:54:54 +0500 Message-ID: <20260728125456.32359-2-meatuni001@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260728125456.32359-1-meatuni001@gmail.com> References: <20260728125456.32359-1-meatuni001@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 rtw_get_wps_attr() walks WPS attributes inside a WPS IE taken from a wireless management frame. For each candidate attribute it only checks that the fixed 4-byte attribute header (2-byte ID + 2-byte length) fits inside the IE: 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; attr_data_len (and therefore attr_len) is read directly from the wire and is never checked against the remaining bytes in the IE before being used as the size of: memcpy(buf_attr, attr_ptr, attr_len); Since attr_len is fully attacker controlled (0 to 65535+4), this is both a heap OOB read of wps_ie, and, more seriously, a stack buffer overflow at several call sites where buf_attr is a single-byte stack variable, e.g. rtw_get_wps_attr_content()'s callers passing WPS_ATTR_SELECTED_REGISTRAR into a stack "u8 sr"/"u8 selected_registrar" (drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c, drivers/staging/rtl8723bs/core/rtw_mlme_ext.c). A crafted WPS IE in a beacon or probe response processed during scanning can therefore smash the stack of the parsing thread. rtw_get_wps_attr_content() itself has no independent length check and simply trusts the attr_len it gets back from rtw_get_wps_attr(), so fixing the bound here also fixes that caller. The "attr_ptr + 4 > wps_ie + wps_ielen" header check above was added by commit 1463ca3ec6601 ("staging: rtl8723bs: fix OOB reads in rtw_get_sec_ie(), rtw_get_wapi_ie(), and rtw_get_wps_attr()"), which bounded the fixed header but never extended the check to cover the variable-length attribute data that follows it. Add that missing check before attr_len is used as a memcpy() length or accepted as a match. Fixes: 554c0a3abf216 ("staging: Add rtl8723bs sdio wifi driver") Cc: stable@vger.kernel.org Signed-off-by: Muhammad Bilal --- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c index 2fb5863dbeef..be374d222c55 100644 --- a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c +++ b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c @@ -733,6 +733,10 @@ u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_att u16 attr_data_len = get_unaligned_be16(attr_ptr + 2); u16 attr_len = attr_data_len + 4; + /* Reject attributes whose claimed length runs past the IE */ + if (attr_ptr + attr_len > wps_ie + wps_ielen) + break; + if (attr_id == target_attr_id) { target_attr_ptr = attr_ptr; -- 2.55.0