d80211: Fix concurrency issues in ieee80211_sta.c
PATCH 1/1 d80211: Fix concurrency issues in ieee80211_sta.c
d80211: Fix concurrency issues in ieee80211_sta.c
This fixes most concurrency issues in ieee80211_sta.c and partially prevents scans from running over an association in progress and vice versa. This is achieved by forcing all potentially racy code to run from a workqueue.
---
net/d80211/ieee80211.c | 6 + net/d80211/ieee80211_i.h | 9 ++ net/d80211/ieee80211_iface.c | 5 + net/d80211/ieee80211_sta.c | 202 ++++++++++++++++++++++++++++++------------ 4 files changed, 162 insertions(+), 60 deletions(-)
net/d80211/ieee80211.c +4 -2
@@ -2179,7 +2179,9 @@ void ieee80211_if_shutdown(struct net_decase IEEE80211_IF_TYPE_STA :case IEEE80211_IF_TYPE_IBSS : sdata->u.sta.state =IEEE80211_DISABLED ; -cancel_delayed_work (&sdata->u.sta.work); +del_timer_sync (&sdata->u.sta.timer); +flush_scheduled_work (); +skb_queue_purge (&sdata->u.sta.skb_queue);if (!local->ops->hw_scan && local->scan_dev == sdata->dev) { local->sta_scanning =0 ;
@@ -4023,7 +4025,7 @@ void ieee80211_rx_irqsafe(struct ieee802 skb->dev = local->mdev;/* copy status into skb->cb for use by tasklet */ -memcpy (skb->cb, status,sizeof (struct ieee80211_rx_status )); +memcpy (skb->cb, status,sizeof (*status)); skb->pkt_type = ieee80211_rx_msg;skb_queue_tail (&local->skb_queue, skb);tasklet_schedule (&local->tasklet);
net/d80211/ieee80211_i.h +8 -1
@@ -242,7 +242,8 @@ struct ieee80211_if_sta {IEEE80211_ASSOCIATE ,IEEE80211_ASSOCIATED , IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED } state; -struct delayed_work work; +struct timer_list timer; +struct work_struct work;u8 bssid[ETH_ALEN ], prev_bssid[ETH_ALEN ];u8 ssid[IEEE80211_MAX_SSID_LEN ];size_t ssid_len;
@@ -267,6 +268,11 @@ struct ieee80211_if_sta { unsigned int create_ibss:1; unsigned int mixed_cell:1; unsigned int wmm_enabled:1; +#define IEEE80211_STA_REQ_SCAN 0 +#define IEEE80211_STA_REQ_AUTH 1 +#define IEEE80211_STA_REQ_RUN 2 +unsigned long request; +struct sk_buff_head skb_queue;int key_mgmt;unsigned long last_probe;
@@ -660,6 +666,7 @@ int ieee80211_set_compression(struct iee struct net_device *dev, struct sta_info *sta);int ieee80211_init_client (struct net_device *dev);/* ieee80211_sta.c */ +void ieee80211_sta_timer (unsigned long data);void ieee80211_sta_work (struct work_struct *work);void ieee80211_sta_scan_work (struct work_struct *work); void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
net/d80211/ieee80211_iface.c +4 -1
@@ -185,7 +185,10 @@ void ieee80211_if_set_type(struct net_destruct ieee80211_if_sta *ifsta; ifsta = &sdata->u.sta; -INIT_DELAYED_WORK (&ifsta->work, ieee80211_sta_work); +INIT_WORK (&ifsta->work, ieee80211_sta_work); +setup_timer (&ifsta->timer, ieee80211_sta_timer, + (unsigned long ) ifsta); +skb_queue_head_init (&ifsta->skb_queue); ifsta->capab =WLAN_CAPABILITY_ESS ; ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
net/d80211/ieee80211_sta.c +146 -56
390 lines not on this page · raw message
Review void ieee80211_rx_irqsafe(struct ieee802 · line 4031
Quoted 9 lines · Michael Wu
(quoted diff) +1
-1@@ -4023,7 +4025,7 @@ void ieee80211_rx_irqsafe(struct ieee802 skb->dev = local->mdev; /* copy status into skb->cb for use by tasklet */ - memcpy(skb->cb, status, sizeof(struct ieee80211_rx_status)); + memcpy(skb->cb, status, sizeof(*status)); skb->pkt_type = ieee80211_rx_msg; skb_queue_tail(&local->skb_queue, skb); tasklet_schedule(&local->tasklet);
Opps.. that was suppose to be part of the previous patch. Fixed patches attached which just merge that chunk into the previous patch.
-Michael Wu
d80211: Fix concurrency issues in ieee80211_sta.c
From: Michael Wu <[email protected]>
This fixes most concurrency issues in ieee80211_sta.c and partially prevents scans from running over an association in progress and vice versa. This is achieved by forcing all potentially racy code to run from a workqueue.
---
net/d80211/ieee80211.c | 4 + net/d80211/ieee80211_i.h | 9 ++ net/d80211/ieee80211_iface.c | 5 + net/d80211/ieee80211_sta.c | 202 ++++++++++++++++++++++++++++++------------ 4 files changed, 161 insertions(+), 59 deletions(-)
net/d80211/ieee80211.c +3 -1
@@ -2179,7 +2179,9 @@ void ieee80211_if_shutdown(struct net_decase IEEE80211_IF_TYPE_STA :case IEEE80211_IF_TYPE_IBSS : sdata->u.sta.state =IEEE80211_DISABLED ; -cancel_delayed_work (&sdata->u.sta.work); +del_timer_sync (&sdata->u.sta.timer); +flush_scheduled_work (); +skb_queue_purge (&sdata->u.sta.skb_queue);if (!local->ops->hw_scan && local->scan_dev == sdata->dev) { local->sta_scanning =0 ;
net/d80211/ieee80211_i.h +8 -1
@@ -242,7 +242,8 @@ struct ieee80211_if_sta {IEEE80211_ASSOCIATE ,IEEE80211_ASSOCIATED , IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED } state; -struct delayed_work work; +struct timer_list timer; +struct work_struct work;u8 bssid[ETH_ALEN ], prev_bssid[ETH_ALEN ];u8 ssid[IEEE80211_MAX_SSID_LEN ];size_t ssid_len;
@@ -267,6 +268,11 @@ struct ieee80211_if_sta { unsigned int create_ibss:1; unsigned int mixed_cell:1; unsigned int wmm_enabled:1; +#define IEEE80211_STA_REQ_SCAN 0 +#define IEEE80211_STA_REQ_AUTH 1 +#define IEEE80211_STA_REQ_RUN 2 +unsigned long request; +struct sk_buff_head skb_queue;int key_mgmt;unsigned long last_probe;
@@ -660,6 +666,7 @@ int ieee80211_set_compression(struct iee struct net_device *dev, struct sta_info *sta);int ieee80211_init_client (struct net_device *dev);/* ieee80211_sta.c */ +void ieee80211_sta_timer (unsigned long data);void ieee80211_sta_work (struct work_struct *work);void ieee80211_sta_scan_work (struct work_struct *work); void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
net/d80211/ieee80211_iface.c +4 -1
@@ -185,7 +185,10 @@ void ieee80211_if_set_type(struct net_destruct ieee80211_if_sta *ifsta; ifsta = &sdata->u.sta; -INIT_DELAYED_WORK (&ifsta->work, ieee80211_sta_work); +INIT_WORK (&ifsta->work, ieee80211_sta_work); +setup_timer (&ifsta->timer, ieee80211_sta_timer, + (unsigned long ) ifsta); +skb_queue_head_init (&ifsta->skb_queue); ifsta->capab =WLAN_CAPABILITY_ESS ; ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
net/d80211/ieee80211_sta.c +146 -56
390 lines not on this page · raw message
d80211: remove hosttime from ieee80211_rx_status
From: Michael Wu <[email protected]>
Nobody fills hosttime in ieee80211_rx_status. Removing it allows ieee80211_rx_status to fit in skb->cb.
---
include/net/d80211.h | 1 - net/d80211/ieee80211.c | 25 +++++-------------------- 2 files changed, 5 insertions(+), 21 deletions(-)
include/net/d80211.h +0 -1
@@ -225,7 +225,6 @@ struct ieee80211_tx_control {* (the subset supported by hardware) to the 802.11 code with each received * frame. */ struct ieee80211_rx_status { -u64 hosttime;u64 mactime;int freq;/* receive frequency in Mhz */ int channel;
net/d80211/ieee80211.c +5 -20
@@ -2627,7 +2627,7 @@ ieee80211_fill_frame_info(struct ieee802struct timespec ts;struct ieee80211_rate *rate; -jiffies_to_timespec (status->hosttime, &ts); +jiffies_to_timespec (jiffies, &ts); fi->hosttime =cpu_to_be64 ((u64 ) ts.tv_sec *1000000 + ts.tv_nsec /1000 ); fi->mactime =cpu_to_be64 (status->mactime);
@@ -4019,25 +4019,11 @@ static void ieee80211_stat_refresh(unsigvoid ieee80211_rx_irqsafe (struct ieee80211_hw *hw,struct sk_buff *skb,struct ieee80211_rx_status *status) { -struct ieee80211_rx_status *saved;struct ieee80211_local *local =hw_to_local (hw); skb->dev = local->mdev; - saved =kmalloc (sizeof (struct ieee80211_rx_status ),GFP_ATOMIC ); -if (unlikely (!saved)) { -if (net_ratelimit ()) -printk (KERN_WARNING "%s: Not enough memory, " -"dropping packet" , skb->dev->name); -/* should be dev_kfree_skb_irq, but due to this function being -* named _irqsafe instead of just _irq we can't be sure that -* people won't call it from non-irq contexts */ -dev_kfree_skb_any (skb); -return ; - } -memcpy (saved, status,sizeof (struct ieee80211_rx_status )); -/* copy pointer to saved status into skb->cb for use by tasklet */ -memcpy (skb->cb, &saved,sizeof (saved)); - +/* copy status into skb->cb for use by tasklet */ +memcpy (skb->cb, status,sizeof (*status)); skb->pkt_type = ieee80211_rx_msg;skb_queue_tail (&local->skb_queue, skb);tasklet_schedule (&local->tasklet);
@@ -4096,13 +4082,12 @@ static void ieee80211_tasklet_handler(un (skb = skb_dequeue(&local->skb_queue_unreliable))) {switch (skb->pkt_type) {case ieee80211_rx_msg: -/* get pointer to saved status out of skb->cb */ -memcpy (&rx_status, skb->cb,sizeof (rx_status)); +/* status is in skb->cb */ + rx_status = (struct ieee80211_rx_status *) skb->cb;/* Clear skb->type in order to not confuse kernel * netstack. */ skb->pkt_type =0 ;__ieee80211_rx (local_to_hw (local), skb, rx_status); -kfree (rx_status);break ;case ieee80211_tx_status_msg:/* get pointer to saved status out of skb->cb */
Quoted 4 lines · Michael Wu
Opps.. that was suppose to be part of the previous patch. Fixed patches attached which just merge that chunk into the previous patch.
-Michael Wu
Release early and release often seems to be my motto. New, hopefully now bug free version of the patch attached. Previous version leaked and refused to scan for 5 minutes after boot. The time_after check was removed to fix the scan issue and the appropriate kfree_skb has been added to stop the leak. Otherwise, it's mostly the same thing.
-Michael Wu
d80211: Fix concurrency issues in ieee80211_sta.c
From: Michael Wu <[email protected]>
This fixes most concurrency issues in ieee80211_sta.c and partially prevents scans from running over an association in progress and vice versa. This is achieved by forcing all potentially racy code to run from a workqueue.
---
net/d80211/ieee80211.c | 4 + net/d80211/ieee80211_i.h | 9 ++ net/d80211/ieee80211_iface.c | 5 + net/d80211/ieee80211_sta.c | 199 ++++++++++++++++++++++++++++++------------ 4 files changed, 159 insertions(+), 58 deletions(-)
net/d80211/ieee80211.c +3 -1
@@ -2179,7 +2179,9 @@ void ieee80211_if_shutdown(struct net_decase IEEE80211_IF_TYPE_STA :case IEEE80211_IF_TYPE_IBSS : sdata->u.sta.state =IEEE80211_DISABLED ; -cancel_delayed_work (&sdata->u.sta.work); +del_timer_sync (&sdata->u.sta.timer); +flush_scheduled_work (); +skb_queue_purge (&sdata->u.sta.skb_queue);if (!local->ops->hw_scan && local->scan_dev == sdata->dev) { local->sta_scanning =0 ;
net/d80211/ieee80211_i.h +8 -1
@@ -242,7 +242,8 @@ struct ieee80211_if_sta {IEEE80211_ASSOCIATE ,IEEE80211_ASSOCIATED , IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED } state; -struct delayed_work work; +struct timer_list timer; +struct work_struct work;u8 bssid[ETH_ALEN ], prev_bssid[ETH_ALEN ];u8 ssid[IEEE80211_MAX_SSID_LEN ];size_t ssid_len;
@@ -267,6 +268,11 @@ struct ieee80211_if_sta { unsigned int create_ibss:1; unsigned int mixed_cell:1; unsigned int wmm_enabled:1; +#define IEEE80211_STA_REQ_SCAN 0 +#define IEEE80211_STA_REQ_AUTH 1 +#define IEEE80211_STA_REQ_RUN 2 +unsigned long request; +struct sk_buff_head skb_queue;int key_mgmt;unsigned long last_probe;
@@ -660,6 +666,7 @@ int ieee80211_set_compression(struct iee struct net_device *dev, struct sta_info *sta);int ieee80211_init_client (struct net_device *dev);/* ieee80211_sta.c */ +void ieee80211_sta_timer (unsigned long data);void ieee80211_sta_work (struct work_struct *work);void ieee80211_sta_scan_work (struct work_struct *work); void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
net/d80211/ieee80211_iface.c +4 -1
@@ -185,7 +185,10 @@ void ieee80211_if_set_type(struct net_destruct ieee80211_if_sta *ifsta; ifsta = &sdata->u.sta; -INIT_DELAYED_WORK (&ifsta->work, ieee80211_sta_work); +INIT_WORK (&ifsta->work, ieee80211_sta_work); +setup_timer (&ifsta->timer, ieee80211_sta_timer, + (unsigned long ) ifsta); +skb_queue_head_init (&ifsta->skb_queue); ifsta->capab =WLAN_CAPABILITY_ESS ; ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
net/d80211/ieee80211_sta.c +144 -55
388 lines not on this page · raw message
Jiri Benc
AppliedQuoted 4 lines · Michael Wu
This fixes most concurrency issues in
ieee80211_sta.cand partially prevents scans from running over an association in progress and vice versa. This is achieved by forcing all potentially racy code to run from a workqueue.
Applied to my tree, thanks for the patch!
Jiri
Signature · 2 lines
Jiri Benc SUSE Labs