Skip to content

Commit

Permalink
ppp: reject claimed-as-LCP but actually malformed packets
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dmantipov authored and Paolo Abeni committed Jul 11, 2024
1 parent 8c6790b commit f2aeb73
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions drivers/net/ppp/ppp_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#define MPHDRLEN_SSN 4 /* ditto with short sequence numbers */

#define PPP_PROTO_LEN 2
#define PPP_LCP_HDRLEN 4

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

static bool ppp_check_packet(struct sk_buff *skb, size_t count)
{
/* LCP packets must include LCP header which 4 bytes long:
* 1-byte code, 1-byte identifier, and 2-byte length.
*/
return get_unaligned_be16(skb->data) != PPP_LCP ||
count >= PPP_PROTO_LEN + PPP_LCP_HDRLEN;
}

static ssize_t ppp_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
Expand All @@ -515,6 +525,11 @@ static ssize_t ppp_write(struct file *file, const char __user *buf,
kfree_skb(skb);
goto out;
}
ret = -EINVAL;
if (unlikely(!ppp_check_packet(skb, count))) {
kfree_skb(skb);
goto out;
}

switch (pf->kind) {
case INTERFACE:
Expand Down

0 comments on commit f2aeb73

Please sign in to comment.