Skip to content

Commit b895885

Browse files
dwmw2David Woodhouse
authored andcommitted
br2684: don't send frames on not-ready vcc
Avoid submitting packets to a vcc which is being closed. Things go badly wrong when the ->pop method gets later called after everything's been torn down. Use the ATM socket lock for synchronisation with vcc_destroy_socket(), which clears the ATM_VF_READY bit under the same lock. Otherwise, we could end up submitting a packet to the device driver even after its ->ops->close method has been called. And it could call the vcc's ->pop method after the protocol has been shut down. Which leads to a panic. Signed-off-by: David Woodhouse <David.Woodhouse@intel.com> Acked-by: Krzysztof Mazur <krzysiek@podlesie.net>
1 parent c971f08 commit b895885

1 file changed

Lines changed: 40 additions & 3 deletions

File tree

‎net/atm/br2684.c‎

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct br2684_vcc {
6868
/* keep old push, pop functions for chaining */
6969
void (*old_push)(struct atm_vcc *vcc, struct sk_buff *skb);
7070
void (*old_pop)(struct atm_vcc *vcc, struct sk_buff *skb);
71+
void (*old_release_cb)(struct atm_vcc *vcc);
7172
enum br2684_encaps encaps;
7273
struct list_head brvccs;
7374
#ifdef CONFIG_ATM_BR2684_IPFILTER
@@ -269,6 +270,17 @@ static int br2684_xmit_vcc(struct sk_buff *skb, struct net_device *dev,
269270
return !atmvcc->send(atmvcc, skb);
270271
}
271272

273+
static void br2684_release_cb(struct atm_vcc *atmvcc)
274+
{
275+
struct br2684_vcc *brvcc = BR2684_VCC(atmvcc);
276+
277+
if (atomic_read(&brvcc->qspace) > 0)
278+
netif_wake_queue(brvcc->device);
279+
280+
if (brvcc->old_release_cb)
281+
brvcc->old_release_cb(atmvcc);
282+
}
283+
272284
static inline struct br2684_vcc *pick_outgoing_vcc(const struct sk_buff *skb,
273285
const struct br2684_dev *brdev)
274286
{
@@ -280,6 +292,8 @@ static netdev_tx_t br2684_start_xmit(struct sk_buff *skb,
280292
{
281293
struct br2684_dev *brdev = BRPRIV(dev);
282294
struct br2684_vcc *brvcc;
295+
struct atm_vcc *atmvcc;
296+
netdev_tx_t ret = NETDEV_TX_OK;
283297

284298
pr_debug("skb_dst(skb)=%p\n", skb_dst(skb));
285299
read_lock(&devs_lock);
@@ -290,9 +304,26 @@ static netdev_tx_t br2684_start_xmit(struct sk_buff *skb,
290304
dev->stats.tx_carrier_errors++;
291305
/* netif_stop_queue(dev); */
292306
dev_kfree_skb(skb);
293-
read_unlock(&devs_lock);
294-
return NETDEV_TX_OK;
307+
goto out_devs;
295308
}
309+
atmvcc = brvcc->atmvcc;
310+
311+
bh_lock_sock(sk_atm(atmvcc));
312+
313+
if (test_bit(ATM_VF_RELEASED, &atmvcc->flags) ||
314+
test_bit(ATM_VF_CLOSE, &atmvcc->flags) ||
315+
!test_bit(ATM_VF_READY, &atmvcc->flags)) {
316+
dev->stats.tx_dropped++;
317+
dev_kfree_skb(skb);
318+
goto out;
319+
}
320+
321+
if (sock_owned_by_user(sk_atm(atmvcc))) {
322+
netif_stop_queue(brvcc->device);
323+
ret = NETDEV_TX_BUSY;
324+
goto out;
325+
}
326+
296327
if (!br2684_xmit_vcc(skb, dev, brvcc)) {
297328
/*
298329
* We should probably use netif_*_queue() here, but that
@@ -304,8 +335,11 @@ static netdev_tx_t br2684_start_xmit(struct sk_buff *skb,
304335
dev->stats.tx_errors++;
305336
dev->stats.tx_fifo_errors++;
306337
}
338+
out:
339+
bh_unlock_sock(sk_atm(atmvcc));
340+
out_devs:
307341
read_unlock(&devs_lock);
308-
return NETDEV_TX_OK;
342+
return ret;
309343
}
310344

311345
/*
@@ -378,6 +412,7 @@ static void br2684_close_vcc(struct br2684_vcc *brvcc)
378412
list_del(&brvcc->brvccs);
379413
write_unlock_irq(&devs_lock);
380414
brvcc->atmvcc->user_back = NULL; /* what about vcc->recvq ??? */
415+
brvcc->atmvcc->release_cb = brvcc->old_release_cb;
381416
brvcc->old_push(brvcc->atmvcc, NULL); /* pass on the bad news */
382417
kfree(brvcc);
383418
module_put(THIS_MODULE);
@@ -554,9 +589,11 @@ static int br2684_regvcc(struct atm_vcc *atmvcc, void __user * arg)
554589
brvcc->encaps = (enum br2684_encaps)be.encaps;
555590
brvcc->old_push = atmvcc->push;
556591
brvcc->old_pop = atmvcc->pop;
592+
brvcc->old_release_cb = atmvcc->release_cb;
557593
barrier();
558594
atmvcc->push = br2684_push;
559595
atmvcc->pop = br2684_pop;
596+
atmvcc->release_cb = br2684_release_cb;
560597

561598
/* initialize netdev carrier state */
562599
if (atmvcc->dev->signal == ATM_PHY_SIG_LOST)

0 commit comments

Comments
 (0)