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 06/10] net/iucv: serialize HiperSockets receive with the socket lock
Date: Sat, 05 Dec 2026 03:02:28 +0000 [thread overview]
Message-ID: <sashiko-outbox-250967@kernel.org> (raw)
In-Reply-To: <20261203-b4-disp-8029c32d-v5-6-0bce531e20d0@proton.me>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] net/iucv: unsynchronized sk_state access and listen()
ordering race
- [Medium] net/iucv: unconditional spin_lock_bh() in
afiucv_hs_apply_now()
- [Medium] net/iucv: unconditional sk_lock.slock in
afiucv_hs_apply_now()
--
commit 28a4d9fb269c7f73184d3bc11fbe4ca645c81ec9
Author: Bryam Vargas <hexlabsecurity@proton.me>
net/iucv: serialize HiperSockets receive with the socket lock
This commit takes bh_lock_sock() in afiucv_hs_rcv() and defers HiperSockets
control and receive handling while a task owns the socket, recording SYN
replies and FINs in iucv_sock.hs_pending and queuing SYNs and dependent data
frames onto the socket backlog.
Link: https://lore.kernel.org/all/20260724222917.134769-1-hexlabsecurity@proton.me/
> diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
> index bc60fcaca1b0b..bf97b8c62eb2e 100644
> --- a/net/iucv/af_iucv.c
> +++ b/net/iucv/af_iucv.c
[ ... ]
> @@ -77,10 +78,81 @@ static void afiucv_hs_fin(struct sock *sk)
[ ... ]
> +static void afiucv_hs_apply_now(struct sock *sk, u8 mask)
> +{
> + spin_lock_bh(&sk->sk_lock.slock);
> + afiucv_hs_apply(sk, mask);
> + spin_unlock_bh(&sk->sk_lock.slock);
> +}
[Severity: Medium]
Does afiucv_hs_apply_now() need to take sk->sk_lock.slock unconditionally
when iucv_sk(sk)->hs_pending has no bits matching mask set?
In afiucv_hs_backlog_rcv(), __release_sock() invokes this once per queued
skb, acquiring and releasing sk->sk_lock.slock on every frame after the first
and on every backlogged SYN for a listener even though AF_IUCV_PEND_SYNREPLY
is never set there. An unlocked fast-path check on
READ_ONCE(iucv_sk(sk)->hs_pending) & mask (paired with WRITE_ONCE() updates
to hs_pending) would skip the spinlock and BH disable/enable in the common
case.
[ ... ]
> @@ -214,6 +305,28 @@ static inline int iucv_below_msglim(struct sock *sk)
[ ... ]
> +static bool iucv_sock_send_ready(struct sock *sk)
> +{
> + if (iucv_sk(sk)->transport == AF_IUCV_TRANS_HIPER)
> + afiucv_hs_apply_now(sk, AF_IUCV_PEND_FIN);
> + return iucv_below_msglim(sk) || (sk->sk_shutdown & SEND_SHUTDOWN);
> +}
[Severity: Medium]
Can calling afiucv_hs_apply_now() unconditionally from iucv_sock_send_ready()
add unnecessary sk->sk_lock.slock contention on the HiperSockets TX hot path?
iucv_sock_sendmsg() evaluates iucv_sock_send_ready() on every message, and
twice before sleeping when the send window is full because iucv_sock_wait()
checks its condition in both the outer if and inner while loop. Since a peer
FIN is recorded at most once at teardown, taking sk->sk_lock.slock on every
sendmsg() adds a per-message spin_lock_bh() round-trip that contends with the
per-packet bh_lock_sock() in afiucv_hs_rcv() on full-duplex streams.
[ ... ]
> @@ -865,7 +979,8 @@ static int iucv_sock_listen(struct socket *sock, int backlog)
> if (sock->type != SOCK_STREAM && sock->type != SOCK_SEQPACKET)
> goto done;
>
> - sk->sk_max_ack_backlog = backlog;
> + /* read in softirq by afiucv_hs_backlog_add() */
> + WRITE_ONCE(sk->sk_max_ack_backlog, backlog);
> sk->sk_ack_backlog = 0;
> sk->sk_state = IUCV_LISTEN;
> err = 0;
[Severity: Medium]
Can sk->sk_state = IUCV_LISTEN be reordered ahead of
WRITE_ONCE(sk->sk_max_ack_backlog, backlog) here?
afiucv_hs_rcv() calls afiucv_hs_stray() under bh_lock_sock() before checking
sock_owned_by_user(), so it runs concurrently with iucv_sock_listen() under
lock_sock(). A plain non-volatile store to sk->sk_state has no release or
compiler barrier against the preceding WRITE_ONCE():
CPU0 (process, lock_sock) CPU1 (softirq, bh_lock_sock)
iucv_sock_listen()
sk->sk_state = IUCV_LISTEN (reordered)
afiucv_hs_rcv()
afiucv_hs_stray()
sk->sk_state == IUCV_LISTEN
afiucv_hs_backlog_add()
READ_ONCE(sk->sk_max_ack_backlog)
<-- reads 0, refuses SYNs
WRITE_ONCE(sk->sk_max_ack_backlog, backlog)
When that happens, valid SYNs beyond the first are spuriously refused while
listen() still owns the socket.
Separately, plain writes to sk->sk_state under lock_sock() (in
iucv_sock_listen(), __iucv_sock_close(), iucv_sock_cleanup_listen(), and
iucv_sock_recvmsg()) race with plain reads in afiucv_hs_stray(),
afiucv_hs_callback_win(), and afiucv_hs_callback_rx(), and
iucv_sock_recv_skb() reads sk->sk_state without READ_ONCE() inside
sk_wait_event() after release_sock() while afiucv_hs_fin() writes it in
softirq, triggering KCSAN data races.
Using smp_store_release(&sk->sk_state, IUCV_LISTEN) paired with
smp_load_acquire(&sk->sk_state) in afiucv_hs_stray(), along with
READ_ONCE()/WRITE_ONCE() on the other concurrent sk->sk_state accesses,
would fix both the ordering race and the data races.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-disp-8029c32d-v5-0-0bce531e20d0@proton.me?part=6
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 [this message]
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
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-250967@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.