Skip to contentSkip to conversation

ppp: Prevent out-of-bounds access in ppp_sync_txmunge

PATCH In review Purva Yeshi 2 participants 5 messages Feb 16, 2025 – Feb 25, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ppp: Prevent out-of-bounds access in ppp_sync_txmunge

Fix an issue detected by syzbot with KMSAN:

BUG: KMSAN: uninit-value in ppp_sync_txmunge
drivers/net/ppp/ppp_synctty.c:516 [inline]
BUG: KMSAN: uninit-value in ppp_sync_send+0x21c/0xb00

drivers/net/ppp/ppp_synctty.c:568

Ensure sk_buff is valid and has at least 3 bytes before accessing its data field in ppp_sync_txmunge(). Without this check, the function may attempt to read uninitialized or invalid memory, leading to undefined behavior.

To address this, add a validation check at the beginning of the function to safely handle cases where skb is NULL or too small. If either condition is met, free the skb and return NULL to prevent processing an invalid packet.

---
 drivers/net/ppp/ppp_synctty.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ppp/ppp_synctty.c +6 -0
index 644e99fc3..e537ea3d9 100644
@@ -506,6 +506,12 @@ ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb)
 	unsigned char *data;
 	int islcp;
 
+	/* Ensure skb is not NULL and has at least 3 bytes */
+	if (!skb || skb->len < 3) {
+		kfree_skb(skb);
+		return NULL;
+	}
+
 	data  = skb->data;
 	proto = get_unaligned_be16(data);
 
Signature · 1 line
2.34.1
#1 lore raw

From: Purva Yeshi <[email protected]>
Date: Sun, 16 Feb 2025 11:34:46 +0530

Quoted 30 lines

Fix an issue detected by syzbot with KMSAN:

BUG: KMSAN: uninit-value in ppp_sync_txmunge
drivers/net/ppp/ppp_synctty.c:516 [inline]
BUG: KMSAN: uninit-value in ppp_sync_send+0x21c/0xb00

drivers/net/ppp/ppp_synctty.c:568

Ensure sk_buff is valid and has at least 3 bytes before accessing its data field in ppp_sync_txmunge(). Without this check, the function may attempt to read uninitialized or invalid memory, leading to undefined behavior.

To address this, add a validation check at the beginning of the function to safely handle cases where skb is NULL or too small. If either condition is met, free the skb and return NULL to prevent processing an invalid packet.

---
 drivers/net/ppp/ppp_synctty.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ppp/ppp_synctty.c +0 -0
index 644e99fc3..e537ea3d9 100644

drivers/net/ppp/ppp_synctty.c ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb) · line 510

Quoted 5 lines
drivers/net/ppp/ppp_synctty.c +2 -0
@@ -506,6 +506,12 @@ ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb)
 	unsigned char *data;
 	int islcp;
 
+	/* Ensure skb is not NULL and has at least 3 bytes */
+	if (!skb || skb->len < 3) {

When is skb NULL ?

Quoted 9 lines
drivers/net/ppp/ppp_synctty.c +4 -0
+		kfree_skb(skb);
+		return NULL;
+	}
+
 	data  = skb->data;
 	proto = get_unaligned_be16(data);
 
Signature · 1 line
2.34.1
#2 lore raw
Quoted 35 lines · Kuniyuki Iwashima

From: Purva Yeshi <[email protected]>
Date: Sun, 16 Feb 2025 11:34:46 +0530

Quoted 33 lines

Fix an issue detected by syzbot with KMSAN:

BUG: KMSAN: uninit-value in ppp_sync_txmunge
drivers/net/ppp/ppp_synctty.c:516 [inline]
BUG: KMSAN: uninit-value in ppp_sync_send+0x21c/0xb00

drivers/net/ppp/ppp_synctty.c:568

Ensure sk_buff is valid and has at least 3 bytes before accessing its data field in ppp_sync_txmunge(). Without this check, the function may attempt to read uninitialized or invalid memory, leading to undefined behavior.

To address this, add a validation check at the beginning of the function to safely handle cases where skb is NULL or too small. If either condition is met, free the skb and return NULL to prevent processing an invalid packet.

---
  drivers/net/ppp/ppp_synctty.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/net/ppp/ppp_synctty.c +0 -0
index 644e99fc3..e537ea3d9 100644
@@ -506,6 +506,12 @@ ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb)
  	unsigned char *data;
  	int islcp;
 
Quoted 4 lines

drivers/net/ppp/ppp_synctty.c ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb) · line 510

Quoted 2 lines
drivers/net/ppp/ppp_synctty.c +2 -0
+	/* Ensure skb is not NULL and has at least 3 bytes */
+	if (!skb || skb->len < 3) {

When is skb NULL ?

skb pointer can be NULL in cases where memory allocation for the socket buffer fails, or if an upstream function incorrectly passes a NULL reference due to improper error handling.

Additionally, skb->len being less than 3 can occur if the received packet is truncated or malformed, leading to out-of-bounds memory access when attempting to read data[2].

Quoted 11 lines
Quoted 11 lines
drivers/net/ppp/ppp_synctty.c +4 -0
+		kfree_skb(skb);
+		return NULL;
+	}
+
  	data  = skb->data;
  	proto = get_unaligned_be16(data);
 
Signature · 1 line
2.34.1
#3 lore raw

From: Purva Yeshi <[email protected]>
Date: Tue, 18 Feb 2025 11:58:17 +0530

Quoted 36 lines · Kuniyuki Iwashima
Quoted 35 lines

From: Purva Yeshi <[email protected]>
Date: Sun, 16 Feb 2025 11:34:46 +0530

Quoted 33 lines

Fix an issue detected by syzbot with KMSAN:

BUG: KMSAN: uninit-value in ppp_sync_txmunge
drivers/net/ppp/ppp_synctty.c:516 [inline]
BUG: KMSAN: uninit-value in ppp_sync_send+0x21c/0xb00

drivers/net/ppp/ppp_synctty.c:568

Ensure sk_buff is valid and has at least 3 bytes before accessing its data field in ppp_sync_txmunge(). Without this check, the function may attempt to read uninitialized or invalid memory, leading to undefined behavior.

To address this, add a validation check at the beginning of the function to safely handle cases where skb is NULL or too small. If either condition is met, free the skb and return NULL to prevent processing an invalid packet.

---
  drivers/net/ppp/ppp_synctty.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/net/ppp/ppp_synctty.c +0 -0
index 644e99fc3..e537ea3d9 100644
@@ -506,6 +506,12 @@ ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb)
  	unsigned char *data;
  	int islcp;
 
Quoted 8 lines
Quoted 4 lines

drivers/net/ppp/ppp_synctty.c ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb) · line 510

Quoted 2 lines
drivers/net/ppp/ppp_synctty.c +2 -0
+	/* Ensure skb is not NULL and has at least 3 bytes */
+	if (!skb || skb->len < 3) {

When is skb NULL ?

skb pointer can be NULL in cases where memory allocation for the socket buffer fails, or if an upstream function incorrectly passes a NULL reference due to improper error handling.

Which caller passes NULL skb ?

If it's really possible, you'll see null-ptr-deref at

  data = skb->data;

below instead of KMSAN's uninit splat.

Quoted 16 lines

Additionally, skb->len being less than 3 can occur if the received packet is truncated or malformed, leading to out-of-bounds memory access when attempting to read data[2].

Quoted 11 lines
Quoted 11 lines
drivers/net/ppp/ppp_synctty.c +4 -0
+		kfree_skb(skb);
+		return NULL;
+	}
+
  	data  = skb->data;
  	proto = get_unaligned_be16(data);
 
Signature · 1 line
2.34.1
#4 lore raw
Quoted 47 lines · Kuniyuki Iwashima

From: Purva Yeshi <[email protected]>
Date: Tue, 18 Feb 2025 11:58:17 +0530

Quoted 36 lines · Kuniyuki Iwashima
Quoted 35 lines

From: Purva Yeshi <[email protected]>
Date: Sun, 16 Feb 2025 11:34:46 +0530

Quoted 33 lines

Fix an issue detected by syzbot with KMSAN:

BUG: KMSAN: uninit-value in ppp_sync_txmunge
drivers/net/ppp/ppp_synctty.c:516 [inline]
BUG: KMSAN: uninit-value in ppp_sync_send+0x21c/0xb00

drivers/net/ppp/ppp_synctty.c:568

Ensure sk_buff is valid and has at least 3 bytes before accessing its data field in ppp_sync_txmunge(). Without this check, the function may attempt to read uninitialized or invalid memory, leading to undefined behavior.

To address this, add a validation check at the beginning of the function to safely handle cases where skb is NULL or too small. If either condition is met, free the skb and return NULL to prevent processing an invalid packet.

---
   drivers/net/ppp/ppp_synctty.c | 6 ++++++
   1 file changed, 6 insertions(+)
drivers/net/ppp/ppp_synctty.c +0 -0
index 644e99fc3..e537ea3d9 100644
@@ -506,6 +506,12 @@ ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb)
   	unsigned char *data;
   	int islcp;
 
Quoted 8 lines
Quoted 4 lines

drivers/net/ppp/ppp_synctty.c ppp_sync_txmunge(struct syncppp *ap, struct sk_buff *skb) · line 510

Quoted 2 lines
drivers/net/ppp/ppp_synctty.c +2 -0
+	/* Ensure skb is not NULL and has at least 3 bytes */
+	if (!skb || skb->len < 3) {

When is skb NULL ?

skb pointer can be NULL in cases where memory allocation for the socket buffer fails, or if an upstream function incorrectly passes a NULL reference due to improper error handling.

Quoted 7 lines

Which caller passes NULL skb ?

If it's really possible, you'll see null-ptr-deref at

   data = skb->data;

below instead of KMSAN's uninit splat.

Understood. I’ll check where the skb pointer is receiving uninitialized data.

Quoted 18 lines
Quoted 18 lines

Additionally, skb->len being less than 3 can occur if the received packet is truncated or malformed, leading to out-of-bounds memory access when attempting to read data[2].

Quoted 11 lines
Quoted 11 lines
drivers/net/ppp/ppp_synctty.c +4 -0
+		kfree_skb(skb);
+		return NULL;
+	}
+
   	data  = skb->data;
   	proto = get_unaligned_be16(data);
 
Signature · 1 line
2.34.1