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 v4 6/8] net/iucv: serialize HiperSockets receive with the socket lock
Date: Mon, 16 Nov 2026 01:29:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-215997@kernel.org> (raw)
In-Reply-To: <20261114-b4-disp-fc0634a3-v4-6-f96c506447ce@proton.me>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] net/iucv: unapplied hs_pending control frames in
iucv_sock_connect() and wait
- [Medium] net/iucv: afiucv_hs_stray() and afiucv_hs_defer() queue stray
data frames
- [Low] net/iucv: missing SOCK_ZAPPED check in afiucv_hs_stray() for
IUCV_BOUND sockets
--
commit c1273c23cdabb854289296a6ae44aec0ac20fc36
Author: Bryam Vargas <hexlabsecurity@proton.me>
net/iucv: serialize HiperSockets receive with the socket lock
This commit serializes HiperSockets receive handling with the socket lock by
taking bh_lock_sock() in afiucv_hs_rcv() and recording control frames or
queueing data and SYN frames in the socket backlog while a task owns the
socket.
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 957315bec2b45..2dd9f12bce625 100644
> --- a/net/iucv/af_iucv.c
> +++ b/net/iucv/af_iucv.c
[ ... ]
> @@ -845,6 +897,15 @@ static int iucv_sock_connect(struct socket *sock, struct sockaddr_unsized *addr,
> if (err)
> goto done;
>
> + /* The reply may be in already, recorded while we own the socket:
> + * apply it, or a non-blocking connect() misses it.
> + */
> + if (iucv->transport == AF_IUCV_TRANS_HIPER) {
> + spin_lock_bh(&sk->sk_lock.slock);
> + afiucv_hs_apply(sk, AF_IUCV_PEND_SYNREPLY);
> + spin_unlock_bh(&sk->sk_lock.slock);
> + }
> +
> if (sk->sk_state != IUCV_CONNECTED)
> err = iucv_sock_wait(sk, iucv_sock_in_state(sk, IUCV_CONNECTED,
> IUCV_DISCONN),
[Severity: Medium]
Can iucv_sock_connect() miss a SYN|ACK or SYN|FIN recorded in
iucv->hs_pending after this single afiucv_hs_apply() call?
iucv_sock_connect()
spin_lock_bh(&sk->sk_lock.slock)
afiucv_hs_apply(sk, AF_IUCV_PEND_SYNREPLY)
spin_unlock_bh(&sk->sk_lock.slock)
iucv_sock_wait()
release_sock(sk)
schedule_timeout()
lock_sock(sk)
<softirq>
afiucv_hs_rcv()
afiucv_hs_record()
iucv->hs_pending |= AF_IUCV_PEND_SYNACK
while (!(condition)) <-- sk_state is still IUCV_BOUND
ret = -EAGAIN / -ERESTARTSYS
break
release_sock(sk)
afiucv_hs_release_cb()
afiucv_hs_synack()
sk->sk_state = IUCV_CONNECTED
If a reply arrives after spin_unlock_bh() on a non-blocking connect(), or
after lock_sock(sk) reacquires ownership inside __iucv_sock_wait() (for
example, when woken by TX completion of the SYN via
afiucv_hs_callback_txnotify() -> iucv_sock_wake_msglim(), a signal, or a
timeout), iucv_sock_in_state() and the post-wait sk->sk_state check still see
IUCV_BOUND. iucv_sock_connect() then returns -EAGAIN or -ERESTARTSYS while
release_sock(sk) applies the recorded reply, leaving the socket in
IUCV_CONNECTED (or in IUCV_DISCONN without returning -ECONNREFUSED) so a
subsequent connect() retry fails with -EBADFD.
Similarly, in iucv_sock_sendmsg(), an incoming FIN recorded as
AF_IUCV_PEND_FIN while the task owns the socket is not applied before
iucv_below_msglim() or the sk->sk_state != IUCV_CONNECTED check.
[ ... ]
> @@ -2189,12 +2244,174 @@ static int afiucv_hs_callback_rx(struct sock *sk, struct sk_buff *skb)
> return NET_RX_SUCCESS;
> }
>
> +/**
> + * afiucv_hs_stray() - test for a frame that no state of the socket can use
> + * @sk: the socket the frame is for, under bh_lock_sock()
> + * @flags: the flags of the frame
> + *
> + * A stray never waits for the owner. A SYN is one outside IUCV_LISTEN and a
> + * SYN|ACK or SYN|FIN outside IUCV_BOUND, the state tests of their
> + * callbacks; a full accept queue is not tested here. A FIN is one unless
> + * the socket is connected or a recorded SYN|ACK is about to connect it.
> + * Data, SHT and WIN are strays once the peer's FIN is recorded: the socket
> + * stays IUCV_CONNECTED until the owner applies it.
> + *
> + * Context: Softirq, under bh_lock_sock().
> + * Return: true if the frame is to be freed or, for a SYN, refused.
> + */
> +static bool afiucv_hs_stray(struct sock *sk, u8 flags)
> +{
> + struct iucv_sock *iucv = iucv_sk(sk);
> +
> + switch (flags) {
> + case 0:
> + case AF_IUCV_FLAG_SHT:
> + case AF_IUCV_FLAG_WIN:
> + return iucv->hs_pending & AF_IUCV_PEND_FIN;
> + case AF_IUCV_FLAG_FIN:
> + return sk->sk_state != IUCV_CONNECTED &&
> + !(iucv->hs_pending & AF_IUCV_PEND_SYNACK);
> + case AF_IUCV_FLAG_SYN:
> + return sk->sk_state != IUCV_LISTEN;
> + case AF_IUCV_FLAG_SYN | AF_IUCV_FLAG_ACK:
> + case AF_IUCV_FLAG_SYN | AF_IUCV_FLAG_FIN:
> + return sk->sk_state != IUCV_BOUND;
> + }
> + return true;
> +}
> +
> +/**
> + * afiucv_hs_defer() - test whether a data, SHT or WIN frame has to wait
> + * @sk: the socket, owned by a task, under bh_lock_sock()
> + *
> + * These frames do not change sk_state and are handled on arrival, also
> + * while a task owns the socket. They wait in the socket backlog only if:
> + *
> + * - the reply to our SYN is recorded and not applied yet: the socket is
> + * still IUCV_BOUND, where data is freed and a WIN ignored;
> + * - frames wait already: a later one must not overtake them, and
> + * sk_backlog.len stays non-zero until __release_sock() has run them all.
> + *
> + * Context: Softirq, under bh_lock_sock().
> + * Return: true if the frame has to wait in the backlog.
> + */
> +static bool afiucv_hs_defer(struct sock *sk)
> +{
> + return (iucv_sk(sk)->hs_pending & AF_IUCV_PEND_SYNREPLY) ||
> + sk->sk_backlog.len != 0;
> +}
[Severity: Medium]
Do afiucv_hs_stray() and afiucv_hs_defer() allow data, SHT, and WIN frames
to be queued into sk->sk_backlog when the socket is neither connected nor
about to be connected by a recorded SYN|ACK?
For flags 0, AF_IUCV_FLAG_SHT, and AF_IUCV_FLAG_WIN, afiucv_hs_stray() only
checks iucv->hs_pending & AF_IUCV_PEND_FIN, and afiucv_hs_defer() tests
AF_IUCV_PEND_SYNREPLY (which includes AF_IUCV_PEND_SYNFIN) as well as
sk->sk_backlog.len != 0. If a task owns an IUCV_BOUND socket that has
recorded a SYN|FIN, or an IUCV_LISTEN socket with a SYN in sk->sk_backlog,
subsequent data, SHT, and WIN frames pass afiucv_hs_stray() and are queued
into sk->sk_backlog by afiucv_hs_backlog_add() instead of being freed in
afiucv_hs_rcv().
[ ... ]
> @@ -2311,18 +2596,25 @@ static int afiucv_hs_rcv(struct sk_buff *skb, struct net_device *dev,
> if (!iucv)
> sk = NULL;
>
> - /* no sock
> - how should we send with no sock
> - 1) send without sock no send rc checking?
> - 2) introduce default sock to handle this cases
> -
> - SYN -> send SYN|ACK in good case, send SYN|FIN in bad case
> - data -> send FIN
> - SYN|ACK, SYN|FIN, FIN -> no action? */
> + /* no socket: a SYN is refused, anything else freed */
> + if (!sk)
> + return afiucv_hs_dispatch(NULL, skb);
>
> - err = afiucv_hs_dispatch(sk, skb);
> - if (sk)
> - sock_put(sk);
> + bh_lock_sock(sk);
> + if (afiucv_hs_stray(sk, trans_hdr->flags)) {
> + if (trans_hdr->flags == AF_IUCV_FLAG_SYN)
> + afiucv_hs_callback_syn(NULL, skb);
> + else if (trans_hdr->flags == AF_IUCV_FLAG_FIN)
> + consume_skb(skb);
> + else
> + kfree_skb_reason(skb, SKB_DROP_REASON_NO_SOCKET);
> + } else if (sock_owned_by_user(sk)) {
> + err = afiucv_hs_rcv_owned(sk, skb, trans_hdr->flags);
> + } else {
> + err = afiucv_hs_dispatch(sk, skb);
> + }
> + bh_unlock_sock(sk);
> + sock_put(sk);
> return err;
> }
[Severity: Low]
Should afiucv_hs_stray() also test sock_flag(sk, SOCK_ZAPPED) for SYN|ACK and
SYN|FIN frames?
CPU0 CPU1 (<softirq>)
iucv_sock_close(sk)
lock_sock_nested(sk, ...)
afiucv_hs_rcv()
read_lock(&iucv_sk_list.lock)
sock_hold(sk)
read_unlock(&iucv_sk_list.lock)
__iucv_sock_close(sk)
iucv->hs_dev = NULL
sock_set_flag(sk, SOCK_ZAPPED)
release_sock(sk)
bh_lock_sock(sk)
afiucv_hs_stray(sk, SYN|ACK) -> false
sock_owned_by_user(sk) -> false
afiucv_hs_dispatch(sk, skb)
afiucv_hs_synack() <-- connected after close
As noted in afiucv_hs_apply(), __iucv_sock_close() leaves sk->sk_state as
IUCV_BOUND and marks the socket with SOCK_ZAPPED. If afiucv_hs_rcv() looks
up the socket just before iucv->hs_dev is cleared and acquires
bh_lock_sock(sk) after release_sock(sk), the unowned path bypasses
afiucv_hs_apply() and transitions the closed socket to IUCV_CONNECTED or
IUCV_DISCONN.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261114-b4-disp-fc0634a3-v4-0-f96c506447ce@proton.me?part=6
next prev parent reply other threads:[~2026-11-16 1:29 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 1:29 [PATCH RFC net v4 0/8] net/iucv: serialize the HiperSockets receive path with the socket lock Bryam Vargas via B4 Relay
2026-11-15 1:29 ` [PATCH RFC net v4 1/8] net/iucv: keep the window given to the peer in a field of its own Bryam Vargas via B4 Relay
2026-11-16 1:29 ` sashiko-bot
2026-11-15 1:29 ` [PATCH RFC net v4 2/8] net/iucv: do not clear SEND_SHUTDOWN to send a control frame Bryam Vargas via B4 Relay
2026-11-16 1:29 ` sashiko-bot
2026-11-15 1:29 ` [PATCH RFC net v4 3/8] net/iucv: fail sendmsg() with EPIPE once sending is shut down Bryam Vargas via B4 Relay
2026-11-16 1:29 ` sashiko-bot
2026-11-15 1:29 ` [PATCH RFC net v4 4/8] net/iucv: run recvmsg() under the socket lock Bryam Vargas via B4 Relay
2026-11-16 1:29 ` sashiko-bot
2026-11-15 1:29 ` [PATCH RFC net v4 5/8] net/iucv: factor out the HiperSockets frame dispatch and state changes Bryam Vargas via B4 Relay
2026-11-16 1:29 ` sashiko-bot
2026-11-15 1:29 ` [PATCH RFC net v4 6/8] net/iucv: serialize HiperSockets receive with the socket lock Bryam Vargas via B4 Relay
2026-11-16 1:29 ` sashiko-bot [this message]
2026-11-15 1:29 ` [PATCH RFC net v4 7/8] net/iucv: set RCV_SHUTDOWN under the socket spinlock Bryam Vargas via B4 Relay
2026-11-16 1:29 ` sashiko-bot
2026-11-15 1:29 ` [PATCH RFC net v4 8/8] net/iucv: return EOF to a reader parked when the peer closes Bryam Vargas via B4 Relay
2026-11-16 1:29 ` 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-215997@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox