Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 827d42c9 authored by Johannes Berg's avatar Johannes Berg Committed by John W. Linville
Browse files

mac80211: fix spurious delBA handling



Lennert Buytenhek noticed that delBA handling in mac80211
was broken and has remotely triggerable problems, some of
which are due to some code shuffling I did that ended up
changing the order in which things were done -- this was

  commit d75636ef
  Author: Johannes Berg <johannes@sipsolutions.net>
  Date:   Tue Feb 10 21:25:53 2009 +0100

    mac80211: RX aggregation: clean up stop session

and other parts were already present in the original

  commit d92684e6
  Author: Ron Rindjunsky <ron.rindjunsky@intel.com>
  Date:   Mon Jan 28 14:07:22 2008 +0200

      mac80211: A-MPDU Tx add delBA from recipient support

The first problem is that I moved a BUG_ON before various
checks -- thereby making it possible to hit. As the comment
indicates, the BUG_ON can be removed since the ampdu_action
callback must already exist when the state is != IDLE.

The second problem isn't easily exploitable but there's a
race condition due to unconditionally setting the state to
OPERATIONAL when a delBA frame is received, even when no
aggregation session was ever initiated. All the drivers
accept stopping the session even then, but that opens a
race window where crashes could happen before the driver
accepts it. Right now, a WARN_ON may happen with non-HT
drivers, while the race opens only for HT drivers.

For this case, there are two things necessary to fix it:
 1) don't process spurious delBA frames, and be more careful
    about the session state; don't drop the lock

 2) HT drivers need to be prepared to handle a session stop
    even before the session was really started -- this is
    true for all drivers (that support aggregation) but
    iwlwifi which can be fixed easily. The other HT drivers
    (ath9k and ar9170) are behaving properly already.

Reported-by: default avatarLennert Buytenhek <buytenh@marvell.com>
Cc: stable@kernel.org
Signed-off-by: default avatarJohannes Berg <johannes@sipsolutions.net>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 4253119a
Loading
Loading
Loading
Loading
+9 −1
Original line number Original line Diff line number Diff line
@@ -1277,8 +1277,16 @@ int iwl_tx_agg_stop(struct iwl_priv *priv , const u8 *ra, u16 tid)
		return -ENXIO;
		return -ENXIO;
	}
	}


	if (priv->stations[sta_id].tid[tid].agg.state ==
				IWL_EMPTYING_HW_QUEUE_ADDBA) {
		IWL_DEBUG_HT(priv, "AGG stop before setup done\n");
		ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, ra, tid);
		priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
		return 0;
	}

	if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON)
	if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON)
		IWL_WARN(priv, "Stopping AGG while state not IWL_AGG_ON\n");
		IWL_WARN(priv, "Stopping AGG while state not ON or starting\n");


	tid_data = &priv->stations[sta_id].tid[tid];
	tid_data = &priv->stations[sta_id].tid[tid];
	ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
	ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
+6 −0
Original line number Original line Diff line number Diff line
@@ -1283,6 +1283,12 @@ enum ieee80211_filter_flags {
 *
 *
 * These flags are used with the ampdu_action() callback in
 * These flags are used with the ampdu_action() callback in
 * &struct ieee80211_ops to indicate which action is needed.
 * &struct ieee80211_ops to indicate which action is needed.
 *
 * Note that drivers MUST be able to deal with a TX aggregation
 * session being stopped even before they OK'ed starting it by
 * calling ieee80211_start_tx_ba_cb(_irqsafe), because the peer
 * might receive the addBA frame and send a delBA right away!
 *
 * @IEEE80211_AMPDU_RX_START: start Rx aggregation
 * @IEEE80211_AMPDU_RX_START: start Rx aggregation
 * @IEEE80211_AMPDU_RX_STOP: stop Rx aggregation
 * @IEEE80211_AMPDU_RX_STOP: stop Rx aggregation
 * @IEEE80211_AMPDU_TX_START: start Tx aggregation
 * @IEEE80211_AMPDU_TX_START: start Tx aggregation
+7 −8
Original line number Original line Diff line number Diff line
@@ -123,13 +123,18 @@ void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u1
	ieee80211_tx_skb(sdata, skb, 0);
	ieee80211_tx_skb(sdata, skb, 0);
}
}


static int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
				    enum ieee80211_back_parties initiator)
				    enum ieee80211_back_parties initiator)
{
{
	struct ieee80211_local *local = sta->local;
	struct ieee80211_local *local = sta->local;
	int ret;
	int ret;
	u8 *state;
	u8 *state;


#ifdef CONFIG_MAC80211_HT_DEBUG
	printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
	       sta->sta.addr, tid);
#endif /* CONFIG_MAC80211_HT_DEBUG */

	state = &sta->ampdu_mlme.tid_state_tx[tid];
	state = &sta->ampdu_mlme.tid_state_tx[tid];


	if (*state == HT_AGG_STATE_OPERATIONAL)
	if (*state == HT_AGG_STATE_OPERATIONAL)
@@ -143,7 +148,6 @@ static int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,


	/* HW shall not deny going back to legacy */
	/* HW shall not deny going back to legacy */
	if (WARN_ON(ret)) {
	if (WARN_ON(ret)) {
		*state = HT_AGG_STATE_OPERATIONAL;
		/*
		/*
		 * We may have pending packets get stuck in this case...
		 * We may have pending packets get stuck in this case...
		 * Not bothering with a workaround for now.
		 * Not bothering with a workaround for now.
@@ -525,11 +529,6 @@ int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
		goto unlock;
		goto unlock;
	}
	}


#ifdef CONFIG_MAC80211_HT_DEBUG
	printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
	       sta->sta.addr, tid);
#endif /* CONFIG_MAC80211_HT_DEBUG */

	ret = ___ieee80211_stop_tx_ba_session(sta, tid, initiator);
	ret = ___ieee80211_stop_tx_ba_session(sta, tid, initiator);


 unlock:
 unlock:
+3 −5
Original line number Original line Diff line number Diff line
@@ -141,7 +141,6 @@ void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
			     struct sta_info *sta,
			     struct sta_info *sta,
			     struct ieee80211_mgmt *mgmt, size_t len)
			     struct ieee80211_mgmt *mgmt, size_t len)
{
{
	struct ieee80211_local *local = sdata->local;
	u16 tid, params;
	u16 tid, params;
	u16 initiator;
	u16 initiator;


@@ -161,10 +160,9 @@ void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
						 WLAN_BACK_INITIATOR, 0);
						 WLAN_BACK_INITIATOR, 0);
	else { /* WLAN_BACK_RECIPIENT */
	else { /* WLAN_BACK_RECIPIENT */
		spin_lock_bh(&sta->lock);
		spin_lock_bh(&sta->lock);
		sta->ampdu_mlme.tid_state_tx[tid] =
		if (sta->ampdu_mlme.tid_state_tx[tid] & HT_ADDBA_REQUESTED_MSK)
				HT_AGG_STATE_OPERATIONAL;
			___ieee80211_stop_tx_ba_session(sta, tid,
		spin_unlock_bh(&sta->lock);
		ieee80211_stop_tx_ba_session(&local->hw, sta->sta.addr, tid,
							WLAN_BACK_RECIPIENT);
							WLAN_BACK_RECIPIENT);
		spin_unlock_bh(&sta->lock);
	}
	}
}
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -1091,6 +1091,8 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,


int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
				   enum ieee80211_back_parties initiator);
				   enum ieee80211_back_parties initiator);
int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
				    enum ieee80211_back_parties initiator);


/* Spectrum management */
/* Spectrum management */
void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata,
void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata,