Skip to content

Commit c22ff7b

Browse files
buytenhholtmann
authored andcommitted
mac802154: Fix memory corruption with global deferred transmit state.
When transmitting a packet via a mac802154 driver that can sleep in its transmit function, mac802154 defers the call to the driver's transmit function to a per-device workqueue. However, mac802154 uses a single global work_struct for this, which means that if you have more than one registered mac802154 interface in the system, and you transmit on more than one of them at the same time, you'll very easily cause memory corruption. This patch moves the deferred transmit processing state from global variables to struct ieee802154_local, and this seems to fix the memory corruption issue. Signed-off-by: Lennert Buytenhek <[email protected]> Acked-by: Alexander Aring <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent 8b44f0d commit c22ff7b

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

net/mac802154/ieee802154_i.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ struct ieee802154_local {
6060

6161
struct tasklet_struct tasklet;
6262
struct sk_buff_head skb_queue;
63+
64+
struct sk_buff *tx_skb;
65+
struct work_struct tx_work;
6366
};
6467

6568
enum {
@@ -125,6 +128,7 @@ ieee802154_sdata_running(struct ieee802154_sub_if_data *sdata)
125128
extern struct ieee802154_mlme_ops mac802154_mlme_wpan;
126129

127130
void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb);
131+
void ieee802154_xmit_worker(struct work_struct *work);
128132
netdev_tx_t
129133
ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
130134
netdev_tx_t

net/mac802154/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ ieee802154_alloc_hw(size_t priv_data_len, const struct ieee802154_ops *ops)
105105

106106
skb_queue_head_init(&local->skb_queue);
107107

108+
INIT_WORK(&local->tx_work, ieee802154_xmit_worker);
109+
108110
/* init supported flags with 802.15.4 default ranges */
109111
phy->supported.max_minbe = 8;
110112
phy->supported.min_maxbe = 3;

net/mac802154/tx.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,11 @@
3030
#include "ieee802154_i.h"
3131
#include "driver-ops.h"
3232

33-
/* IEEE 802.15.4 transceivers can sleep during the xmit session, so process
34-
* packets through the workqueue.
35-
*/
36-
struct ieee802154_xmit_cb {
37-
struct sk_buff *skb;
38-
struct work_struct work;
39-
struct ieee802154_local *local;
40-
};
41-
42-
static struct ieee802154_xmit_cb ieee802154_xmit_cb;
43-
44-
static void ieee802154_xmit_worker(struct work_struct *work)
33+
void ieee802154_xmit_worker(struct work_struct *work)
4534
{
46-
struct ieee802154_xmit_cb *cb =
47-
container_of(work, struct ieee802154_xmit_cb, work);
48-
struct ieee802154_local *local = cb->local;
49-
struct sk_buff *skb = cb->skb;
35+
struct ieee802154_local *local =
36+
container_of(work, struct ieee802154_local, tx_work);
37+
struct sk_buff *skb = local->tx_skb;
5038
struct net_device *dev = skb->dev;
5139
int res;
5240

@@ -106,11 +94,8 @@ ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
10694
dev->stats.tx_packets++;
10795
dev->stats.tx_bytes += skb->len;
10896
} else {
109-
INIT_WORK(&ieee802154_xmit_cb.work, ieee802154_xmit_worker);
110-
ieee802154_xmit_cb.skb = skb;
111-
ieee802154_xmit_cb.local = local;
112-
113-
queue_work(local->workqueue, &ieee802154_xmit_cb.work);
97+
local->tx_skb = skb;
98+
queue_work(local->workqueue, &local->tx_work);
11499
}
115100

116101
return NETDEV_TX_OK;

0 commit comments

Comments
 (0)