aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>2016-10-25 12:27:39 -0400
committerDavid S. Miller <davem@davemloft.net>2016-10-29 12:00:10 -0400
commitbf911e985d6bbaa328c20c3e05f4eb03de11fdd6 (patch)
tree1b27244b2383e75616e7c1d4a3c1faa329108f99
parentc2e169be8ce7bde1e4189dc6e72eb9861fe9b6fb (diff)
sctp: validate chunk len before actually using it
Andrey Konovalov reported that KASAN detected that SCTP was using a slab beyond the boundaries. It was caused because when handling out of the blue packets in function sctp_sf_ootb() it was checking the chunk len only after already processing the first chunk, validating only for the 2nd and subsequent ones. The fix is to just move the check upwards so it's also validated for the 1st chunk. Reported-by: Andrey Konovalov <andreyknvl@google.com> Tested-by: Andrey Konovalov <andreyknvl@google.com> Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Reviewed-by: Xin Long <lucien.xin@gmail.com> Acked-by: Neil Horman <nhorman@tuxdriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/sctp/sm_statefuns.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 026e3bca4a94..8ec20a64a3f8 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -3422,6 +3422,12 @@ sctp_disposition_t sctp_sf_ootb(struct net *net,
3422 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, 3422 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3423 commands); 3423 commands);
3424 3424
3425 /* Report violation if chunk len overflows */
3426 ch_end = ((__u8 *)ch) + SCTP_PAD4(ntohs(ch->length));
3427 if (ch_end > skb_tail_pointer(skb))
3428 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3429 commands);
3430
3425 /* Now that we know we at least have a chunk header, 3431 /* Now that we know we at least have a chunk header,
3426 * do things that are type appropriate. 3432 * do things that are type appropriate.
3427 */ 3433 */
@@ -3453,12 +3459,6 @@ sctp_disposition_t sctp_sf_ootb(struct net *net,
3453 } 3459 }
3454 } 3460 }
3455 3461
3456 /* Report violation if chunk len overflows */
3457 ch_end = ((__u8 *)ch) + SCTP_PAD4(ntohs(ch->length));
3458 if (ch_end > skb_tail_pointer(skb))
3459 return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
3460 commands);
3461
3462 ch = (sctp_chunkhdr_t *) ch_end; 3462 ch = (sctp_chunkhdr_t *) ch_end;
3463 } while (ch_end < skb_tail_pointer(skb)); 3463 } while (ch_end < skb_tail_pointer(skb));
3464 3464