[SCTP] Implementation of SCTP Implementer's Guide Section 2.35.

Linux Kernel Mailing List <[email protected]>
Newsgroups gmane.linux.kernel.commits.2-4
Message-ID <[email protected]>
ChangeSet 1.1530.1.15, 2004/12/28 16:20:16-08:00, [email protected]

	[SCTP] Implementation of SCTP Implementer's Guide Section 2.35.
	This code checks that the verification tag, source port and
	destination port in the SCTP header matches the information
	contained in the state cookie.
	
	Signed-off-by: Vladislav Yasevich <[email protected]>
	Signed-off-by: Sridhar Samudrala <[email protected]>



 include/net/sctp/constants.h |    1 +
 include/net/sctp/structs.h   |    9 +++++++++
 net/sctp/associola.c         |    1 +
 net/sctp/sm_make_chunk.c     |   18 ++++++++++++++++++
 4 files changed, 29 insertions(+)


diff -Nru a/include/net/sctp/constants.h b/include/net/sctp/constants.h
--- a/include/net/sctp/constants.h	2005-01-15 07:05:35 -08:00
+++ b/include/net/sctp/constants.h	2005-01-15 07:05:35 -08:00
@@ -176,6 +176,7 @@
 	SCTP_IERROR_IGNORE_TSN,
 	SCTP_IERROR_NO_DATA,
 	SCTP_IERROR_BAD_STREAM,
+	SCTP_IERROR_BAD_PORTS,
 
 } sctp_ierror_t;
 
diff -Nru a/include/net/sctp/structs.h b/include/net/sctp/structs.h
--- a/include/net/sctp/structs.h	2005-01-15 07:05:35 -08:00
+++ b/include/net/sctp/structs.h	2005-01-15 07:05:35 -08:00
@@ -322,9 +322,18 @@
 	/* This holds the originating address of the INIT packet.  */
 	union sctp_addr peer_addr;
 
+	/* IG Section 2.35.3 
+	 * Include the source port of the INIT-ACK
+	 */
+	__u16		my_port;
+
 	__u8 prsctp_capable;
 
+	/* Padding for future use */
+	__u8 padding;  		
+
 	__u32 adaption_ind;	
+
 
 	/* This is a shim for my peer's INIT packet, followed by
 	 * a copy of the raw address list of the association.
diff -Nru a/net/sctp/associola.c b/net/sctp/associola.c
--- a/net/sctp/associola.c	2005-01-15 07:05:35 -08:00
+++ b/net/sctp/associola.c	2005-01-15 07:05:35 -08:00
@@ -179,6 +179,7 @@
 	asoc->c.peer_vtag = 0;
 	asoc->c.my_ttag   = 0;
 	asoc->c.peer_ttag = 0;
+	asoc->c.my_port = ep->base.bind_addr.port;
 
 	asoc->c.initial_tsn = sctp_generate_tsn(ep);
 
diff -Nru a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
--- a/net/sctp/sm_make_chunk.c	2005-01-15 07:05:35 -08:00
+++ b/net/sctp/sm_make_chunk.c	2005-01-15 07:05:35 -08:00
@@ -1401,6 +1401,24 @@
 	}
 
 no_hmac:
+	/* IG Section 2.35.2:
+	 *  3) Compare the port numbers and the verification tag contained
+	 *     within the COOKIE ECHO chunk to the actual port numbers and the
+	 *     verification tag within the SCTP common header of the received
+	 *     packet. If these values do not match the packet MUST be silently
+	 *     discarded,
+	 */
+	if (ntohl(chunk->sctp_hdr->vtag) != bear_cookie->my_vtag) {
+		*error = -SCTP_IERROR_BAD_TAG;
+		goto fail;
+	}
+
+	if (ntohs(chunk->sctp_hdr->source) != bear_cookie->peer_addr.v4.sin_port ||
+	    ntohs(chunk->sctp_hdr->dest) != bear_cookie->my_port) {
+		*error = -SCTP_IERROR_BAD_PORTS;
+		goto fail;
+	}
+
 	/* Check to see if the cookie is stale.  If there is already
 	 * an association, there is no need to check cookie's expiration
 	 * for init collision case of lost COOKIE ACK.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.