netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ppp: reject claimed-as-LCP but actually malformed packets
@ 2024-07-05 16:08 Dmitry Antipov
  2024-07-06  9:35 ` Simon Horman
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Antipov @ 2024-07-05 16:08 UTC (permalink / raw)
  To: David S . Miller
  Cc: linux-ppp, netdev, lvc-project, Dmitry Antipov,
	syzbot+ec0723ba9605678b14bf

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: syzbot+ec0723ba9605678b14bf@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=ec0723ba9605678b14bf
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 drivers/net/ppp/ppp_generic.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index 0a65b6d690fe..2c8dfeb8ca58 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -493,6 +493,18 @@ 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)
+{
+	if (get_unaligned_be16(skb->data) == PPP_LCP &&
+	    count < PPP_PROTO_LEN + 4)
+		/* Claimed as LCP but has no actual LCP body,
+		 * which is 4 bytes at least (code, identifier,
+		 * and 2-byte length).
+		 */
+		return false;
+	return true;
+}
+
 static ssize_t ppp_write(struct file *file, const char __user *buf,
 			 size_t count, loff_t *ppos)
 {
@@ -515,6 +527,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:
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-07-11  9:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-05 16:08 [PATCH] net: ppp: reject claimed-as-LCP but actually malformed packets Dmitry Antipov
2024-07-06  9:35 ` Simon Horman
2024-07-08 11:56   ` [PATCH net v2] " Dmitry Antipov
2024-07-09  8:30     ` Simon Horman
2024-07-11  8:41       ` Paolo Abeni
2024-07-11  9:30     ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).