mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jia-Ju Bai <baijiaju@buaa.edu.cn>
To: Simon Horman <simon.horman@corigine.com>
Cc: johannes@sipsolutions.net, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] net: mac80211: Add NULL checks for sta->sdata
Date: Tue, 4 Apr 2023 17:58:13 +0800	[thread overview]
Message-ID: <f70554b9-eedf-43e4-9a55-a809e9b9e89a@buaa.edu.cn> (raw)
In-Reply-To: <ZCBfHlOhU8LjdRg3@corigine.com>

Hi Simon,

Thanks for your reply, and sorry for the delay.

On 2023/3/26 23:05, Simon Horman wrote:
> On Tue, Mar 21, 2023 at 05:31:22PM +0800, Jia-Ju Bai wrote:
>> In a previous commit 69403bad97aa ("wifi: mac80211: sdata can be NULL
>> during AMPDU start"), sta->sdata can be NULL, and thus it should be
>> checked before being used.
>>
>> However, in the same call stack, sta->sdata is also used in the
>> following functions:
>>
>> ieee80211_ba_session_work()
>>    ___ieee80211_stop_rx_ba_session(sta)
>>      ht_dbg(sta->sdata, ...); -> No check
>>      sdata_info(sta->sdata, ...); -> No check
>>      ieee80211_send_delba(sta->sdata, ...) -> No check
>>    ___ieee80211_start_rx_ba_session(sta)
>>      ht_dbg(sta->sdata, ...); -> No check
>>      ht_dbg_ratelimited(sta->sdata, ...); -> No check
>>    ieee80211_tx_ba_session_handle_start(sta)
>>      sdata = sta->sdata; if (!sdata) -> Add check by previous commit
>>    ___ieee80211_stop_tx_ba_session(sdata)
>>      ht_dbg(sta->sdata, ...); -> No check
>>    ieee80211_start_tx_ba_cb(sdata)
>>      sdata = sta->sdata; local = sdata->local -> No check
>>    ieee80211_stop_tx_ba_cb(sdata)
>>      ht_dbg(sta->sdata, ...); -> No check
>>
>> Thus, to avoid possible null-pointer dereferences, the related checks
>> should be added.
>>
>> These bugs are reported by a static analysis tool implemented by myself,
>> and they are found by extending a known bug fixed in the previous commit.
>> Thus, they could be theoretical bugs.
>>
>> Signed-off-by: Jia-Ju Bai <baijiaju@buaa.edu.cn>
>> ---
>> v2:
>> * Fix an error reported by checkpatch.pl, and make the bug finding
>>    process more clear in the description. Thanks for Simon's advice.
>> ---
>>   net/mac80211/agg-rx.c | 68 ++++++++++++++++++++++++++-----------------
>>   net/mac80211/agg-tx.c | 16 ++++++++--
>>   2 files changed, 55 insertions(+), 29 deletions(-)
>>
>> diff --git a/net/mac80211/agg-rx.c b/net/mac80211/agg-rx.c
>> index c6fa53230450..6616970785a2 100644
>> --- a/net/mac80211/agg-rx.c
>> +++ b/net/mac80211/agg-rx.c
>> @@ -80,19 +80,21 @@ void ___ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
>>   	RCU_INIT_POINTER(sta->ampdu_mlme.tid_rx[tid], NULL);
>>   	__clear_bit(tid, sta->ampdu_mlme.agg_session_valid);
>>   
>> -	ht_dbg(sta->sdata,
>> -	       "Rx BA session stop requested for %pM tid %u %s reason: %d\n", > -	       sta->sta.addr, tid,
>> -	       initiator == WLAN_BACK_RECIPIENT ? "recipient" : "initiator",
>> -	       (int)reason);
>> +	if (sta->sdata) {
>> +		ht_dbg(sta->sdata,
>> +		       "Rx BA session stop requested for %pM tid %u %s reason: %d\n",
>> +		       sta->sta.addr, tid,
>> +		       initiator == WLAN_BACK_RECIPIENT ? "recipient" : "initiator",
>> +		       (int)reason);
>> +	}
> The first line of the body of ___ieee80211_stop_rx_ba_session() is:
>
> 	struct ieee80211_local *local = sta->sdata->local;
>
> So a NULL pointer dereference will have occurred before
> the checks this change adds to that function.

I checked the source code again (including the latest version 6.3-rc5).
The first line of the body of ___ieee80211_stop_rx_ba_session() is:

     struct ieee80211_local *local = sta->local;

Thus, there is no dereference of sta->sdata.

In a different function, namely ___ieee80211_start_rx_ba_session(), the 
first line is:

     struct ieee80211_local *local = sta->sdata->local;

Thus, there should be a NULL check for sta->sdata in this function.
I will add this in my patch v3.

>
>
>>   
>> -	if (drv_ampdu_action(local, sta->sdata, &params))
>> +	if (sta->sdata && drv_ampdu_action(local, sta->sdata, &params))
>>   		sdata_info(sta->sdata,
>>   			   "HW problem - can not stop rx aggregation for %pM tid %d\n",
>>   			   sta->sta.addr, tid);
>>   
> ...
>
>> diff --git a/net/mac80211/agg-tx.c b/net/mac80211/agg-tx.c
>> index f9514bacbd4a..03b31b6e7ac7 100644
>> --- a/net/mac80211/agg-tx.c
>> +++ b/net/mac80211/agg-tx.c
>> @@ -368,8 +368,10 @@ int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
>>   
>>   	spin_unlock_bh(&sta->lock);
>>   
>> -	ht_dbg(sta->sdata, "Tx BA session stop requested for %pM tid %u\n",
>> -	       sta->sta.addr, tid);
>> +	if (sta->sdata) {
>> +		ht_dbg(sta->sdata, "Tx BA session stop requested for %pM tid %u\n",
>> +		       sta->sta.addr, tid);
>> +	}
> This seems clean :)
>
>>   	del_timer_sync(&tid_tx->addba_resp_timer);
>>   	del_timer_sync(&tid_tx->session_timer);
>> @@ -776,7 +778,12 @@ void ieee80211_start_tx_ba_cb(struct sta_info *sta, int tid,
>>   			      struct tid_ampdu_tx *tid_tx)
>>   {
>>   	struct ieee80211_sub_if_data *sdata = sta->sdata;
>> -	struct ieee80211_local *local = sdata->local;
>> +	struct ieee80211_local *local;
>> +
>> +	if (!sdata)
>> +		return;
> I'm not sure that silently ignoring non-existent sdata is the right approach.
> Perhaps a WARN_ON or WARN_ONCE is appropriate?

Okay, I will use WARN_ON  in my patch v3.

>
>> +
>> +	local = sdata->local;
>>   
>>   	if (WARN_ON(test_and_set_bit(HT_AGG_STATE_DRV_READY, &tid_tx->state)))
>>   		return;
>> @@ -902,6 +909,9 @@ void ieee80211_stop_tx_ba_cb(struct sta_info *sta, int tid,
>>   	bool send_delba = false;
>>   	bool start_txq = false;
>>   
>> +	if (!sdata)
>> +		return;
>> +
> Ditto.

Okay, I will use WARN_ON  in my patch v3.

>
>>   	ht_dbg(sdata, "Stopping Tx BA session for %pM tid %d\n",
>>   	       sta->sta.addr, tid);
>>   


Best wishes,
Jia-Ju Bai


  reply	other threads:[~2023-04-04  9:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21  9:31 Jia-Ju Bai
2023-03-26 15:05 ` Simon Horman
2023-04-04  9:58   ` Jia-Ju Bai [this message]
2023-04-04 10:51     ` Simon Horman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f70554b9-eedf-43e4-9a55-a809e9b9e89a@buaa.edu.cn \
    --to=baijiaju@buaa.edu.cn \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=simon.horman@corigine.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®