Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp293077pxb; Wed, 20 Oct 2021 22:47:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9aXHw2nHVUbCUYnd+zW24/pe0gFxl1yhxtWWmlb2wB+TwYZadB+mqV3Hhexlnq8P/BPgp X-Received: by 2002:a17:902:8a97:b0:13e:6e77:af59 with SMTP id p23-20020a1709028a9700b0013e6e77af59mr3446847plo.4.1634795244910; Wed, 20 Oct 2021 22:47:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634795244; cv=none; d=google.com; s=arc-20160816; b=vKVXeMIo3ZIY0Z0MrFcyEB+3u/H/UaKJ6yXA/Ge9wqIijN/8aWvCic7O3MsrWyl54Q k9E/DrEPMKz39tV2/ZvXlQG8HgHkAzrfgI5RNwj3Y73bZGExqf1eRP3y/eDhoNyG777d x03cOlODn9gUqMy9nLDDqZ0z19hYErmO/ToN0/eWt2So6mhPtXUZD2K83fALinD6u/7e 2+2WFMK7zuIoTgdctnn2+Z/KbteOyQBR5IzEf84ftMUGoHIDGaAkMzdBnxr3yNknn0GP RD4Lg5vMZVTvG7nfkQNTMpCFuusZac3EBgTHRF12QTuL/OcSGKjdq4kAnEFi03DOzsGU JClw== 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=5+/uCzGLhKCAew88YDDzBOxBy01/32EThERRDGWwuXs=; b=j0BTRY6vZ4jWqxHaC2ezO4s1vA8v7VSzEHETy0gBveoMX8Xj2FM6FDDcn0LpQQlmDV 7dEMPXHJi0S8RMl5iJBSnzaSrUw5mWi3zWfLJr3tM5Z8ZXI+T7AfXA3f3KcjGifJraBd tCoRpfYVh2zFrL1OdezMKuN3fcYAbXSFtZ/6BmLVuxBSJcj/9LnfgN8+xC2f4LytZ1c3 SG4T2Dpz4aepXhOmyPcGvPjZnHKmz4kCNNBnCNzMjjYfidRUsam+Vvz/k9p4wSi1SxfY FE0CxS1OMNXQ+1+P4A5/E3+hymfj0Ym59Mk8JvlseC1d9x2elTgI6QerkxzZJQhdHX3J GOlg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pc8si12345262pjb.118.2021.10.20.22.47.16; Wed, 20 Oct 2021 22:47:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230000AbhJUFss convert rfc822-to-8bit (ORCPT + 63 others); Thu, 21 Oct 2021 01:48:48 -0400 Received: from rtits2.realtek.com ([211.75.126.72]:47248 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229499AbhJUFsr (ORCPT ); Thu, 21 Oct 2021 01:48:47 -0400 Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.73 with qID 19L5kGedD026158, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36503.realtek.com.tw[172.21.6.25]) by rtits2.realtek.com.tw (8.15.2/2.71/5.88) with ESMTPS id 19L5kGedD026158 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 21 Oct 2021 13:46:16 +0800 Received: from RTEXDAG01.realtek.com.tw (172.21.6.100) by RTEXH36503.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Thu, 21 Oct 2021 13:46:15 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXDAG01.realtek.com.tw (172.21.6.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Wed, 20 Oct 2021 22:46:15 -0700 Received: from RTEXMBS04.realtek.com.tw ([fe80::dc53:1026:298b:c584]) by RTEXMBS04.realtek.com.tw ([fe80::dc53:1026:298b:c584%5]) with mapi id 15.01.2308.015; Thu, 21 Oct 2021 13:46:15 +0800 From: Pkshih To: Kalle Valo CC: Colin King , "David S . Miller" , Jakub Kicinski , "linux-wireless@vger.kernel.org" , "netdev@vger.kernel.org" , "kernel-janitors@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH][next] rtw89: Fix potential dereference of the null pointer sta Thread-Topic: [PATCH][next] rtw89: Fix potential dereference of the null pointer sta Thread-Index: AQHXwduziBNegQ3KtE6tzEeaYjpkJqvX/pCwgACwb0mAANdosIACEPZJgAFhaMA= Date: Thu, 21 Oct 2021 05:46:15 +0000 Message-ID: <35c096e5251f49c1abfbb51f761eab82@realtek.com> References: <20211015154530.34356-1-colin.king@canonical.com> <9cc681c217a449519aee524b35e6b6bc@realtek.com> <87pms2ttvi.fsf@codeaurora.org> <87h7dcf5zj.fsf@codeaurora.org> In-Reply-To: <87h7dcf5zj.fsf@codeaurora.org> 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: RTEXDAG01.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:_2021/10/21_=3F=3F_03:10:00?= x-kse-bulkmessagesfiltering-scan-result: protection disabled Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-KSE-ServerInfo: RTEXH36503.realtek.com.tw, 9 X-KSE-Attachment-Filter-Triggered-Rules: Clean X-KSE-Attachment-Filter-Triggered-Filters: Clean X-KSE-BulkMessagesFiltering-Scan-Result: protection disabled X-KSE-AntiSpam-Outbound-Interceptor-Info: scan successful X-KSE-AntiSpam-Version: 5.9.20, Database issued on: 10/21/2021 05:25:21 X-KSE-AntiSpam-Status: KAS_STATUS_NOT_DETECTED X-KSE-AntiSpam-Method: none X-KSE-AntiSpam-Rate: 0 X-KSE-AntiSpam-Info: Lua profiles 166865 [Oct 20 2021] X-KSE-AntiSpam-Info: Version: 5.9.20.0 X-KSE-AntiSpam-Info: Envelope from: pkshih@realtek.com X-KSE-AntiSpam-Info: LuaCore: 463 463 5854868460de3f0d8e8c0a4df98aeb05fb764a09 X-KSE-AntiSpam-Info: {Tracking_from_domain_doesnt_match_to} X-KSE-AntiSpam-Info: d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;realtek.com:7.1.1;127.0.0.199:7.1.2 X-KSE-AntiSpam-Info: Rate: 0 X-KSE-AntiSpam-Info: Status: not_detected X-KSE-AntiSpam-Info: Method: none X-KSE-AntiSpam-Info: Auth:dkim=none X-KSE-Antiphishing-Info: Clean X-KSE-Antiphishing-ScanningType: Heuristic X-KSE-Antiphishing-Method: None X-KSE-Antiphishing-Bases: 10/21/2021 05:27:00 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org > -----Original Message----- > From: kvalo=codeaurora.org@mg.codeaurora.org On Behalf Of Kalle > Valo > Sent: Wednesday, October 20, 2021 4:36 PM > To: Pkshih > Cc: Colin King ; David S . Miller ; Jakub Kicinski > ; linux-wireless@vger.kernel.org; netdev@vger.kernel.org; > kernel-janitors@vger.kernel.org; linux-kernel@vger.kernel.org > Subject: Re: [PATCH][next] rtw89: Fix potential dereference of the null pointer sta > > Pkshih writes: > > >> -----Original Message----- > >> From: kvalo=codeaurora.org@mg.codeaurora.org > >> On > >> Behalf Of Kalle Valo > >> Sent: Monday, October 18, 2021 8:12 PM > >> To: Pkshih > >> Cc: Colin King ; David S . Miller > >> ; Jakub > >> Kicinski ; linux-wireless@vger.kernel.org; netdev@vger.kernel.org; > >> kernel-janitors@vger.kernel.org; linux-kernel@vger.kernel.org > >> Subject: Re: [PATCH][next] rtw89: Fix potential dereference of the null pointer sta > >> > >> Pkshih writes: > >> > >> >> -----Original Message----- > >> >> From: Colin King > >> >> Sent: Friday, October 15, 2021 11:46 PM > >> >> To: Kalle Valo ; David S . Miller ; Jakub Kicinski > >> >> ; Pkshih ; linux-wireless@vger.kernel.org; > >> >> netdev@vger.kernel.org > >> >> Cc: kernel-janitors@vger.kernel.org; linux-kernel@vger.kernel.org > >> >> Subject: [PATCH][next] rtw89: Fix potential dereference of the null pointer sta > >> >> > >> >> From: Colin Ian King > >> >> > >> >> The pointer rtwsta is dereferencing pointer sta before sta is > >> >> being null checked, so there is a potential null pointer deference > >> >> issue that may occur. Fix this by only assigning rtwsta after sta > >> >> has been null checked. Add in a null pointer check on rtwsta before > >> >> dereferencing it too. > >> >> > >> >> Fixes: e3ec7017f6a2 ("rtw89: add Realtek 802.11ax driver") > >> >> Addresses-Coverity: ("Dereference before null check") > >> >> Signed-off-by: Colin Ian King > >> >> --- > >> >> drivers/net/wireless/realtek/rtw89/core.c | 9 +++++++-- > >> >> 1 file changed, 7 insertions(+), 2 deletions(-) > >> >> > >> >> diff --git a/drivers/net/wireless/realtek/rtw89/core.c > >> >> b/drivers/net/wireless/realtek/rtw89/core.c > >> >> index 06fb6e5b1b37..26f52a25f545 100644 > >> >> --- a/drivers/net/wireless/realtek/rtw89/core.c > >> >> +++ b/drivers/net/wireless/realtek/rtw89/core.c > >> >> @@ -1534,9 +1534,14 @@ static bool rtw89_core_txq_agg_wait(struct rtw89_dev *rtwdev, > >> >> { > >> >> struct rtw89_txq *rtwtxq = (struct rtw89_txq *)txq->drv_priv; > >> >> struct ieee80211_sta *sta = txq->sta; > >> >> - struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv; > >> > > >> > 'sta->drv_priv' is only a pointer, we don't really dereference the > >> > data right here, so I think this is safe. More, compiler can optimize > >> > this instruction that reorder it to the place just right before using. > >> > So, it seems like a false alarm. > >> > > >> >> + struct rtw89_sta *rtwsta; > >> >> > >> >> - if (!sta || rtwsta->max_agg_wait <= 0) > >> >> + if (!sta) > >> >> + return false; > >> >> + rtwsta = (struct rtw89_sta *)sta->drv_priv; > >> >> + if (!rtwsta) > >> >> + return false; > >> >> + if (rtwsta->max_agg_wait <= 0) > >> >> return false; > >> >> > >> >> if (rtwdev->stats.tx_tfc_lv <= RTW89_TFC_MID) > >> > > >> > I check the size of object files before/after this patch, and > >> > the original one is smaller. > >> > > >> > text data bss dec hex filename > >> > 16781 3392 1 20174 4ece core-0.o // original > >> > 16819 3392 1 20212 4ef4 core-1.o // after this patch > >> > > >> > Do you think it is worth to apply this patch? > >> > >> I think that we should apply the patch. Even though the compiler _may_ > >> reorder the code, it might choose not to do that. > > > > Understand. > > > > I have another way to fix this coverity warning, like: > > > > @@ -1617,7 +1617,7 @@ static bool rtw89_core_txq_agg_wait(struct rtw89_dev *rtwdev, > > { > > struct rtw89_txq *rtwtxq = (struct rtw89_txq *)txq->drv_priv; > > struct ieee80211_sta *sta = txq->sta; > > - struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv; > > + struct rtw89_sta *rtwsta = sta ? (struct rtw89_sta *)sta->drv_priv : NULL; > > > > if (!sta || rtwsta->max_agg_wait <= 0) > > return false; > > > > Is this acceptable? > > It has a little redundant checking of 'sta', but the code looks clean. > > I feel that Colin's fix is more readable, but this is just matter of > taste. You can choose. I would like my version. There are three similar warnings reported by smatch, so I will fix them by myself. Please drop this patch. But, still thank Colin to point out this issue. -- Ping-Ke