Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2155062rwb; Thu, 8 Dec 2022 21:16:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Djk5tb+DbYfFj5OMWBBVO0WJgC3mbUWh5BNaUB06Doh7isupkqnPnMfaLyhH8TjStgHNp X-Received: by 2002:a05:6a21:358c:b0:aa:3b85:1c2f with SMTP id az12-20020a056a21358c00b000aa3b851c2fmr6236886pzc.36.1670562988018; Thu, 08 Dec 2022 21:16:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670562988; cv=none; d=google.com; s=arc-20160816; b=ftYJpS+4L8jRjU/wz8Swt178dN+kLa86P/DwHKZ0znL5Psrr8O8bBe4e6oDYJPdcGk K/Vbo4laDHnHE0RIchzWexUGsR1aPH/IRs7FJWctmYla8Vcz0IZeODRqP+FXEO9gUZi5 kXFvz5ndRELKZashJDYH4HTeKqy+mjvaBpbysfO6855nROHEMR9/KlNugMqHBYhHUnLz RZQWYyu1brfADnqRGfmbuGTZ+l6GlzU7MOx7xsY1l/FFPov2Rl/SN+RUyHoXIyezwr9m xohIkw6mzMWaLf70dvdNYlyf/iobMTCMSJXwCJVugvPKkVSpWVwVuVN+pM+Lp0IbJ0U4 iSFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:authenticated-by; bh=VpaiIi5ft1j5Ld5ekKK9uvq6sMhU3rgONCMHY2qlfrM=; b=BjNCO7fr2WJyGm8XDDZMnczTME8Gs66Vz5EaCcjtDkv2Odfe9p1/ePjwGHlGX1luXq Bu8WHiPkefBtCVVddvDYIpvEXsPEv0YboRONBJFs7VnDn9xCjq502ZfkjZCCbo9zzDS2 ouaA2gitlAQtBwuA/dzoV6giwqVRgQ9HAgsiLY+GM6S4womsRtvO4C/NPWtjIH6tn+Iw FUQwBzh9o81d0JOVV2sSSOnP4S/xjTQMrA0IHe5YaTqLkbRYboDdoQcNrHspUFfKZosq x/jn9Wj6Hg37yshSNNPM5C6yTBm67fJ/0QZ3eAAdmCJ2pvwms7Hes5a+rDAI8XZVdhjU ZiGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 185-20020a6307c2000000b00477aeffa74fsi732355pgh.107.2022.12.08.21.16.16; Thu, 08 Dec 2022 21:16:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229591AbiLIFN6 convert rfc822-to-8bit (ORCPT + 65 others); Fri, 9 Dec 2022 00:13:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbiLIFN5 (ORCPT ); Fri, 9 Dec 2022 00:13:57 -0500 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 27D5B87417; Thu, 8 Dec 2022 21:13:52 -0800 (PST) Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.77 with qID 2B95B1n44016358, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36506.realtek.com.tw[172.21.6.27]) by rtits2.realtek.com.tw (8.15.2/2.81/5.90) with ESMTPS id 2B95B1n44016358 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Fri, 9 Dec 2022 13:11:01 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXH36506.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.9; Fri, 9 Dec 2022 13:11:48 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 9 Dec 2022 13:11:48 +0800 Received: from RTEXMBS04.realtek.com.tw ([fe80::15b5:fc4b:72f3:424b]) by RTEXMBS04.realtek.com.tw ([fe80::15b5:fc4b:72f3:424b%5]) with mapi id 15.01.2375.007; Fri, 9 Dec 2022 13:11:48 +0800 From: Ping-Ke Shih To: Li Zetao , "kvalo@kernel.org" , "davem@davemloft.net" , "edumazet@google.com" , "kuba@kernel.org" , "pabeni@redhat.com" CC: "Larry.Finger@lwfinger.net" , "linville@tuxdriver.com" , "linux-wireless@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] rtlwifi: rtl8821ae: Fix global-out-of-bounds bug in _rtl8812ae_phy_set_txpower_limit() Thread-Topic: [PATCH] rtlwifi: rtl8821ae: Fix global-out-of-bounds bug in _rtl8812ae_phy_set_txpower_limit() Thread-Index: AQHZCkbbXqqj5E4pa0em0g/eG4ORkq5lAS7w Date: Fri, 9 Dec 2022 05:11:48 +0000 Message-ID: References: <20221207152319.3135500-1-lizetao1@huawei.com> In-Reply-To: <20221207152319.3135500-1-lizetao1@huawei.com> Accept-Language: en-US, zh-TW Content-Language: zh-TW X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.21.69.188] x-kse-serverinfo: RTEXMBS04.realtek.com.tw, 9 x-kse-attachmentfiltering-interceptor-info: no applicable attachment filtering rules found x-kse-antivirus-interceptor-info: scan successful x-kse-antivirus-info: =?us-ascii?Q?Clean,_bases:_2022/12/9_=3F=3F_02:22:00?= x-kse-bulkmessagesfiltering-scan-result: protection disabled Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org > -----Original Message----- > From: Li Zetao > Sent: Wednesday, December 7, 2022 11:23 PM > To: Ping-Ke Shih ; kvalo@kernel.org; davem@davemloft.net; edumazet@google.com; > kuba@kernel.org; pabeni@redhat.com > Cc: lizetao1@huawei.com; Larry.Finger@lwfinger.net; linville@tuxdriver.com; > linux-wireless@vger.kernel.org; netdev@vger.kernel.org; linux-kernel@vger.kernel.org > Subject: [PATCH] rtlwifi: rtl8821ae: Fix global-out-of-bounds bug in _rtl8812ae_phy_set_txpower_limit() > > There is a global-out-of-bounds reported by KASAN: > > BUG: KASAN: global-out-of-bounds in > _rtl8812ae_eq_n_byte.part.0+0x3d/0x84 [rtl8821ae] > Read of size 1 at addr ffffffffa0773c43 by task NetworkManager/411 > > CPU: 6 PID: 411 Comm: NetworkManager Tainted: G D > 6.1.0-rc8+ #144 e15588508517267d37 > Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), > Call Trace: > > ... > kasan_report+0xbb/0x1c0 > _rtl8812ae_eq_n_byte.part.0+0x3d/0x84 [rtl8821ae] > rtl8821ae_phy_bb_config.cold+0x346/0x641 [rtl8821ae] > rtl8821ae_hw_init+0x1f5e/0x79b0 [rtl8821ae] > ... > > > The root cause of the problem is that the comparison order of > "prate_section" in _rtl8812ae_phy_set_txpower_limit() is wrong. The > _rtl8812ae_eq_n_byte() is used to compare the first n bytes of the two > strings, so this requires the length of the two strings be greater > than or equal to n. In the _rtl8812ae_phy_set_txpower_limit(), it was > originally intended to meet this requirement by carefully designing > the comparison order. For example, "pregulation" and "pbandwidth" are > compared in order of length from small to large, first is 3 and last > is 4. However, the comparison order of "prate_section" dose not obey > such order requirement, therefore when "prate_section" is "HT", it will > lead to access out of bounds in _rtl8812ae_eq_n_byte(). > > Fix it by adding a length check in _rtl8812ae_eq_n_byte(). Although it > can be fixed by adjusting the comparison order of "prate_section", this > may cause the value of "rate_section" to not be from 0 to 5. In > addition, commit "21e4b0726dc6" not only moved driver from staging to > regular tree, but also added setting txpower limit function during the > driver config phase, so the problem was introduced by this commit. > > Fixes: 21e4b0726dc6 ("rtlwifi: rtl8821ae: Move driver from staging to regular tree") > Signed-off-by: Li Zetao > --- > drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c > b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c > index a29321e2fa72..720114a9ddb2 100644 > --- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c > +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c > @@ -1600,7 +1600,7 @@ static bool _rtl8812ae_get_integer_from_string(const char *str, u8 *pint) > > static bool _rtl8812ae_eq_n_byte(const char *str1, const char *str2, u32 num) > { This can causes problem because it compares characters from tail to head, and we can't simply replace this by strncmp() that does similar work. But, I also don't like strlen() to loop 'str1' constantly. How about having a simple loop to compare characters forward: for (i = 0; i < num; i++) if (str1[i] != str2[i]) return false; return true; > - if (num == 0) > + if (num == 0 || strlen(str1) < num) > return false; > while (num > 0) { > num--; > -- > 2.31.1 > > > ------Please consider the environment before printing this e-mail.