#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
        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)
 {
                kfree_skb(skb);
                goto out;
        }
+       ret = -EINVAL;
+       if (unlikely(!ppp_check_packet(skb, count))) {
+               kfree_skb(skb);
+               goto out;
+       }
 
        switch (pf->kind) {
        case INTERFACE: