Skip to content

Commit cf2e394

Browse files
Julian Anastasovhorms
authored andcommitted
ipvs: fix sctp chunk length order
Fix wrong but non-fatal access to chunk length. sch->length should be in network order, next chunk should be aligned to 4 bytes. Problem noticed in sparse output. Signed-off-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: Simon Horman <horms@verge.net.au>
1 parent a82783c commit cf2e394

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎net/netfilter/ipvs/ip_vs_proto_sctp.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -906,16 +906,16 @@ set_sctp_state(struct ip_vs_proto_data *pd, struct ip_vs_conn *cp,
906906
sctp_chunkhdr_t _sctpch, *sch;
907907
unsigned char chunk_type;
908908
int event, next_state;
909-
int ihl;
909+
int ihl, cofs;
910910

911911
#ifdef CONFIG_IP_VS_IPV6
912912
ihl = cp->af == AF_INET ? ip_hdrlen(skb) : sizeof(struct ipv6hdr);
913913
#else
914914
ihl = ip_hdrlen(skb);
915915
#endif
916916

917-
sch = skb_header_pointer(skb, ihl + sizeof(sctp_sctphdr_t),
918-
sizeof(_sctpch), &_sctpch);
917+
cofs = ihl + sizeof(sctp_sctphdr_t);
918+
sch = skb_header_pointer(skb, cofs, sizeof(_sctpch), &_sctpch);
919919
if (sch == NULL)
920920
return;
921921

@@ -933,10 +933,12 @@ set_sctp_state(struct ip_vs_proto_data *pd, struct ip_vs_conn *cp,
933933
*/
934934
if ((sch->type == SCTP_CID_COOKIE_ECHO) ||
935935
(sch->type == SCTP_CID_COOKIE_ACK)) {
936-
sch = skb_header_pointer(skb, (ihl + sizeof(sctp_sctphdr_t) +
937-
sch->length), sizeof(_sctpch), &_sctpch);
938-
if (sch) {
939-
if (sch->type == SCTP_CID_ABORT)
936+
int clen = ntohs(sch->length);
937+
938+
if (clen >= sizeof(sctp_chunkhdr_t)) {
939+
sch = skb_header_pointer(skb, cofs + ALIGN(clen, 4),
940+
sizeof(_sctpch), &_sctpch);
941+
if (sch && sch->type == SCTP_CID_ABORT)
940942
chunk_type = sch->type;
941943
}
942944
}

0 commit comments

Comments
 (0)