sctp: validate chunk len before actually using it
authorMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Tue, 25 Oct 2016 16:27:39 +0000 (14:27 -0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 15 Nov 2016 06:46:39 +0000 (07:46 +0100)
commitbd891f40f04f8b96d9148ff8a5d538b60171409c
treedea8bf60bc890c93a54ccf986c5208e3631d0bfa
parent7c230d0e546a3c6fa72485e80b8e5fe8873822d7
sctp: validate chunk len before actually using it

[ Upstream commit bf911e985d6bbaa328c20c3e05f4eb03de11fdd6 ]

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/sctp/sm_statefuns.c