sctp: improve locking

While there, do some cleanup.

Reported by:	syzbot+f475e054c454310bc26d@syzkaller.appspotmail.com
MFC after:	3 day
This commit is contained in:
Michael Tuexen 2022-04-27 16:07:31 +02:00
parent c40e434988
commit 490a0f77de

View File

@ -4870,8 +4870,9 @@ sctp_add_to_readq(struct sctp_inpcb *inp,
#endif
return;
}
if (inp_read_lock_held == 0)
if (inp_read_lock_held == SCTP_READ_LOCK_NOT_HELD) {
SCTP_INP_READ_LOCK(inp);
}
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_CANT_READ) {
if (!control->on_strm_q) {
sctp_free_remote_addr(control->whoFrom);
@ -4881,8 +4882,9 @@ sctp_add_to_readq(struct sctp_inpcb *inp,
}
sctp_free_a_readq(stcb, control);
}
if (inp_read_lock_held == 0)
if (inp_read_lock_held == SCTP_READ_LOCK_NOT_HELD) {
SCTP_INP_READ_UNLOCK(inp);
}
return;
}
if (!(control->spec_flags & M_NOTIFICATION)) {
@ -4894,7 +4896,7 @@ sctp_add_to_readq(struct sctp_inpcb *inp,
m = control->data;
control->held_length = 0;
control->length = 0;
while (m) {
while (m != NULL) {
if (SCTP_BUF_LEN(m) == 0) {
/* Skip mbufs with NO length */
if (prev == NULL) {
@ -4938,11 +4940,12 @@ sctp_add_to_readq(struct sctp_inpcb *inp,
}
TAILQ_INSERT_TAIL(&inp->read_queue, control, next);
control->on_read_q = 1;
if (inp_read_lock_held == 0)
SCTP_INP_READ_UNLOCK(inp);
if (inp && inp->sctp_socket) {
if ((inp != NULL) && (inp->sctp_socket != NULL)) {
sctp_wakeup_the_read_socket(inp, stcb, so_locked);
}
if (inp_read_lock_held == SCTP_READ_LOCK_NOT_HELD) {
SCTP_INP_READ_UNLOCK(inp);
}
}
/*************HOLD THIS COMMENT FOR PATCH FILE OF