Skip to content

Commit 7115e63

Browse files
Wei Yongjundavem330
authored andcommitted
sctp: Validate Initiate Tag when handling ICMP message
This patch add to validate initiate tag and chunk type if verification tag is 0 when handling ICMP message. RFC 4960, Appendix C. ICMP Handling ICMP6) An implementation MUST validate that the Verification Tag contained in the ICMP message matches the Verification Tag of the peer. If the Verification Tag is not 0 and does NOT match, discard the ICMP message. If it is 0 and the ICMP message contains enough bytes to verify that the chunk type is an INIT chunk and that the Initiate Tag matches the tag of the peer, continue with ICMP7. If the ICMP message is too short or the chunk type or the Initiate Tag does not match, silently discard the packet. Signed-off-by: Wei Yongjun <[email protected]> Signed-off-by: Vlad Yasevich <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0344f1c commit 7115e63

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

net/sctp/input.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ struct sock *sctp_err_lookup(int family, struct sk_buff *skb,
430430
struct sock *sk = NULL;
431431
struct sctp_association *asoc;
432432
struct sctp_transport *transport = NULL;
433+
struct sctp_init_chunk *chunkhdr;
434+
__u32 vtag = ntohl(sctphdr->vtag);
435+
int len = skb->len - ((void *)sctphdr - (void *)skb->data);
433436

434437
*app = NULL; *tpp = NULL;
435438

@@ -451,8 +454,28 @@ struct sock *sctp_err_lookup(int family, struct sk_buff *skb,
451454

452455
sk = asoc->base.sk;
453456

454-
if (ntohl(sctphdr->vtag) != asoc->c.peer_vtag) {
455-
ICMP_INC_STATS_BH(ICMP_MIB_INERRORS);
457+
/* RFC 4960, Appendix C. ICMP Handling
458+
*
459+
* ICMP6) An implementation MUST validate that the Verification Tag
460+
* contained in the ICMP message matches the Verification Tag of
461+
* the peer. If the Verification Tag is not 0 and does NOT
462+
* match, discard the ICMP message. If it is 0 and the ICMP
463+
* message contains enough bytes to verify that the chunk type is
464+
* an INIT chunk and that the Initiate Tag matches the tag of the
465+
* peer, continue with ICMP7. If the ICMP message is too short
466+
* or the chunk type or the Initiate Tag does not match, silently
467+
* discard the packet.
468+
*/
469+
if (vtag == 0) {
470+
chunkhdr = (struct sctp_init_chunk *)((void *)sctphdr
471+
+ sizeof(struct sctphdr));
472+
if (len < sizeof(struct sctphdr) + sizeof(sctp_chunkhdr_t)
473+
+ sizeof(__be32) ||
474+
chunkhdr->chunk_hdr.type != SCTP_CID_INIT ||
475+
ntohl(chunkhdr->init_hdr.init_tag) != asoc->c.my_vtag) {
476+
goto out;
477+
}
478+
} else if (vtag != asoc->c.peer_vtag) {
456479
goto out;
457480
}
458481

0 commit comments

Comments
 (0)