Skip to contentSkip to conversation

slip: Check if rstate is initialized before uncompressing

PATCH Superseded Tejaswi Tanikella 3 participants 5 messages Apr 9, 2018 – Apr 10, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 slip: Check if rstate is initialized before uncompressing

On receiving a packet the state index points to the rstate which must be used to fill up IP and TCP headers. But if the state index points to a rstate which is unitialized, i.e. filled with zeros, it gets stuck in an infinite loop inside ip_fast_csum trying to compute the ip checsum of a header with zero length.

89.666953:   <2> [<ffffff9dd3e94d38>] slhc_uncompress+0x464/0x468
89.666965:   <2> [<ffffff9dd3e87d88>] ppp_receive_nonmp_frame+0x3b4/0x65c
89.666978:   <2> [<ffffff9dd3e89dd4>] ppp_receive_frame+0x64/0x7e0
89.666991:   <2> [<ffffff9dd3e8a708>] ppp_input+0x104/0x198
89.667005:   <2> [<ffffff9dd3e93868>] pppopns_recv_core+0x238/0x370
89.667027:   <2> [<ffffff9dd4428fc8>] __sk_receive_skb+0xdc/0x250
89.667040:   <2> [<ffffff9dd3e939e4>] pppopns_recv+0x44/0x60
89.667053:   <2> [<ffffff9dd4426848>] __sock_queue_rcv_skb+0x16c/0x24c
89.667065:   <2> [<ffffff9dd4426954>] sock_queue_rcv_skb+0x2c/0x38
89.667085:   <2> [<ffffff9dd44f7358>] raw_rcv+0x124/0x154
89.667098:   <2> [<ffffff9dd44f7568>] raw_local_deliver+0x1e0/0x22c
89.667117:   <2> [<ffffff9dd44c8ba0>] ip_local_deliver_finish+0x70/0x24c
89.667131:   <2> [<ffffff9dd44c92f4>] ip_local_deliver+0x100/0x10c

./scripts/faddr2line vmlinux slhc_uncompress+0x464/0x468 output:
ip_fast_csum at arch/arm64/include/asm/checksum.h:40 (inlined by) slhc_uncompress at drivers/net/slip/slhc.c:615

Adding a variable to indicate if the current rstate is initialized. If such a packet arrives, move to toss state.

---
 drivers/net/slip/slhc.c | 5 +++++
 include/net/slhc_vj.h   | 1 +
 2 files changed, 6 insertions(+)
drivers/net/slip/slhc.c +5 -0
index 5782733..e710b0b 100644
@@ -509,6 +509,10 @@ struct slcompress *
 		if(x < 0 || x > comp->rslot_limit)
 			goto bad;
 
+		/* Check if the cstate is initialized */
+		if(!comp->rstate[x].initialized)
+			goto bad;
+
 		comp->flags &=~ SLF_TOSS;
 		comp->recv_current = x;
 	} else {
@@ -673,6 +677,7 @@ struct slcompress *
 	if (cs->cs_tcp.doff > 5)
 	  memcpy(cs->cs_tcpopt, icp + ihl*4 + sizeof(struct tcphdr), (cs->cs_tcp.doff - 5) * 4);
 	cs->cs_hsize = ihl*2 + cs->cs_tcp.doff*2;
+	cs->initialized = 1;
 	/* Put headers back on packet
 	 * Neither header checksum is recalculated
 	 */
include/net/slhc_vj.h +1 -0
index 8716d59..d673365 100644
@@ -127,6 +127,7 @@
  */
 struct cstate {
 	byte_t	cs_this;	/* connection id number (xmit) */
+	byte_t	initialized;	/* non-zero if initialized */
 	struct cstate *next;	/* next in ring (xmit) */
 	struct iphdr cs_ip;	/* ip/tcp hdr from most recent packet */
 	struct tcphdr cs_tcp;
Signature · 1 line
1.9.1
maintainer
#1 lore raw

From: Tejaswi Tanikella <[email protected]>
Date: Mon, 9 Apr 2018 14:23:49 +0530

Quoted 6 lines
drivers/net/slip/slhc.c +1 -0
@@ -673,6 +677,7 @@ struct slcompress *
 	if (cs->cs_tcp.doff > 5)
 	  memcpy(cs->cs_tcpopt, icp + ihl*4 + sizeof(struct tcphdr), (cs->cs_tcp.doff - 5) * 4);
 	cs->cs_hsize = ihl*2 + cs->cs_tcp.doff*2;
+	cs->initialized = 1;
 	/* Put headers back on packet

...

include/net/slhc_vj.h line 130

Quoted 3 lines

struct cstate {

include/net/slhc_vj.h +1 -0
 	byte_t	cs_this;	/* connection id number (xmit) */
+	byte_t	initialized;	/* non-zero if initialized */

Please use 'bool' and true/false for 'initialized'.

#2 lore raw
Quoted 11 lines · David Miller

From: Tejaswi Tanikella <[email protected]>
Date: Mon, 9 Apr 2018 14:23:49 +0530

Quoted 7 lines
(quoted diff) +1 -0
@@ -673,6 +677,7 @@ struct slcompress *
 	if (cs->cs_tcp.doff > 5)
 	  memcpy(cs->cs_tcpopt, icp + ihl*4 + sizeof(struct tcphdr), 
 (cs->cs_tcp.doff - 5) * 4);
 	cs->cs_hsize = ihl*2 + cs->cs_tcp.doff*2;
+	cs->initialized = 1;
 	/* Put headers back on packet

...

Quoted 5 lines

Review

Quoted 3 lines

struct cstate {

(quoted diff) +1 -0
 	byte_t	cs_this;	/* connection id number (xmit) */
+	byte_t	initialized;	/* non-zero if initialized */

Please use 'bool' and true/false for 'initialized'.

Made the changes.

From b04441041034a5e044705d3c5a2cc338dd4bfc3a Mon Sep 17 00:00:00 2001
From: Tejaswi Tanikella <[email protected]>
Date: Thu, 29 Mar 2018 14:46:41 +0530
Subject: [PATCH] slip: Check if rstate is initialized before uncompressing

On receiving a packet the state index points to the rstate which must be used to fill up IP and TCP headers. But if the state index points to a rstate which is unitialized, i.e. filled with zeros, it gets stuck in an infinite loop inside ip_fast_csum trying to compute the ip checsum of a header with zero length.

89.666953:   <2> [<ffffff9dd3e94d38>] slhc_uncompress+0x464/0x468
89.666965:   <2> [<ffffff9dd3e87d88>] ppp_receive_nonmp_frame+0x3b4/0x65c
89.666978:   <2> [<ffffff9dd3e89dd4>] ppp_receive_frame+0x64/0x7e0
89.666991:   <2> [<ffffff9dd3e8a708>] ppp_input+0x104/0x198
89.667005:   <2> [<ffffff9dd3e93868>] pppopns_recv_core+0x238/0x370
89.667027:   <2> [<ffffff9dd4428fc8>] __sk_receive_skb+0xdc/0x250
89.667040:   <2> [<ffffff9dd3e939e4>] pppopns_recv+0x44/0x60
89.667053:   <2> [<ffffff9dd4426848>] __sock_queue_rcv_skb+0x16c/0x24c
89.667065:   <2> [<ffffff9dd4426954>] sock_queue_rcv_skb+0x2c/0x38
89.667085:   <2> [<ffffff9dd44f7358>] raw_rcv+0x124/0x154
89.667098:   <2> [<ffffff9dd44f7568>] raw_local_deliver+0x1e0/0x22c
89.667117:   <2> [<ffffff9dd44c8ba0>] ip_local_deliver_finish+0x70/0x24c
89.667131:   <2> [<ffffff9dd44c92f4>] ip_local_deliver+0x100/0x10c

./scripts/faddr2line vmlinux slhc_uncompress+0x464/0x468 output:
ip_fast_csum at arch/arm64/include/asm/checksum.h:40 (inlined by) slhc_uncompress at drivers/net/slip/slhc.c:615

Adding a variable to indicate if the current rstate is initialized. If such a packet arrives, move to toss state.

---
 drivers/net/slip/slhc.c | 5 +++++
 include/net/slhc_vj.h   | 1 +
 2 files changed, 6 insertions(+)
drivers/net/slip/slhc.c +5 -0
index 5782733..f4e93f5 100644
@@ -509,6 +509,10 @@ struct slcompress *
 		if(x < 0 || x > comp->rslot_limit)
 			goto bad;
 
+		/* Check if the cstate is initialized */
+		if (!comp->rstate[x].initialized)
+			goto bad;
+
 		comp->flags &=~ SLF_TOSS;
 		comp->recv_current = x;
 	} else {
@@ -673,6 +677,7 @@ struct slcompress *
 	if (cs->cs_tcp.doff > 5)
 	  memcpy(cs->cs_tcpopt, icp + ihl*4 + sizeof(struct tcphdr), (cs->cs_tcp.doff - 5) * 4);
 	cs->cs_hsize = ihl*2 + cs->cs_tcp.doff*2;
+	cs->initialized = true;
 	/* Put headers back on packet
 	 * Neither header checksum is recalculated
 	 */
include/net/slhc_vj.h +1 -0
index 8716d59..8fcf890 100644
@@ -127,6 +127,7 @@
  */
 struct cstate {
 	byte_t	cs_this;	/* connection id number (xmit) */
+	bool	initialized;	/* true if initialized */
 	struct cstate *next;	/* next in ring (xmit) */
 	struct iphdr cs_ip;	/* ip/tcp hdr from most recent packet */
 	struct tcphdr cs_tcp;
Signature · 1 line
1.9.1
#3 lore raw
Quoted 12 lines · On Tue, Apr 10, 2018 at 11:28:10AM +0530, [email protected] wrote:
Quoted 11 lines · David Miller

From: Tejaswi Tanikella <[email protected]>
Date: Mon, 9 Apr 2018 14:23:49 +0530

Quoted 7 lines
drivers/net/slip/slhc.c +1 -0
@@ -673,6 +677,7 @@ struct slcompress *
 	if (cs->cs_tcp.doff > 5)
 	  memcpy(cs->cs_tcpopt, icp + ihl*4 + sizeof(struct tcphdr),
 (cs->cs_tcp.doff - 5) * 4);
 	cs->cs_hsize = ihl*2 + cs->cs_tcp.doff*2;
+	cs->initialized = 1;
 	/* Put headers back on packet

...

Quoted 7 lines
Quoted 5 lines

Review

Quoted 3 lines

struct cstate {

(quoted diff) +1 -0
 	byte_t	cs_this;	/* connection id number (xmit) */
+	byte_t	initialized;	/* non-zero if initialized */

Please use 'bool' and true/false for 'initialized'.

Made the changes.

Hi Tejaswi,

Please send the new version of your patch as fresh new submission, with proper subject prefix. In this case, it should be [PATCH net v2]. 'net' because this is a bugfix and it should therefore target the 'net' tree. 'v2' because that's the second version of this series.

Also it'd be good if you could add a proper 'Fixes' tag in order to help with stable backports. If the bug has always been there, just say so.

I have no expertise on slhc, but overall, the patch content looks fine.

Guillaume

maintainer
#4 lore raw
In reply to [email protected]

From: [email protected]
Date: Tue, 10 Apr 2018 11:28:10 +0530

Quoted 12 lines · David Miller
Quoted 11 lines

From: Tejaswi Tanikella <[email protected]>
Date: Mon, 9 Apr 2018 14:23:49 +0530

Quoted 7 lines
drivers/net/slip/slhc.c +1 -0
@@ -673,6 +677,7 @@ struct slcompress *
 	if (cs->cs_tcp.doff > 5)
 	  memcpy(cs->cs_tcpopt, icp + ihl*4 + sizeof(struct tcphdr),
 	  (cs->cs_tcp.doff - 5) * 4);
 	cs->cs_hsize = ihl*2 + cs->cs_tcp.doff*2;
+	cs->initialized = 1;
 	/* Put headers back on packet

...

Quoted 6 lines
Quoted 4 lines

Review

Quoted 3 lines

struct cstate {

(quoted diff) +1 -0
 	byte_t	cs_this;	/* connection id number (xmit) */
+	byte_t	initialized;	/* non-zero if initialized */

Please use 'bool' and true/false for 'initialized'.

Made the changes.

Please, when you are asked to fix a patch, post it as a new posting with '[PATCH v2 net] slip: ...' in the subject line.

And also not as an attachment, all patches must be inline.

Thank you.