From nobody Sat Jun 13 00:38:27 2026 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 7B5254C900A for ; Mon, 11 May 2026 18:53:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778525616; cv=none; b=Qy7daA1MrMDLILPcBmIRmASTO4Nxuu4SQhY4uArs38lvBoIWvOkQNJ5zv4SYnCx6LvD+bPOrRS++FWoiwGFJ+4ne8KJRFclkMS+6gCiWr1Ce/z5HI8TJbAjZb2yYeq2wFqnINbhimHQm3Xnqu1PNizBRPMansS3qbRSHINVaCT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778525616; c=relaxed/simple; bh=1nRE8JOy2JLcbHw8X50R2pYMpRN0QI4DGUktvzLnKfY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RKSpmW3V1LT4xf/5fe+8TOzQox6ASVOBbfPimD8Tx+I4zUWxwCq/flgGUDq4JIvfqZsW8O4jLgQ/NrM1Ww5lbYJQSq4PKBdvy83wOSDJXFQ8zutmx5a2emqiJ9U7mo8JjdPCpDr3coPPEjMrxmXq6UXV8nr4WOHgrQwsfH4SeJs= 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=EfIv0eZQ; arc=none smtp.client-ip=209.85.218.41 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="EfIv0eZQ" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-bd2087858c4so89011866b.0 for ; Mon, 11 May 2026 11:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778525613; x=1779130413; 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=IDY9dxT2zvqgp8lt00rKuBPK9aYcf3HfzHToSBInp3M=; b=EfIv0eZQluP4JXHfurul6SuqEBQjAPGhyghm0hs9Ue5BSJxisDcbuK168uOdpmpOaH ePrW6f5rkA0GEFFBuiKQzE2W8287ryluDYe4iXjjmp7CdvhETZ9Kvcb8oa/iSb1UrhZC 8IEs16qRUgY5oSkAjSlfUGsHBkJ9gdtJxYSXsPYyDn+Lh5t8H3UNeRX48/NQVCZoRukG Po4ZEKGYE7nWwS4ZS0NXbymOQ1A2e44XBf332ZQRgEpMCsmQXudkwnj5s1A235pRnSBB /ax8L2/wYjikBCeIVGeaO8jEWlgJwswiBHbrXxUx85b2vVXWdYLAYOEYpVpXrmGcaBbT 4MMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778525613; x=1779130413; 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=IDY9dxT2zvqgp8lt00rKuBPK9aYcf3HfzHToSBInp3M=; b=XlRAxxOVw2vfoygrTFKfG5CaAcpkxlIpidnAz/667Pb4/HCDXXYGw2NTlXkwROfb3D +BwNraL/QNBI+S0q27h6F61zrFUzoyPofVRzxDguTmhZX/hVwuEvT/4io1/LlLF0xGfM bQeXxnWFD8bKK+++yGDBHrvM7dQvhTyeUeBkFMJtG+CtWt9sxzpSPwvi6112WfNUmTEK LVNtp0FwHX1H3VnchqGur6htAvgMELLwT/o0FSbQrPf49dy9RNYTgMkazesSGAE2xMy5 Vh4pTVlmA4uixTF4m1H2OwXjnbqg18RjvrYPBTt241TFfjqk4Z9Prq+7j9sfm0bpl/JN rJwA== X-Forwarded-Encrypted: i=1; AFNElJ8YkTWTD8XDziEVId/pnxcM+fDPgouYsyKnChq56IW35TCRzE/RXWqMSAD5chP9uXaaaAMS5pD3Lc9Bfxc=@vger.kernel.org X-Gm-Message-State: AOJu0YwVJsEvvKUcSYQx6ikF0Zt0efs17jQQgRp2mwcCM2q8ktw1LAcb XP22+WWDTMulumDeFX3/UBeZ+El9aFJRilk3oWHZq1tI1bCn9VcIOfaxRw3KVw== X-Gm-Gg: Acq92OFA1ZbT+v/4YXINWv6rUtPo8CGXFt4fc17X5y67TXQq1o0Y3ifepssUd+5GR/A SG2pQnHvfU02ubyRVJs1dHn+9sgzHVq5Q90+PC+XGmT5MMJFq9Cl95BSGkgbTDsJQbhdCfsqC4p MuM3M9BU3F8Of2q89OKhXmADZjMy+6cv0LYX3PdiSkmHcz48DP6OFAdjeNTZ9INn0ZPIVR/L2pL 4m+Rg8Mz77R6DTBhfcToQLcYUFIJjO3NGVYmy0LbVOCgFLaGtv9MaCqpZfwFp1Jr5UnOWMoO5pJ 5fj0dOvSURV71Mr31FDLtkaYWfMop2N82m7VEJNV8TagBawlrwjD7W1kIrXsQJuJhZcPoRjUh1b za3/5xxhfYINBX9lu7ZYB0brw29pr3xZUF7A6fRNG9aw9pQjjE0DC+1ILWL95QLB9c5cuN1DQmJ jyBKt5ToYpaxZCt05E2I32P2OPFrF0fGx0uh6hn2+OfCMLsmhzLqOYN49WpQFbQj6Nv/Gf39IEL y2ywNhnAb5MpQUB30MvEHEfTKlR5K1qAUmRp05HkRk4J763FkHikIGPrqbSOt5h5E7/XQ4Zl4vw dL6hU3HXSVM= X-Received: by 2002:a17:907:d28:b0:bd1:fe0f:1c93 with SMTP id a640c23a62f3a-bd1fe0f2210mr131603366b.6.1778525612748; Mon, 11 May 2026 11:53:32 -0700 (PDT) Received: from ahossu.localdomain ([2a02:a420:22d2:4061:8cc7:b361:391f:af99]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-bcd7bf48623sm310803366b.48.2026.05.11.11.53.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 11:53:32 -0700 (PDT) From: Alexandru Hossu To: gregkh@linuxfoundation.org Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Alexandru Hossu , stable@vger.kernel.org Subject: [PATCH v8 1/1] staging: rtl8723bs: fix missing frame length checks in OnAuth() Date: Mon, 11 May 2026 20:53:14 +0200 Message-ID: <20260511185314.1625375-2-hossu.alexandru@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260511185314.1625375-1-hossu.alexandru@gmail.com> References: <20260511185314.1625375-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: quoted-printable Content-Type: text/plain; charset="utf-8" Three out-of-bounds read paths caused by missing frame length guards in the AP-mode authentication handler OnAuth(): 1. OnAuth() reads GetAddr2Ptr(pframe) without verifying the frame is at least WLAN_HDR_A3_LEN bytes long. The first operation on pframe after the AP-state guard is GetAddr2Ptr(pframe), which reads 6 bytes at offset 10..15 (Addr2). If the received frame is shorter than WLAN_HDR_A3_LEN (24 bytes), this reads past the end of the frame buffer. Add: if (len < WLAN_HDR_A3_LEN) return _FAIL; Using return _FAIL rather than goto auth_fail: the auth_fail block calls memcpy(pstat->hwaddr, sa, ETH_ALEN) to build a rejection frame, but sa has not been set at this point. 2. OnAuth() reads iv[3] inside the GetPrivacy() branch without checking the frame is long enough to contain the IV. When the Privacy bit is set, the code sets iv =3D pframe + WLAN_HDR_A3_L= EN and immediately reads iv[3] to extract the key index. If the frame is shorter than WLAN_HDR_A3_LEN + 4 bytes, this reads past the frame buffer. Add: if (len < WLAN_HDR_A3_LEN + 4) return _FAIL; Using return _FAIL: pstat has not been looked up yet and status is uninitialised, so goto auth_fail would send a malformed rejection frame. 3. OnAuth() reads the algorithm and sequence fields at pframe + WLAN_HDR_A3_LEN + offset + {0,2} without verifying those offsets are within the frame. offset is 0 for open-system and 4 for WEP-encapsulated frames. The reads at offset+0 and offset+2 are both 2-byte, so the last byte accessed is at WLAN_HDR_A3_LEN + offset + 3. Add: if (len < WLAN_HDR_A3_LEN + offset + 4) goto auth_fail; At this point sa is valid and pstat is NULL, so goto auth_fail is safe. WLAN_STATUS_UNSPECIFIED_FAILURE is set first to avoid sending a garbage rejection status code. Fixes: 554c0a3abf21 ("staging: Add rtl8723bs sdio wifi driver") Cc: stable@vger.kernel.org Signed-off-by: Alexandru Hossu --- Changes in v8: - Change if (len < WLAN_HDR_A3_LEN) from goto auth_fail to return _FAIL: sa is uninitialised at that point and auth_fail dereferences it via memcpy(pstat->hwaddr, sa, ETH_ALEN) to build the rejection frame (sashiko review of v7). - Add if (len < WLAN_HDR_A3_LEN + 4) return _FAIL; before iv[3] access in the GetPrivacy() branch: the missing length guard was a new OOB read path not caught in any earlier version (sashiko review of v7). - Set status =3D WLAN_STATUS_UNSPECIFIED_FAILURE before the if (len < WLAN_HDR_A3_LEN + offset + 4) goto auth_fail check to avoid sending an uninitialised status code in the rejection frame. Changes in v7: - Add frame length checks for OnAuth(): guard before GetAddr2Ptr (len < WLAN_HDR_A3_LEN) and guard before algorithm/seq reads (len < WLAN_HDR_A3_LEN + offset + 4). - Correct commit message: rtw_get_ie() uses signed int limit and returns NULL when limit < 2, so the prior unsigned-underflow claim was incorrect (sashiko review of v6). Changes in v6: - Add frame length checks for OnAuthClient(): guard before get_da() and guard before seq/status reads. drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/stagin= g/rtl8723bs/core/rtw_mlme_ext.c index 68ce422305ed..c3f2d4e5f6a7 100644 --- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c @@ -687,6 +687,9 @@ unsigned int OnAuth(struct adapter *padapter, union rec= v_frame *precv_frame) if ((pmlmeinfo->state&0x03) !=3D WIFI_FW_AP_STATE) return _FAIL; =20 + if (len < WLAN_HDR_A3_LEN) + return _FAIL; + sa =3D GetAddr2Ptr(pframe); =20 auth_mode =3D psecuritypriv->dot11AuthAlgrthm; @@ -698,6 +701,9 @@ unsigned int OnAuth(struct adapter *padapter, union rec= v_frame *precv_frame) prxattrib->hdrlen =3D WLAN_HDR_A3_LEN; prxattrib->encrypt =3D _WEP40_; =20 + if (len < WLAN_HDR_A3_LEN + 4) + return _FAIL; + iv =3D pframe+prxattrib->hdrlen; prxattrib->key_index =3D ((iv[3]>>6)&0x3); =20 @@ -709,6 +715,11 @@ unsigned int OnAuth(struct adapter *padapter, union re= cv_frame *precv_frame) offset =3D 4; } =20 + if (len < WLAN_HDR_A3_LEN + offset + 4) { + status =3D WLAN_STATUS_UNSPECIFIED_FAILURE; + goto auth_fail; + } + algorithm =3D le16_to_cpu(*(__le16 *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN = + offset)); seq =3D le16_to_cpu(*(__le16 *)((SIZE_PTR)pframe + WLAN_HDR_A3_LEN + offs= et + 2)); =20 -- 2.53.0