Skip to contentSkip to conversation

net: wireless: iwlegacy: Fix possible data races in il4965_send_rxon_assoc()

PATCH In review Jia-Ju Bai 2 participants 5 messages Oct 3, 2018 – Oct 5, 2018

Subsystems (3)
lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 net: wireless: iwlegacy: Fix possible data races in il4965_send_rxon_assoc()

CPU0:
il4965_configure_filter

	mutex_lock()
	line 6183: il->staging.filter_flags &= ... [WRITE]
	line 6184: il->staging.filter_flags |= ... [WRITE]

CPU1:
il4965_send_rxon_assoc

	line 1301: rxon1->filter_flags, rxon1->filter_flags [READ]
	line 1314: il->staging.filter_flags [READ]

The WRITE operations in CPU0 are performed with holding a mutex lock, but the READ operations in CPU1 are performed without holding this lock, so there may exist data races.

These possible races are detected by a runtime testing.
To fix these races, the mutex lock is used in il4965_send_rxon_assoc() to protect the data.

---
 drivers/net/wireless/intel/iwlegacy/4965.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/wireless/intel/iwlegacy/4965.c +4 -0
index c3c638ed0ed7..45342777a5f1 100644
@@ -1297,6 +1297,7 @@ il4965_send_rxon_assoc(struct il_priv *il)
 	const struct il_rxon_cmd *rxon1 = &il->staging;
 	const struct il_rxon_cmd *rxon2 = &il->active;
 
+	mutex_lock(&il->mutex);
 	if (rxon1->flags == rxon2->flags &&
 	    rxon1->filter_flags == rxon2->filter_flags &&
 	    rxon1->cck_basic_rates == rxon2->cck_basic_rates &&
@@ -1307,6 +1308,7 @@ il4965_send_rxon_assoc(struct il_priv *il)
 	    rxon1->rx_chain == rxon2->rx_chain &&
 	    rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates) {
 		D_INFO("Using current RXON_ASSOC.  Not resending.\n");
+		mutex_unlock(&il->mutex);
 		return 0;
 	}
 
@@ -1321,6 +1323,8 @@ il4965_send_rxon_assoc(struct il_priv *il)
 	    il->staging.ofdm_ht_dual_stream_basic_rates;
 	rxon_assoc.rx_chain_select_flags = il->staging.rx_chain;
 
+	mutex_unlock(&il->mutex);
+
 	ret =
 	    il_send_cmd_pdu_async(il, C_RXON_ASSOC, sizeof(rxon_assoc),
 				  &rxon_assoc, NULL);
Signature · 1 line
2.17.0
#1 lore raw
Quoted 3 lines · Jia-Ju Bai

These possible races are detected by a runtime testing.
To fix these races, the mutex lock is used in il4965_send_rxon_assoc() to protect the data.

Really ? I'm surprised by that, see below.

drivers/net/wireless/intel/iwlegacy/4965.c il4965_send_rxon_assoc(struct il_priv *il) · line 1301

Quoted 6 lines
drivers/net/wireless/intel/iwlegacy/4965.c +1 -0
@@ -1297,6 +1297,7 @@ il4965_send_rxon_assoc(struct il_priv *il)
 	const struct il_rxon_cmd *rxon1 = &il->staging;
 	const struct il_rxon_cmd *rxon2 = &il->active;
 
+	mutex_lock(&il->mutex);
 	if (rxon1->flags == rxon2->flags &&

For 4965 driver il4965_send_rxon_assoc() is only called by il_mac_bss_info_changed() and il4965_commit_rxon().

il_mac_bss_info_changed() acquire il->mutex and callers of il4965_commit_rxon() acquire il->mutex (but I did not check all of them).

So I wonder how this patch did not cause the deadlock ?

Anyway what can be done is adding:

lockdep_assert_held(&il->mutex);

il4965_commit_rxon() to check if we hold the mutex.

Thanks
Stanislaw

author
#2 lore raw

Thanks for your reply :)

Quoted 5 lines · Stanislaw Gruszka
Quoted 3 lines · Jia-Ju Bai

These possible races are detected by a runtime testing.
To fix these races, the mutex lock is used in il4965_send_rxon_assoc() to protect the data.

Really ? I'm surprised by that, see below.

My runtime testing shows that il4965_send_rxon_assoc() and il4965_configure_filter() are concurrently executed.
But after seeing your reply, I need to carefully check whether my runtime testing is right, because I think you are right.
In fact, I only monitored the iwl4965 driver, but did not monitor the iwlegacy driver, so I will do the testing again with monitoring the lwlegacy driver.

Quoted 10 lines

drivers/net/wireless/intel/iwlegacy/4965.c il4965_send_rxon_assoc(struct il_priv *il) · line 1301

Quoted 7 lines
drivers/net/wireless/intel/iwlegacy/4965.c +1 -0
@@ -1297,6 +1297,7 @@ il4965_send_rxon_assoc(struct il_priv *il)
  	const struct il_rxon_cmd *rxon1 = &il->staging;
  	const struct il_rxon_cmd *rxon2 = &il->active;
 
+	mutex_lock(&il->mutex);
  	if (rxon1->flags == rxon2->flags &&

For 4965 driver il4965_send_rxon_assoc() is only called by il_mac_bss_info_changed() and il4965_commit_rxon().

Quoted 5 lines

il_mac_bss_info_changed() acquire il->mutex and callers of il4965_commit_rxon() acquire il->mutex (but I did not check all of them).

So I wonder how this patch did not cause the deadlock ?

Oh, sorry, anyway, my patch will cause double locks...

Quoted 6 lines

Anyway what can be done is adding:

lockdep_assert_held(&il->mutex);

il4965_commit_rxon() to check if we hold the mutex.

I agree.

Best wishes,
Jia-Ju Bai

#3 lore raw
Quoted 14 lines · Jia-Ju Bai
Quoted 5 lines · Stanislaw Gruszka
Quoted 3 lines · Jia-Ju Bai

These possible races are detected by a runtime testing.
To fix these races, the mutex lock is used in il4965_send_rxon_assoc() to protect the data.

Really ? I'm surprised by that, see below.

My runtime testing shows that il4965_send_rxon_assoc() and il4965_configure_filter() are concurrently executed.
But after seeing your reply, I need to carefully check whether my runtime testing is right, because I think you are right. In fact, I only monitored the iwl4965 driver, but did not monitor the iwlegacy driver, so I will do the testing again with monitoring the lwlegacy driver.

<snip>

Quoted 3 lines
Quoted 1 line

So I wonder how this patch did not cause the deadlock ?

Oh, sorry, anyway, my patch will cause double locks...

So how those runtime test were performend such you didn't notice this ?

Quoted 7 lines
Quoted 5 lines

Anyway what can be done is adding:

lockdep_assert_held(&il->mutex);

il4965_commit_rxon() to check if we hold the mutex.

I agree.

Care to post a patch ?

Thanks
Stanislaw

author
#4 lore raw
Quoted 14 lines · Stanislaw Gruszka
Quoted 5 lines · Jia-Ju Bai
Quoted 4 lines · Stanislaw Gruszka
Quoted 3 lines · Jia-Ju Bai

These possible races are detected by a runtime testing.
To fix these races, the mutex lock is used in il4965_send_rxon_assoc() to protect the data.

Quoted 8 lines
Quoted 1 line

Really ? I'm surprised by that, see below.

My runtime testing shows that il4965_send_rxon_assoc() and il4965_configure_filter() are concurrently executed.
But after seeing your reply, I need to carefully check whether my runtime testing is right, because I think you are right. In fact, I only monitored the iwl4965 driver, but did not monitor the iwlegacy driver, so I will do the testing again with monitoring the lwlegacy driver.

Quoted 5 lines

<snip>

Quoted 2 lines
Quoted 1 line

So I wonder how this patch did not cause the deadlock ?

Oh, sorry, anyway, my patch will cause double locks...

So how those runtime test were performend such you didn't notice this ?

I write a tool to perform runtime testing.
This tool records the lock status during driver execution.
Some calls to mutex_lock() are in common.c that I did not handle, so the corresponding lock status was not recorded by my tool, causing this false positive.

Now I have handled common.c, and this false positive is not reported any more. Actually, I get several new reports.
I will send you these reports to you later, and hope you can have a look, thanks in advance :)

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

Anyway what can be done is adding:

lockdep_assert_held(&il->mutex);

il4965_commit_rxon() to check if we hold the mutex.

I agree.

Care to post a patch ?

Sure :)

Best wishes,
Jia-Ju Bai