[PATCH 1/7] sctp: don't let a blocked reader take write-space wakeups
From: Linus Torvalds
Date: Tue Nov 24 2026 - 12:43:34 EST
From: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 23 Nov 2026 17:33:14 -0800
Subject: [PATCH 1/7] sctp: don't let a blocked reader take write-space wakeups
sctp_wait_for_packet() waits exclusively on sk_sleep() with the default
autoremove wake function, so it accepts any wakeup and consumes it.
Then __sctp_write_space() sends EPOLLOUT with a wake-one wakeup:
sctp_wait_for_packet() wakes up, finds no data, goes back to sleep, and
the walk stops.
End result: anybody else queued behind it that was waiting for EPOLLOUT
will never see it.
Filter on EPOLLIN | EPOLLERR like receiver_wake_function() in
net/core/datagram.c. State changes (using sock_def_wakeup()) use an
unkeyed wake-all and still get through and will ignore the exclusive
nature of sctp_wait_for_packet().
Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
Cc: Marcelo Ricardo Leitner <marcelo.leitner@xxxxxxxxx>
Cc: Xin Long <lucien.xin@xxxxxxxxx>
Cc: Eric Dumazet <edumazet@xxxxxxxxxx>
Cc: Jakub Kicinski <kuba@xxxxxxxxxx>
Cc: Paolo Abeni <pabeni@xxxxxxxxxx>
Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
---
net/sctp/socket.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index bc68af88e271..85ac4952e9cb 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -9070,6 +9070,15 @@ static int sctp_msghdr_parse(const struct
msghdr *msg, struct sctp_cmsgs *cmsgs)
return 0;
}
+/* Don't take wakeups for other events, e.g. EPOLLOUT from write space. */
+static int sctp_receiver_wake_function(wait_queue_entry_t *wait,
+ unsigned int mode, int sync, void *key)
+{
+ if (key && !(key_to_poll(key) & (EPOLLIN | EPOLLERR)))
+ return 0;
+ return autoremove_wake_function(wait, mode, sync, key);
+}
+
/*
* Wait for a packet..
* Note: This function is the same function as in core/datagram.c
@@ -9078,7 +9087,7 @@ static int sctp_msghdr_parse(const struct msghdr
*msg, struct sctp_cmsgs *cmsgs)
static int sctp_wait_for_packet(struct sock *sk, int *err, long *timeo_p)
{
int error;
- DEFINE_WAIT(wait);
+ DEFINE_WAIT_FUNC(wait, sctp_receiver_wake_function);
prepare_to_wait_exclusive(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
--
2.56.0.313.g975a75ca90