Skip to content

Commit 090da7c

Browse files
Guillaume Naultgregkh
authored andcommitted
ppp: avoid loop in xmit recursion detection code
[ Upstream commit 6d06673 ] We already detect situations where a PPP channel sends packets back to its upper PPP device. While this is enough to avoid deadlocking on xmit locks, this doesn't prevent packets from looping between the channel and the unit. The problem is that ppp_start_xmit() enqueues packets in ppp->file.xq before checking for xmit recursion. Therefore, __ppp_xmit_process() might dequeue a packet from ppp->file.xq and send it on the channel which, in turn, loops it back on the unit. Then ppp_start_xmit() queues the packet back to ppp->file.xq and __ppp_xmit_process() picks it up and sends it again through the channel. Therefore, the packet will loop between __ppp_xmit_process() and ppp_start_xmit() until some other part of the xmit path drops it. For L2TP, we rapidly fill the skb's headroom and pppol2tp_xmit() drops the packet after a few iterations. But PPTP reallocates the headroom if necessary, letting the loop run and exhaust the machine resources (as reported in https://bugzilla.kernel.org/show_bug.cgi?id=199109). Fix this by letting __ppp_xmit_process() enqueue the skb to ppp->file.xq, so that we can check for recursion before adding it to the queue. Now ppp_xmit_process() can drop the packet when recursion is detected. __ppp_channel_push() is a bit special. It calls __ppp_xmit_process() without having any actual packet to send. This is used by ppp_output_wakeup() to re-enable transmission on the parent unit (for implementations like ppp_async.c, where the .start_xmit() function might not consume the skb, leaving it in ppp->xmit_pending and disabling transmission). Therefore, __ppp_xmit_process() needs to handle the case where skb is NULL, dequeuing as many packets as possible from ppp->file.xq. Reported-by: xu heng <xuheng333@zoho.com> Fixes: 55454a5 ("ppp: avoid dealock on recursive xmit") Signed-off-by: Guillaume Nault <g.nault@alphalink.fr> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 28b488f commit 090da7c

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

‎drivers/net/ppp/ppp_generic.c‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ struct ppp_net {
256256
/* Prototypes. */
257257
static int ppp_unattached_ioctl(struct net *net, struct ppp_file *pf,
258258
struct file *file, unsigned int cmd, unsigned long arg);
259-
static void ppp_xmit_process(struct ppp *ppp);
259+
static void ppp_xmit_process(struct ppp *ppp, struct sk_buff *skb);
260260
static void ppp_send_frame(struct ppp *ppp, struct sk_buff *skb);
261261
static void ppp_push(struct ppp *ppp);
262262
static void ppp_channel_push(struct channel *pch);
@@ -512,13 +512,12 @@ static ssize_t ppp_write(struct file *file, const char __user *buf,
512512
goto out;
513513
}
514514

515-
skb_queue_tail(&pf->xq, skb);
516-
517515
switch (pf->kind) {
518516
case INTERFACE:
519-
ppp_xmit_process(PF_TO_PPP(pf));
517+
ppp_xmit_process(PF_TO_PPP(pf), skb);
520518
break;
521519
case CHANNEL:
520+
skb_queue_tail(&pf->xq, skb);
522521
ppp_channel_push(PF_TO_CHANNEL(pf));
523522
break;
524523
}
@@ -1264,8 +1263,8 @@ ppp_start_xmit(struct sk_buff *skb, struct net_device *dev)
12641263
put_unaligned_be16(proto, pp);
12651264

12661265
skb_scrub_packet(skb, !net_eq(ppp->ppp_net, dev_net(dev)));
1267-
skb_queue_tail(&ppp->file.xq, skb);
1268-
ppp_xmit_process(ppp);
1266+
ppp_xmit_process(ppp, skb);
1267+
12691268
return NETDEV_TX_OK;
12701269

12711270
outf:
@@ -1417,13 +1416,14 @@ static void ppp_setup(struct net_device *dev)
14171416
*/
14181417

14191418
/* Called to do any work queued up on the transmit side that can now be done */
1420-
static void __ppp_xmit_process(struct ppp *ppp)
1419+
static void __ppp_xmit_process(struct ppp *ppp, struct sk_buff *skb)
14211420
{
1422-
struct sk_buff *skb;
1423-
14241421
ppp_xmit_lock(ppp);
14251422
if (!ppp->closing) {
14261423
ppp_push(ppp);
1424+
1425+
if (skb)
1426+
skb_queue_tail(&ppp->file.xq, skb);
14271427
while (!ppp->xmit_pending &&
14281428
(skb = skb_dequeue(&ppp->file.xq)))
14291429
ppp_send_frame(ppp, skb);
@@ -1437,15 +1437,15 @@ static void __ppp_xmit_process(struct ppp *ppp)
14371437
ppp_xmit_unlock(ppp);
14381438
}
14391439

1440-
static void ppp_xmit_process(struct ppp *ppp)
1440+
static void ppp_xmit_process(struct ppp *ppp, struct sk_buff *skb)
14411441
{
14421442
local_bh_disable();
14431443

14441444
if (unlikely(*this_cpu_ptr(ppp->xmit_recursion)))
14451445
goto err;
14461446

14471447
(*this_cpu_ptr(ppp->xmit_recursion))++;
1448-
__ppp_xmit_process(ppp);
1448+
__ppp_xmit_process(ppp, skb);
14491449
(*this_cpu_ptr(ppp->xmit_recursion))--;
14501450

14511451
local_bh_enable();
@@ -1455,6 +1455,8 @@ static void ppp_xmit_process(struct ppp *ppp)
14551455
err:
14561456
local_bh_enable();
14571457

1458+
kfree_skb(skb);
1459+
14581460
if (net_ratelimit())
14591461
netdev_err(ppp->dev, "recursion detected\n");
14601462
}
@@ -1939,7 +1941,7 @@ static void __ppp_channel_push(struct channel *pch)
19391941
if (skb_queue_empty(&pch->file.xq)) {
19401942
ppp = pch->ppp;
19411943
if (ppp)
1942-
__ppp_xmit_process(ppp);
1944+
__ppp_xmit_process(ppp, NULL);
19431945
}
19441946
}
19451947

0 commit comments

Comments
 (0)