Skip to content

Commit bbd0d59

Browse files
Vlad YasevichDavid S. Miller
authored andcommitted
[SCTP]: Implement the receive and verification of AUTH chunk
This patch implements the receive path needed to process authenticated chunks. Add ability to process the AUTH chunk and handle edge cases for authenticated COOKIE-ECHO as well. Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4cd57c8 commit bbd0d59

9 files changed

Lines changed: 374 additions & 13 deletions

File tree

‎include/net/sctp/constants.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ typedef enum {
183183
SCTP_IERROR_NO_DATA,
184184
SCTP_IERROR_BAD_STREAM,
185185
SCTP_IERROR_BAD_PORTS,
186-
186+
SCTP_IERROR_AUTH_BAD_HMAC,
187+
SCTP_IERROR_AUTH_BAD_KEYID,
188+
SCTP_IERROR_PROTO_VIOLATION,
187189
} sctp_ierror_t;
188190

189191

‎include/net/sctp/sm.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ sctp_state_fn_t sctp_sf_do_asconf_ack;
143143
sctp_state_fn_t sctp_sf_do_9_2_reshutack;
144144
sctp_state_fn_t sctp_sf_eat_fwd_tsn;
145145
sctp_state_fn_t sctp_sf_eat_fwd_tsn_fast;
146+
sctp_state_fn_t sctp_sf_eat_auth;
146147

147148
/* Prototypes for primitive event state functions. */
148149
sctp_state_fn_t sctp_sf_do_prm_asoc;

‎include/net/sctp/structs.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,13 @@ struct sctp_chunk {
724724
*/
725725
struct sctp_transport *transport;
726726

727+
/* SCTP-AUTH: For the special case inbound processing of COOKIE-ECHO
728+
* we need save a pointer to the AUTH chunk, since the SCTP-AUTH
729+
* spec violates the principle premis that all chunks are processed
730+
* in order.
731+
*/
732+
struct sk_buff *auth_chunk;
733+
727734
__u8 rtt_in_progress; /* Is this chunk used for RTT calculation? */
728735
__u8 resent; /* Has this chunk ever been retransmitted. */
729736
__u8 has_tsn; /* Does this chunk have a TSN yet? */
@@ -1067,6 +1074,7 @@ void sctp_inq_init(struct sctp_inq *);
10671074
void sctp_inq_free(struct sctp_inq *);
10681075
void sctp_inq_push(struct sctp_inq *, struct sctp_chunk *packet);
10691076
struct sctp_chunk *sctp_inq_pop(struct sctp_inq *);
1077+
struct sctp_chunkhdr *sctp_inq_peek(struct sctp_inq *);
10701078
void sctp_inq_set_th_handler(struct sctp_inq *, work_func_t);
10711079

10721080
/* This is the structure we use to hold outbound chunks. You push

‎net/sctp/associola.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,16 @@ static void sctp_assoc_bh_rcv(struct work_struct *work)
10111011
state = asoc->state;
10121012
subtype = SCTP_ST_CHUNK(chunk->chunk_hdr->type);
10131013

1014+
/* SCTP-AUTH, Section 6.3:
1015+
* The receiver has a list of chunk types which it expects
1016+
* to be received only after an AUTH-chunk. This list has
1017+
* been sent to the peer during the association setup. It
1018+
* MUST silently discard these chunks if they are not placed
1019+
* after an AUTH chunk in the packet.
1020+
*/
1021+
if (sctp_auth_recv_cid(subtype.chunk, asoc) && !chunk->auth)
1022+
continue;
1023+
10141024
/* Remember where the last DATA chunk came from so we
10151025
* know where to send the SACK.
10161026
*/

‎net/sctp/endpointola.c‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ static void sctp_endpoint_bh_rcv(struct work_struct *work)
400400
sctp_subtype_t subtype;
401401
sctp_state_t state;
402402
int error = 0;
403+
int first_time = 1; /* is this the first time through the looop */
403404

404405
if (ep->base.dead)
405406
return;
@@ -411,6 +412,29 @@ static void sctp_endpoint_bh_rcv(struct work_struct *work)
411412
while (NULL != (chunk = sctp_inq_pop(inqueue))) {
412413
subtype = SCTP_ST_CHUNK(chunk->chunk_hdr->type);
413414

415+
/* If the first chunk in the packet is AUTH, do special
416+
* processing specified in Section 6.3 of SCTP-AUTH spec
417+
*/
418+
if (first_time && (subtype.chunk == SCTP_CID_AUTH)) {
419+
struct sctp_chunkhdr *next_hdr;
420+
421+
next_hdr = sctp_inq_peek(inqueue);
422+
if (!next_hdr)
423+
goto normal;
424+
425+
/* If the next chunk is COOKIE-ECHO, skip the AUTH
426+
* chunk while saving a pointer to it so we can do
427+
* Authentication later (during cookie-echo
428+
* processing).
429+
*/
430+
if (next_hdr->type == SCTP_CID_COOKIE_ECHO) {
431+
chunk->auth_chunk = skb_clone(chunk->skb,
432+
GFP_ATOMIC);
433+
chunk->auth = 1;
434+
continue;
435+
}
436+
}
437+
normal:
414438
/* We might have grown an association since last we
415439
* looked, so try again.
416440
*
@@ -426,6 +450,8 @@ static void sctp_endpoint_bh_rcv(struct work_struct *work)
426450
}
427451

428452
state = asoc ? asoc->state : SCTP_STATE_CLOSED;
453+
if (sctp_auth_recv_cid(subtype.chunk, asoc) && !chunk->auth)
454+
continue;
429455

430456
/* Remember where the last DATA chunk came from so we
431457
* know where to send the SACK.
@@ -449,5 +475,8 @@ static void sctp_endpoint_bh_rcv(struct work_struct *work)
449475
*/
450476
if (!sctp_sk(sk)->ep)
451477
break;
478+
479+
if (first_time)
480+
first_time = 0;
452481
}
453482
}

‎net/sctp/input.c‎

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -911,15 +911,6 @@ static struct sctp_association *__sctp_rcv_init_lookup(struct sk_buff *skb,
911911

912912
ch = (sctp_chunkhdr_t *) skb->data;
913913

914-
/* If this is INIT/INIT-ACK look inside the chunk too. */
915-
switch (ch->type) {
916-
case SCTP_CID_INIT:
917-
case SCTP_CID_INIT_ACK:
918-
break;
919-
default:
920-
return NULL;
921-
}
922-
923914
/* The code below will attempt to walk the chunk and extract
924915
* parameter information. Before we do that, we need to verify
925916
* that the chunk length doesn't cause overflow. Otherwise, we'll
@@ -964,6 +955,60 @@ static struct sctp_association *__sctp_rcv_init_lookup(struct sk_buff *skb,
964955
return NULL;
965956
}
966957

958+
/* SCTP-AUTH, Section 6.3:
959+
* If the receiver does not find a STCB for a packet containing an AUTH
960+
* chunk as the first chunk and not a COOKIE-ECHO chunk as the second
961+
* chunk, it MUST use the chunks after the AUTH chunk to look up an existing
962+
* association.
963+
*
964+
* This means that any chunks that can help us identify the association need
965+
* to be looked at to find this assocation.
966+
*
967+
* TODO: The only chunk currently defined that can do that is ASCONF, but we
968+
* don't support that functionality yet.
969+
*/
970+
static struct sctp_association *__sctp_rcv_auth_lookup(struct sk_buff *skb,
971+
const union sctp_addr *paddr,
972+
const union sctp_addr *laddr,
973+
struct sctp_transport **transportp)
974+
{
975+
/* XXX - walk through the chunks looking for something that can
976+
* help us find the association. INIT, and INIT-ACK are not permitted.
977+
* That leaves ASCONF, but we don't support that yet.
978+
*/
979+
return NULL;
980+
}
981+
982+
/*
983+
* There are circumstances when we need to look inside the SCTP packet
984+
* for information to help us find the association. Examples
985+
* include looking inside of INIT/INIT-ACK chunks or after the AUTH
986+
* chunks.
987+
*/
988+
static struct sctp_association *__sctp_rcv_lookup_harder(struct sk_buff *skb,
989+
const union sctp_addr *paddr,
990+
const union sctp_addr *laddr,
991+
struct sctp_transport **transportp)
992+
{
993+
sctp_chunkhdr_t *ch;
994+
995+
ch = (sctp_chunkhdr_t *) skb->data;
996+
997+
/* If this is INIT/INIT-ACK look inside the chunk too. */
998+
switch (ch->type) {
999+
case SCTP_CID_INIT:
1000+
case SCTP_CID_INIT_ACK:
1001+
return __sctp_rcv_init_lookup(skb, laddr, transportp);
1002+
break;
1003+
1004+
case SCTP_CID_AUTH:
1005+
return __sctp_rcv_auth_lookup(skb, paddr, laddr, transportp);
1006+
break;
1007+
}
1008+
1009+
return NULL;
1010+
}
1011+
9671012
/* Lookup an association for an inbound skb. */
9681013
static struct sctp_association *__sctp_rcv_lookup(struct sk_buff *skb,
9691014
const union sctp_addr *paddr,
@@ -979,7 +1024,7 @@ static struct sctp_association *__sctp_rcv_lookup(struct sk_buff *skb,
9791024
* parameters within the INIT or INIT-ACK.
9801025
*/
9811026
if (!asoc)
982-
asoc = __sctp_rcv_init_lookup(skb, laddr, transportp);
1027+
asoc = __sctp_rcv_lookup_harder(skb, paddr, laddr, transportp);
9831028

9841029
return asoc;
9851030
}

‎net/sctp/inqueue.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ void sctp_inq_push(struct sctp_inq *q, struct sctp_chunk *chunk)
100100
q->immediate.func(&q->immediate);
101101
}
102102

103+
/* Peek at the next chunk on the inqeue. */
104+
struct sctp_chunkhdr *sctp_inq_peek(struct sctp_inq *queue)
105+
{
106+
struct sctp_chunk *chunk;
107+
sctp_chunkhdr_t *ch = NULL;
108+
109+
chunk = queue->in_progress;
110+
/* If there is no more chunks in this packet, say so */
111+
if (chunk->singleton ||
112+
chunk->end_of_packet ||
113+
chunk->pdiscard)
114+
return NULL;
115+
116+
ch = (sctp_chunkhdr_t *)chunk->chunk_end;
117+
118+
return ch;
119+
}
120+
121+
103122
/* Extract a chunk from an SCTP inqueue.
104123
*
105124
* WARNING: If you need to put the chunk on another queue, you need to

0 commit comments

Comments
 (0)