Skip to content

Commit f2aeb73

Browse files
dmantipovPaolo Abeni
authored andcommitted
ppp: reject claimed-as-LCP but actually malformed packets
Since 'ppp_async_encode()' assumes valid LCP packets (with code from 1 to 7 inclusive), add 'ppp_check_packet()' to ensure that LCP packet has an actual body beyond PPP_LCP header bytes, and reject claimed-as-LCP but actually malformed data otherwise. Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=ec0723ba9605678b14bf Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Dmitry Antipov <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 8c6790b commit f2aeb73

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

drivers/net/ppp/ppp_generic.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#define MPHDRLEN_SSN 4 /* ditto with short sequence numbers */
7171

7272
#define PPP_PROTO_LEN 2
73+
#define PPP_LCP_HDRLEN 4
7374

7475
/*
7576
* An instance of /dev/ppp can be associated with either a ppp
@@ -493,6 +494,15 @@ static ssize_t ppp_read(struct file *file, char __user *buf,
493494
return ret;
494495
}
495496

497+
static bool ppp_check_packet(struct sk_buff *skb, size_t count)
498+
{
499+
/* LCP packets must include LCP header which 4 bytes long:
500+
* 1-byte code, 1-byte identifier, and 2-byte length.
501+
*/
502+
return get_unaligned_be16(skb->data) != PPP_LCP ||
503+
count >= PPP_PROTO_LEN + PPP_LCP_HDRLEN;
504+
}
505+
496506
static ssize_t ppp_write(struct file *file, const char __user *buf,
497507
size_t count, loff_t *ppos)
498508
{
@@ -515,6 +525,11 @@ static ssize_t ppp_write(struct file *file, const char __user *buf,
515525
kfree_skb(skb);
516526
goto out;
517527
}
528+
ret = -EINVAL;
529+
if (unlikely(!ppp_check_packet(skb, count))) {
530+
kfree_skb(skb);
531+
goto out;
532+
}
518533

519534
switch (pf->kind) {
520535
case INTERFACE:

0 commit comments

Comments
 (0)