From: sashiko-bot@kernel.org
To: "Bryam Vargas" <hexlabsecurity@proton.me>
Cc: linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH RFC net v5 08/10] net/iucv: return EOF to a reader parked when the peer closes
Date: Sat, 05 Dec 2026 03:02:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-250969@kernel.org> (raw)
In-Reply-To: <20261203-b4-disp-8029c32d-v5-8-0bce531e20d0@proton.me>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] net/iucv: spurious -ENOTCONN with unread skb in
iucv_sock_recv_skb()
- [Medium] net/iucv: premature EOF race with afiucv_hs_callback_rx() in
wait loop
- [Medium] net/iucv: inverted sk_state and sk_shutdown write order in
afiucv_hs_fin()
- [Low] net/iucv: unlocked plain queue and state reads in
iucv_sock_recv_skb()
--
commit 6854a3fcb4e6608b2df648d05777c99e3260a82a
Author: Bryam Vargas <hexlabsecurity@proton.me>
net/iucv: return EOF to a reader parked when the peer closes
This commit sets RCV_SHUTDOWN when applying a HiperSockets FIN so poll()
reports EPOLLRDHUP, and changes iucv_sock_recv_skb() to return EOF
instead of -ENOTCONN when the socket is IUCV_DISCONN with empty queues.
Link: https://lore.kernel.org/netdev/51a4a40a-f34b-4d41-b049-69aa53f4dcf5@linux.ibm.com/
> diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
> index b9eecebbdff10..8336f7056d49c 100644
> --- a/net/iucv/af_iucv.c
> +++ b/net/iucv/af_iucv.c
> @@ -75,6 +75,8 @@ static void afiucv_hs_synfin(struct sock *sk)
> static void afiucv_hs_fin(struct sock *sk)
> {
> sk->sk_state = IUCV_DISCONN;
> + /* as a TCP FIN: EOF for a reader, EPOLLRDHUP for poll() */
> + WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN);
> sk->sk_state_change(sk);
> }
[Severity: Medium]
Can writing sk->sk_state before RCV_SHUTDOWN cause a concurrent poll() to
miss EPOLLRDHUP, EPOLLRDNORM, and EPOLLHUP on a peer FIN?
iucv_sock_poll() runs without locks and reads sk->sk_shutdown before
testing sk->sk_state == IUCV_DISCONN:
CPU0 CPU1
iucv_sock_poll()
reads sk->sk_shutdown (0)
afiucv_hs_fin()
sk->sk_state = IUCV_DISCONN
sk->sk_state == IUCV_DISCONN
returns EPOLLIN only <-- misses EPOLLRDHUP/EPOLLRDNORM
sk->sk_shutdown |= RCV_SHUTDOWN
sk->sk_state_change(sk)
If SEND_SHUTDOWN was already set, poll() misses EPOLLHUP as well.
Setting RCV_SHUTDOWN before sk->sk_state = IUCV_DISCONN with release/
acquire (or smp_wmb()/smp_rmb()) ordering, as tcp_fin() and tcp_poll()
do, would prevent poll() from observing IUCV_DISCONN before RCV_SHUTDOWN.
[ ... ]
> @@ -1459,7 +1462,16 @@ static struct sk_buff *iucv_sock_recv_skb(struct sock *sk, int flags, int *err)
> if (!timeo)
> break;
> if (sk->sk_state != IUCV_CONNECTED) {
> - *err = -ENOTCONN;
> + /* disconnected and nothing left to read: EOF, as at
> + * the top of iucv_sock_recvmsg()
> + */
> + if (sk->sk_state == IUCV_DISCONN &&
> + skb_queue_empty(&iucv_sk(sk)->backlog_skb_q) &&
> + skb_queue_empty(&sk->sk_receive_queue) &&
> + list_empty(&iucv_sk(sk)->message_q.list))
> + *err = 0;
> + else
> + *err = -ENOTCONN;
> break;
> }
> if (signal_pending(current)) {
[Severity: Medium]
Should this branch retry dequeuing instead of returning -ENOTCONN when
sk->sk_receive_queue is no longer empty?
Even with lock_sock(sk) held, afiucv_hs_callback_rx() can queue a frame
onto sk->sk_receive_queue and afiucv_netdev_event() can set
sk->sk_state = IUCV_DISCONN without RCV_SHUTDOWN between
skb_recv_datagram() and the sk_state check. This code then sees
sk_receive_queue is non-empty and falls into the else branch, returning
-ENOTCONN while an unread skb is sitting on the queue; callers that treat
-ENOTCONN as fatal will close the socket and drop that message.
Checking !skb_queue_empty_lockless(queue) and continuing the loop, as
__skb_wait_for_more_packets() does in net/core/datagram.c, would deliver
the queued skb before checking sk_state.
[Severity: Medium]
Can this check return a premature EOF while afiucv_hs_callback_rx() is
still enqueuing an already-accepted frame?
CPU0 CPU1 CPU2
iucv_sock_recv_skb()
afiucv_hs_callback_rx()
sk_state == CONNECTED
skb_pull()/sk_filter()
afiucv_netdev_event()
sk_state = IUCV_DISCONN
sk_state == IUCV_DISCONN
all queues empty
*err = 0 <-- EOF
__sock_queue_rcv_skb()
afiucv_netdev_event() sets sk->sk_state = IUCV_DISCONN without taking
lock_sock(sk), bh_lock_sock(sk), or iucv->message_q.lock. Because
iucv_sock_recv_skb() holds only lock_sock(sk), it can observe
IUCV_DISCONN and empty queues before afiucv_hs_callback_rx() queues the
frame onto sk->sk_receive_queue, silently losing the message when
userspace closes on EOF.
[Severity: Low]
Should these checks use READ_ONCE(sk->sk_state) and
skb_queue_empty_lockless()?
iucv_sock_recv_skb() holds only lock_sock(sk), while
afiucv_hs_callback_rx() and iucv_callback_rx() concurrently modify
backlog_skb_q and sk_receive_queue without it, and afiucv_netdev_event()
updates sk->sk_state without it as well. skb_queue_empty() does a plain
load of list->next (unlike skb_queue_empty_lockless() later in this
function and list_empty() below it), and sk->sk_state is read twice
without READ_ONCE(). These unlocked plain loads are data races that will
trigger KCSAN reports and allow the compiler to reload sk->sk_state
between the two checks.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-disp-8029c32d-v5-0-0bce531e20d0@proton.me?part=8
next prev parent reply other threads:[~2026-12-05 3:02 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 3:02 [PATCH RFC net v5 00/10] net/iucv: serialize the HiperSockets receive path with the socket lock Bryam Vargas
2026-12-04 3:02 ` Bryam Vargas via B4 Relay
2026-12-04 3:02 ` [PATCH RFC net v5 01/10] net/iucv: record that a HiperSockets socket sent its SYN Bryam Vargas
2026-12-04 3:02 ` Bryam Vargas via B4 Relay
2026-12-04 18:58 ` Alexandra Winter
2026-12-04 3:02 ` [PATCH RFC net v5 02/10] net/iucv: do not clear SEND_SHUTDOWN to send a control frame Bryam Vargas
2026-12-04 3:02 ` Bryam Vargas via B4 Relay
2026-12-04 3:02 ` [PATCH RFC net v5 03/10] net/iucv: fail sendmsg() with EPIPE once sending is shut down Bryam Vargas
2026-12-04 3:02 ` Bryam Vargas via B4 Relay
2026-12-05 3:02 ` sashiko-bot
2026-12-04 3:02 ` [PATCH RFC net v5 04/10] net/iucv: run recvmsg() under the socket lock Bryam Vargas
2026-12-04 3:02 ` Bryam Vargas via B4 Relay
2026-12-05 3:02 ` sashiko-bot
2026-12-04 3:02 ` [PATCH RFC net v5 05/10] net/iucv: factor out the HiperSockets frame dispatch and state changes Bryam Vargas
2026-12-04 3:02 ` Bryam Vargas via B4 Relay
2026-12-04 3:02 ` [PATCH RFC net v5 06/10] net/iucv: serialize HiperSockets receive with the socket lock Bryam Vargas
2026-12-04 3:02 ` Bryam Vargas via B4 Relay
2026-12-05 3:02 ` sashiko-bot
2026-12-04 3:02 ` [PATCH RFC net v5 07/10] net/iucv: set RCV_SHUTDOWN under the socket spinlock Bryam Vargas
2026-12-04 3:02 ` Bryam Vargas via B4 Relay
2026-12-05 3:02 ` sashiko-bot
2026-12-04 3:02 ` [PATCH RFC net v5 08/10] net/iucv: return EOF to a reader parked when the peer closes Bryam Vargas
2026-12-04 3:02 ` Bryam Vargas via B4 Relay
2026-12-05 3:02 ` sashiko-bot [this message]
2026-12-04 3:02 ` [PATCH RFC net v5 09/10] net/iucv: decrement pendings when a pending frame's transmit fails Bryam Vargas
2026-12-04 3:02 ` Bryam Vargas via B4 Relay
2026-12-05 3:02 ` sashiko-bot
2026-12-04 3:02 ` [PATCH RFC net v5 10/10] net/iucv: forget a SYN that the device reports unreachable Bryam Vargas
2026-12-04 3:02 ` Bryam Vargas via B4 Relay
2026-12-05 3:02 ` sashiko-bot
2026-12-04 11:05 ` [PATCH RFC net v5 00/10] net/iucv: serialize the HiperSockets receive path with the socket lock Hidayath Khan
2026-12-05 3:02 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-250969@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=hexlabsecurity@proton.me \
--cc=linux-s390@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.