Skip to content

Commit

Permalink
sctp: get rid of stcb send lock
Browse files Browse the repository at this point in the history
Just use the stcb lock instead to simplify locking.

Reported by:	syzbot+d00b202063150f85b110@syzkaller.appspotmail.com
Reported by:	syzbot+87f268a0a6d2d6383306@syzkaller.appspotmail.com
MFC after:	3 days
  • Loading branch information
tuexen committed Mar 28, 2022
1 parent c1970a7 commit 5ac9182
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 406 deletions.
11 changes: 4 additions & 7 deletions sys/netinet/sctp_input.c
Expand Up @@ -179,14 +179,15 @@ sctp_is_there_unsent_data(struct sctp_tcb *stcb, int so_locked)
struct sctp_stream_queue_pending *sp;
struct sctp_association *asoc;

SCTP_TCB_LOCK_ASSERT(stcb);

/*
* This function returns if any stream has true unsent data on it.
* Note that as it looks through it will clean up any places that
* have old data that has been sent but left at top of stream queue.
*/
asoc = &stcb->asoc;
unsent_data = 0;
SCTP_TCB_SEND_LOCK(stcb);
if (!stcb->asoc.ss_functions.sctp_ss_is_empty(stcb, asoc)) {
/* Check to see if some data queued */
for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
Expand Down Expand Up @@ -234,7 +235,6 @@ sctp_is_there_unsent_data(struct sctp_tcb *stcb, int so_locked)
}
}
}
SCTP_TCB_SEND_UNLOCK(stcb);
return (unsent_data);
}

Expand All @@ -246,6 +246,8 @@ sctp_process_init(struct sctp_init_chunk *cp, struct sctp_tcb *stcb)
struct sctp_nets *lnet;
unsigned int i;

SCTP_TCB_LOCK_ASSERT(stcb);

init = &cp->init;
asoc = &stcb->asoc;
/* save off parameters */
Expand All @@ -263,7 +265,6 @@ sctp_process_init(struct sctp_init_chunk *cp, struct sctp_tcb *stcb)
}
}
}
SCTP_TCB_SEND_LOCK(stcb);
if (asoc->pre_open_streams > ntohs(init->num_inbound_streams)) {
unsigned int newcnt;
struct sctp_stream_out *outs;
Expand Down Expand Up @@ -323,7 +324,6 @@ sctp_process_init(struct sctp_init_chunk *cp, struct sctp_tcb *stcb)
/* cut back the count */
asoc->pre_open_streams = newcnt;
}
SCTP_TCB_SEND_UNLOCK(stcb);
asoc->streamoutcnt = asoc->pre_open_streams;
if (asoc->strmout) {
for (i = 0; i < asoc->streamoutcnt; i++) {
Expand Down Expand Up @@ -1808,8 +1808,6 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
SCTP_TCB_LOCK(stcb);
atomic_subtract_int(&stcb->asoc.refcnt, 1);
/* send up all the data */
SCTP_TCB_SEND_LOCK(stcb);

sctp_report_all_outbound(stcb, 0, SCTP_SO_LOCKED);
for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
stcb->asoc.strmout[i].chunks_on_queues = 0;
Expand Down Expand Up @@ -1896,7 +1894,6 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
*/
LIST_INSERT_HEAD(head, stcb, sctp_asocs);

SCTP_TCB_SEND_UNLOCK(stcb);
SCTP_INP_WUNLOCK(stcb->sctp_ep);
SCTP_INP_INFO_WUNLOCK();
asoc->total_flight = 0;
Expand Down
22 changes: 0 additions & 22 deletions sys/netinet/sctp_lock_bsd.h
Expand Up @@ -337,28 +337,6 @@ __FBSDID("$FreeBSD$");
#define SCTP_ASOC_CREATE_LOCK_CONTENDED(_inp) \
((_inp)->inp_create_mtx.mtx_lock & MTX_CONTESTED)

#define SCTP_TCB_SEND_LOCK_INIT(_tcb) do { \
mtx_init(&(_tcb)->tcb_send_mtx, "sctp-send-tcb", "tcbs", \
MTX_DEF | MTX_DUPOK); \
} while (0)

#define SCTP_TCB_SEND_LOCK_DESTROY(_tcb) do { \
mtx_destroy(&(_tcb)->tcb_send_mtx); \
} while (0)

#define SCTP_TCB_SEND_LOCK(_tcb) do { \
mtx_lock(&(_tcb)->tcb_send_mtx); \
} while (0)

#define SCTP_TCB_SEND_UNLOCK(_tcb) do { \
mtx_unlock(&(_tcb)->tcb_send_mtx); \
} while (0)

#define SCTP_TCB_SEND_LOCK_ASSERT(_tcb) do { \
KASSERT(mtx_owned(&(_tcb)->tcb_send_mtx), \
("Don't own TCB send lock")); \
} while (0)

/*
* For the majority of things (once we have found the association) we will
* lock the actual association mutex. This will protect all the assoiciation
Expand Down

0 comments on commit 5ac9182

Please sign in to comment.