slip: Check if rstate is initialized before uncompressing
authorTejaswi Tanikella <tejaswit@codeaurora.org>
Wed, 11 Apr 2018 11:04:47 +0000 (16:34 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 19 Apr 2018 06:56:16 +0000 (08:56 +0200)
[ Upstream commit 3f01ddb962dc506916c243f9524e8bef97119b77 ]

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.

Signed-off-by: Tejaswi Tanikella <tejaswit@codeaurora.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/slip/slhc.c
include/net/slhc_vj.h

index 5782733959f0e0a7648d92ae1717065eb72b85fd..f4e93f5fc2043ebb29c5b36e94afe49ec0c7d7ba 100644 (file)
@@ -509,6 +509,10 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
                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 @@ slhc_remember(struct slcompress *comp, unsigned char *icp, int isize)
        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
         */
index 8716d5942b6561dc1cfd037ccfb7d732d26eba07..8fcf8908a694fb63a7316d1b0f760511d189e880 100644 (file)
@@ -127,6 +127,7 @@ typedef __u32 int32;
  */
 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;