Skip to content

Commit

Permalink
[SCTP]: Fix potential race condition between sctp_close() and sctp_rc…
Browse files Browse the repository at this point in the history
…v().

Do not release the reference to association/endpoint if an incoming skb is
added to backlog. Instead release it after the chunk is processed in
sctp_backlog_rcv().

Signed-off-by: Sridhar Samudrala <[email protected]>
Signed-off-by: Vlad Yasevich <[email protected]>
  • Loading branch information
Sridhar Samudrala committed Jan 17, 2006
1 parent 2664b25 commit 7a48f92
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
29 changes: 20 additions & 9 deletions net/sctp/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,12 @@ int sctp_rcv(struct sk_buff *skb)
else
sctp_backlog_rcv(sk, skb);

/* Release the sock and any reference counts we took in the
* lookup calls.
/* Release the sock and the sock ref we took in the lookup calls.
* The asoc/ep ref will be released in sctp_backlog_rcv.
*/
sctp_bh_unlock_sock(sk);
if (asoc)
sctp_association_put(asoc);
else
sctp_endpoint_put(ep);
sock_put(sk);

return ret;

discard_it:
Expand All @@ -296,9 +293,23 @@ int sctp_rcv(struct sk_buff *skb)
int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb)
{
struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk;
struct sctp_inq *inqueue = &chunk->rcvr->inqueue;

sctp_inq_push(inqueue, chunk);
struct sctp_inq *inqueue = NULL;
struct sctp_ep_common *rcvr = NULL;

rcvr = chunk->rcvr;
if (rcvr->dead) {
sctp_chunk_free(chunk);
} else {
inqueue = &chunk->rcvr->inqueue;
sctp_inq_push(inqueue, chunk);
}

/* Release the asoc/ep ref we took in the lookup calls in sctp_rcv. */
if (SCTP_EP_TYPE_ASSOCIATION == rcvr->type)
sctp_association_put(sctp_assoc(rcvr));
else
sctp_endpoint_put(sctp_ep(rcvr));

return 0;
}

Expand Down
4 changes: 3 additions & 1 deletion net/sctp/inqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ void sctp_inq_free(struct sctp_inq *queue)
/* If there is a packet which is currently being worked on,
* free it as well.
*/
if (queue->in_progress)
if (queue->in_progress) {
sctp_chunk_free(queue->in_progress);
queue->in_progress = NULL;
}

if (queue->malloced) {
/* Dump the master memory segment. */
Expand Down

0 comments on commit 7a48f92

Please sign in to comment.