mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Luis Henriques <luis.henriques@canonical.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	kernel-team@lists.ubuntu.com
Cc: Emmanuel Grumbach <emmanuel.grumbach@intel.com>,
	Johannes Berg <johannes.berg@intel.com>,
	Luis Henriques <luis.henriques@canonical.com>
Subject: [PATCH 3.5 03/71] mac80211: fix AP powersave TX vs. wakeup race
Date: Mon, 31 Mar 2014 14:22:09 +0100	[thread overview]
Message-ID: <1396272197-13394-4-git-send-email-luis.henriques@canonical.com> (raw)
In-Reply-To: <1396272197-13394-1-git-send-email-luis.henriques@canonical.com>

3.5.7.33 -stable review patch.  If anyone has any objections, please let me know.

------------------

From: Emmanuel Grumbach <emmanuel.grumbach@intel.com>

commit 1d147bfa64293b2723c4fec50922168658e613ba upstream.

There is a race between the TX path and the STA wakeup: while
a station is sleeping, mac80211 buffers frames until it wakes
up, then the frames are transmitted. However, the RX and TX
path are concurrent, so the packet indicating wakeup can be
processed while a packet is being transmitted.

This can lead to a situation where the buffered frames list
is emptied on the one side, while a frame is being added on
the other side, as the station is still seen as sleeping in
the TX path.

As a result, the newly added frame will not be send anytime
soon. It might be sent much later (and out of order) when the
station goes to sleep and wakes up the next time.

Additionally, it can lead to the crash below.

Fix all this by synchronising both paths with a new lock.
Both path are not fastpath since they handle PS situations.

In a later patch we'll remove the extra skb queue locks to
reduce locking overhead.

BUG: unable to handle kernel
NULL pointer dereference at 000000b0
IP: [<ff6f1791>] ieee80211_report_used_skb+0x11/0x3e0 [mac80211]
*pde = 00000000
Oops: 0000 [#1] SMP DEBUG_PAGEALLOC
EIP: 0060:[<ff6f1791>] EFLAGS: 00210282 CPU: 1
EIP is at ieee80211_report_used_skb+0x11/0x3e0 [mac80211]
EAX: e5900da0 EBX: 00000000 ECX: 00000001 EDX: 00000000
ESI: e41d00c0 EDI: e5900da0 EBP: ebe458e4 ESP: ebe458b0
 DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068
CR0: 8005003b CR2: 000000b0 CR3: 25a78000 CR4: 000407d0
DR0: 00000000 DR1: 00000000 DR2: 00000000 DR3: 00000000
DR6: ffff0ff0 DR7: 00000400
Process iperf (pid: 3934, ti=ebe44000 task=e757c0b0 task.ti=ebe44000)
iwlwifi 0000:02:00.0: I iwl_pcie_enqueue_hcmd Sending command LQ_CMD (#4e), seq: 0x0903, 92 bytes at 3[3]:9
Stack:
 e403b32c ebe458c4 00200002 00200286 e403b338 ebe458cc c10960bb e5900da0
 ff76a6ec ebe458d8 00000000 e41d00c0 e5900da0 ebe458f0 ff6f1b75 e403b210
 ebe4598c ff723dc1 00000000 ff76a6ec e597c978 e403b758 00000002 00000002
Call Trace:
 [<ff6f1b75>] ieee80211_free_txskb+0x15/0x20 [mac80211]
 [<ff723dc1>] invoke_tx_handlers+0x1661/0x1780 [mac80211]
 [<ff7248a5>] ieee80211_tx+0x75/0x100 [mac80211]
 [<ff7249bf>] ieee80211_xmit+0x8f/0xc0 [mac80211]
 [<ff72550e>] ieee80211_subif_start_xmit+0x4fe/0xe20 [mac80211]
 [<c149ef70>] dev_hard_start_xmit+0x450/0x950
 [<c14b9aa9>] sch_direct_xmit+0xa9/0x250
 [<c14b9c9b>] __qdisc_run+0x4b/0x150
 [<c149f732>] dev_queue_xmit+0x2c2/0xca0

Reported-by: Yaara Rozenblum <yaara.rozenblum@intel.com>
Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Reviewed-by: Stanislaw Gruszka <sgruszka@redhat.com>
[reword commit log, use a separate lock]
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
---
 net/mac80211/sta_info.c |  4 ++++
 net/mac80211/sta_info.h |  7 +++----
 net/mac80211/tx.c       | 15 +++++++++++++++
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index 91eb0c5..55975bd 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -242,6 +242,7 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
 		return NULL;
 
 	spin_lock_init(&sta->lock);
+	spin_lock_init(&sta->ps_lock);
 	INIT_WORK(&sta->drv_unblock_wk, sta_unblock);
 	INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
 	mutex_init(&sta->ampdu_mlme.mtx);
@@ -979,6 +980,8 @@ void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
 
 	skb_queue_head_init(&pending);
 
+	/* sync with ieee80211_tx_h_unicast_ps_buf */
+	spin_lock(&sta->ps_lock);
 	/* Send all buffered frames to the station */
 	for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
 		int count = skb_queue_len(&pending), tmp;
@@ -998,6 +1001,7 @@ void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
 	}
 
 	ieee80211_add_pending_skbs_fn(local, &pending, clear_sta_ps_flags, sta);
+	spin_unlock(&sta->ps_lock);
 
 	local->total_ps_buffered -= buffered;
 
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index a470e11..4223a28 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -233,6 +233,7 @@ struct sta_ampdu_mlme {
  * @drv_unblock_wk: used for driver PS unblocking
  * @listen_interval: listen interval of this station, when we're acting as AP
  * @_flags: STA flags, see &enum ieee80211_sta_info_flags, do not use directly
+ * @ps_lock: used for powersave (when mac80211 is the AP) related locking
  * @ps_tx_buf: buffers (per AC) of frames to transmit to this station
  *	when it leaves power saving state or polls
  * @tx_filtered: buffers (per AC) of frames we already tried to
@@ -309,10 +310,8 @@ struct sta_info {
 	/* use the accessors defined below */
 	unsigned long _flags;
 
-	/*
-	 * STA powersave frame queues, no more than the internal
-	 * locking required.
-	 */
+	/* STA powersave lock and frame queues */
+	spinlock_t ps_lock;
 	struct sk_buff_head ps_tx_buf[IEEE80211_NUM_ACS];
 	struct sk_buff_head tx_filtered[IEEE80211_NUM_ACS];
 	unsigned long driver_buffered_tids;
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index df9e376..2be46b1 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -462,6 +462,20 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
 		if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
 			purge_old_ps_buffers(tx->local);
+
+		/* sync with ieee80211_sta_ps_deliver_wakeup */
+		spin_lock(&sta->ps_lock);
+		/*
+		 * STA woke up the meantime and all the frames on ps_tx_buf have
+		 * been queued to pending queue. No reordering can happen, go
+		 * ahead and Tx the packet.
+		 */
+		if (!test_sta_flag(sta, WLAN_STA_PS_STA) &&
+		    !test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
+			spin_unlock(&sta->ps_lock);
+			return TX_CONTINUE;
+		}
+
 		if (skb_queue_len(&sta->ps_tx_buf[ac]) >= STA_MAX_TX_BUFFER) {
 			struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf[ac]);
 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
@@ -476,6 +490,7 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
 		info->control.vif = &tx->sdata->vif;
 		info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
 		skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb);
+		spin_unlock(&sta->ps_lock);
 
 		if (!timer_pending(&local->sta_cleanup))
 			mod_timer(&local->sta_cleanup,
-- 
1.9.1


  parent reply	other threads:[~2014-03-31 13:55 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-31 13:22 [3.5.y.z extended stable] Linux 3.5.7.33 stable review Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 01/71] ALSA: oxygen: Xonar DG(X): capture from I2S channel 1, not 2 Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 02/71] ALSA: oxygen: Xonar DG(X): modify DAC routing Luis Henriques
2014-03-31 13:22 ` Luis Henriques [this message]
2014-03-31 13:22 ` [PATCH 3.5 04/71] iwlwifi: dvm: clear IWL_STA_UCODE_INPROGRESS when assoc fails Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 05/71] ath9k: protect tid->sched check Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 06/71] ath9k: Fix ETSI compliance for AR9462 2.0 Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 07/71] genirq: Remove racy waitqueue_active check Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 08/71] sched: Fix double normalization of vruntime Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 09/71] cpuset: fix a race condition in __cpuset_node_allowed_softwall() Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 10/71] firewire: net: fix use after free Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 11/71] mwifiex: do not advertise usb autosuspend support Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 12/71] NFS: Fix a delegation callback race Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 13/71] can: flexcan: fix shutdown: first disable chip, then all interrupts Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 14/71] can: flexcan: flexcan_open(): fix error path if flexcan_chip_start() fails Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 15/71] tracing: Do not add event files for modules that fail tracepoints Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 16/71] ocfs2: fix quota file corruption Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 17/71] rapidio/tsi721: fix tasklet termination in dma channel release Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 18/71] ALSA: usb-audio: Add quirk for Logitech Webcam C500 Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 19/71] drm/radeon: TTM must be init with cpu-visible VRAM, v2 Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 20/71] drm/radeon/atom: select the proper number of lanes in transmitter setup Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 21/71] powerpc: Align p_dyn, p_rela and p_st symbols Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 22/71] libata: add ATA_HORKAGE_BROKEN_FPDMA_AA quirk for Seagate Momentus SpinPoint M8 (2BA30001) Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 23/71] usb: Add device quirk for Logitech HD Pro Webcams C920 and C930e Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 24/71] usb: Make DELAY_INIT quirk wait 100ms between Get Configuration requests Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 25/71] ARM: 7991/1: sa1100: fix compile problem on Collie Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 26/71] firewire: don't use PREPARE_DELAYED_WORK Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 27/71] x86: Ignore NMIs that come in during early boot Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 28/71] x86: fix compile error due to X86_TRAP_NMI use in asm files Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 29/71] virtio-net: alloc big buffers also when guest can receive UFO Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 30/71] tg3: Don't check undefined error bits in RXBD Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 31/71] net: sctp: fix sctp_sf_do_5_1D_ce to verify if we/peer is AUTH capable Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 32/71] usb: dwc3: add support for Merrifield Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 33/71] mac80211: clear sequence/fragment number in QoS-null frames Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 34/71] mwifiex: copy AP's HT capability info correctly Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 35/71] net: unix socket code abuses csum_partial Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 36/71] ibmveth: Fix endian issues with MAC addresses Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 37/71] [SCSI] isci: fix reset timeout handling Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 38/71] [SCSI] isci: correct erroneous for_each_isci_host macro Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 39/71] [SCSI] qla2xxx: Poll during initialization for ISP25xx and ISP83xx Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 40/71] ocfs2 syncs the wrong range Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 41/71] fs/proc/base.c: fix GPF in /proc/$PID/map_files Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 42/71] vmxnet3: fix netpoll race condition Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 43/71] [SCSI] storvsc: NULL pointer dereference fix Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 44/71] PCI: Enable INTx in pci_reenable_device() only when MSI/MSI-X not enabled Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 45/71] KVM: SVM: fix cr8 intercept window Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 46/71] drm/ttm: don't oops if no invalidate_caches() Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 47/71] vmxnet3: fix building without CONFIG_PCI_MSI Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 48/71] x86/amd/numa: Fix northbridge quirk to assign correct NUMA node Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 49/71] Btrfs: fix data corruption when reading/updating compressed extents Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 50/71] jiffies: Avoid undefined behavior from signed overflow Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 51/71] ALSA: compress: Pass through return value of open ops callback Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 52/71] acpi-cpufreq: set current frequency based on target P-State Luis Henriques
2014-03-31 13:22 ` [PATCH 3.5 53/71] hpfs: deadlock and race in directory lseek() Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 54/71] intel_idle: Check cpu_idle_get_driver() for NULL before dereferencing it Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 55/71] ipc/msg: fix race around refcount Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 56/71] Input: synaptics - add manual min/max quirk Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 57/71] Input: synaptics - add manual min/max quirk for ThinkPad X240 Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 58/71] x86: fix boot on uniprocessor systems Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 59/71] staging: speakup: Prefix externally-visible symbols Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 60/71] ext4: atomically set inode->i_flags in ext4_set_inode_flags() Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 61/71] deb-pkg: Fix cross-building linux-headers package Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 62/71] x86: bpf_jit: support negative offsets Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 63/71] p54: clamp properly instead of just truncating Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 64/71] ALSA: hda/realtek - Avoid invalid COEFs for ALC271X Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 65/71] of: Fix address decoding on Bimini and js2x machines Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 66/71] of: fix PCI bus match for PCIe slots Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 67/71] libata: disable LPM for some WD SATA-I devices Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 68/71] mmc: sdhci: fix lockdep error in tuning routine Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 69/71] usb: ehci: add freescale imx28 special write register method Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 70/71] USB: pl2303: fix data corruption on termios updates Luis Henriques
2014-03-31 13:23 ` [PATCH 3.5 71/71] ioat: fix tasklet tear down Luis Henriques
2014-04-04  0:13   ` Ben Hutchings
2014-04-04  8:32     ` Luís Henriques

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=1396272197-13394-4-git-send-email-luis.henriques@canonical.com \
    --to=luis.henriques@canonical.com \
    --cc=emmanuel.grumbach@intel.com \
    --cc=johannes.berg@intel.com \
    --cc=kernel-team@lists.ubuntu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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®