Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: conntrack: fix bug in for_each_sctp_chunk

skb_header_pointer() will return NULL if offset + sizeof(_sch) exceeds
skb->len, so this offset < skb->len test is redundant.

if sch->length == 0, this will end up in an infinite loop, add a check
for sch->length > 0

Fixes: 9fb9cbb1082d ("[NETFILTER]: Add nf_conntrack subsystem.")
Suggested-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Sriram Yagnaraman <sriram.yagnaraman@est.tech>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Sriram Yagnaraman and committed by
Pablo Neira Ayuso
98ee0077 a9993591

+2 -2
+2 -2
net/netfilter/nf_conntrack_proto_sctp.c
··· 160 160 161 161 #define for_each_sctp_chunk(skb, sch, _sch, offset, dataoff, count) \ 162 162 for ((offset) = (dataoff) + sizeof(struct sctphdr), (count) = 0; \ 163 - (offset) < (skb)->len && \ 164 - ((sch) = skb_header_pointer((skb), (offset), sizeof(_sch), &(_sch))); \ 163 + ((sch) = skb_header_pointer((skb), (offset), sizeof(_sch), &(_sch))) && \ 164 + (sch)->length; \ 165 165 (offset) += (ntohs((sch)->length) + 3) & ~3, (count)++) 166 166 167 167 /* Some validity checks to make sure the chunks are fine */