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 10/10] net/iucv: forget a SYN that the device reports unreachable
Date: Sat, 05 Dec 2026 03:02:30 +0000 [thread overview]
Message-ID: <sashiko-outbox-250971@kernel.org> (raw)
In-Reply-To: <20261203-b4-disp-8029c32d-v5-10-0bce531e20d0@proton.me>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] net/iucv: unlocked plain and double read of sk_state in
txnotify()
- [Medium] net/iucv: race between txnotify() and synack() accepts forged
SYN|ACK
- [Medium] net/iucv: ABA race on syn_sent in
afiucv_hs_callback_txnotify()
- [Low] net/iucv: data race on iucv->msglimit in setsockopt() and
backlog_add()
--
commit 277ffdd9e148eca08eaf4bce27f87df25388d013
Author: Bryam Vargas <hexlabsecurity@proton.me>
net/iucv: forget a SYN that the device reports unreachable
This commit clears iucv->syn_sent in afiucv_hs_callback_txnotify() when a
HiperSockets SYN on an IUCV_BOUND socket is reported unreachable, so a later
connect() can send another SYN and SO_MSGLIMIT can be updated beforehand. It
also converts the socket-owner reads of iucv->syn_sent to READ_ONCE().
> diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
> index 1f1f6f6986484..8f0bc2d806e60 100644
> --- a/net/iucv/af_iucv.c
> +++ b/net/iucv/af_iucv.c
[ ... ]
> @@ -930,8 +930,8 @@ static int iucv_sock_connect(struct socket *sock, struct sockaddr_unsized *addr,
>
> lock_sock(sk);
>
> - /* A HiperSockets socket sends one SYN: wait for the reply to it */
> - if (iucv->syn_sent) {
> + /* The SYN is out: wait for the reply to it */
> + if (READ_ONCE(iucv->syn_sent)) {
> err = 0;
> if (memcmp(iucv->dst_user_id, sa->siucv_user_id, 8) ||
> memcmp(iucv->dst_name, sa->siucv_name, 8))
[Severity: Medium]
Can an ABA transition on iucv->syn_sent cause a retry of connect() to apply a
stale SYN reply and backlogged data from the first SYN to a new SYN?
After an earlier connect() to peer A returns -EAGAIN with SYN #1 still in
flight, a second connect() to peer B acquires lock_sock(sk), which leaves
softirqs enabled before checking iucv->syn_sent:
CPU0 (connect) CPU1 (softirq)
lock_sock(sk)
afiucv_hs_rcv() [SYN|ACK from peer A]
bh_lock_sock(sk)
afiucv_hs_record()
hs_pending |= AF_IUCV_PEND_SYNACK
afiucv_hs_rcv() [DATA from peer A]
afiucv_hs_backlog_add()
afiucv_hs_callback_txnotify() [SYN #1]
WRITE_ONCE(iucv->syn_sent, false)
if (READ_ONCE(iucv->syn_sent))
/* false */
/* overwrite dst_* with peer B */
iucv_send_ctrl(AF_IUCV_FLAG_SYN)
WRITE_ONCE(iucv->syn_sent, true)
iucv_sock_connect_done()
afiucv_hs_apply() <-- applies peer A's SYN|ACK to SYN #2
release_sock(sk)
afiucv_hs_backlog_rcv() <-- queues peer A's DATA on receive_queue
Because syn_sent goes true -> false -> true within the same lock_sock(sk)
critical section, afiucv_hs_apply() sees syn_sent set again and does not mask
off AF_IUCV_PEND_SYNREPLY. The socket transitions to IUCV_CONNECTED with
peer A's window and data while SYN #2 is in flight to peer B, where it can
create an orphaned child; a stale SYN|FIN fails the new connect() with
-ECONNREFUSED instead.
Clearing hs_pending and purging sk_backlog under sk_lock.slock before sending
SYN #2 would prevent stale replies and backlogged frames from carrying over.
[ ... ]
> @@ -1806,7 +1806,7 @@ static int iucv_sock_setsockopt(struct socket *sock, int level, int optname,
> switch (sk->sk_state) {
> case IUCV_BOUND:
> /* the SYN gave the peer msglimit as its window */
> - if (iucv->syn_sent) {
> + if (READ_ONCE(iucv->syn_sent)) {
> rc = -EINVAL;
> break;
> }
[Severity: Low]
Does clearing syn_sent asynchronously introduce a data race on iucv->msglimit
between iucv_sock_setsockopt() and afiucv_hs_backlog_add()?
Because lock_sock(sk) and bh_lock_sock(sk) do not exclude each other, a
forged SYN|ACK can set AF_IUCV_PEND_SYNACK in iucv->hs_pending while
setsockopt(SO_MSGLIMIT) holds lock_sock(sk). If afiucv_hs_callback_txnotify()
then clears syn_sent without clearing hs_pending, setsockopt() writes
iucv->msglimit while softirq still backlogs arriving DATA frames and reads it:
CPU0 (setsockopt) CPU1 (softirq)
lock_sock(sk)
afiucv_hs_rcv() [SYN|ACK]
bh_lock_sock(sk)
hs_pending |= AF_IUCV_PEND_SYNACK
afiucv_hs_callback_txnotify()
WRITE_ONCE(iucv->syn_sent, false)
READ_ONCE(iucv->syn_sent)
iucv->msglimit = val; afiucv_hs_rcv() [DATA]
bh_lock_sock(sk)
afiucv_hs_backlog_add()
iucv->msglimit + 1 <-- data race
This causes a KCSAN data race on iucv->msglimit and can apply an inconsistent
backlog limit to incoming frames. Using WRITE_ONCE()/READ_ONCE() or
synchronizing the update under sk_lock.slock would avoid the race.
[ ... ]
> @@ -2735,6 +2735,14 @@ static void afiucv_hs_callback_txnotify(struct sock *sk, enum iucv_tx_notify n)
> if (sk->sk_state == IUCV_CONNECTED) {
> sk->sk_state = IUCV_DISCONN;
> sk->sk_state_change(sk);
> + } else if ((n == TX_NOTIFY_UNREACHABLE ||
> + n == TX_NOTIFY_DELAYED_UNREACHABLE) &&
> + sk->sk_state == IUCV_BOUND) {
[Severity: Medium]
Does this second unlocked read of sk->sk_state create both a data race and a
double-read hazard?
afiucv_hs_callback_txnotify() runs from qeth_notify_skbs() without holding
lock_sock(sk) or sk_lock.slock, while afiucv_hs_synack(), afiucv_hs_synfin(),
and iucv_sock_listen() write sk->sk_state under those locks. Reading
sk->sk_state twice without synchronization also allows a state transition
between the two checks to bypass both branches:
CPU0 (txnotify) CPU1 (softirq)
if (sk->sk_state == IUCV_CONNECTED)
/* false: sees IUCV_BOUND */
afiucv_hs_synack()
sk->sk_state = IUCV_CONNECTED;
else if (... &&
sk->sk_state == IUCV_BOUND)
/* false: sees IUCV_CONNECTED */ <-- both branches skipped
In that case the socket is neither disconnected nor has syn_sent cleared,
leaving it in an inconsistent state. Serializing the state check and update
under sk_lock.slock (or at least caching sk->sk_state with READ_ONCE()) would
prevent skipping both branches.
> + /* An IUCV_BOUND socket has sent nothing but its SYN.
> + * Forget a SYN that is reported unreachable: the next
> + * connect() sends another.
> + */
> + WRITE_ONCE(iucv->syn_sent, false);
> }
[Severity: Medium]
Can a concurrent forged SYN|ACK still connect the socket while
afiucv_hs_callback_txnotify() is clearing syn_sent?
afiucv_hs_callback_txnotify() does not take sk_lock.slock, so it is not
serialized with afiucv_hs_callback_synack() (under bh_lock_sock(sk)) or
afiucv_hs_apply() (under sk_lock.slock):
CPU0 (txnotify) CPU1 (softirq)
sk->sk_state == IUCV_BOUND
/* true */
afiucv_hs_callback_synack()
bh_lock_sock(sk)
sk->sk_state == IUCV_BOUND
READ_ONCE(iucv->syn_sent) /* true */
afiucv_hs_synack()
sk->sk_state = IUCV_CONNECTED;
WRITE_ONCE(iucv->syn_sent, false) <-- connected with syn_sent == false
A remote peer on the HiperSockets LAN can thus move the socket to
IUCV_CONNECTED while txnotify() only clears syn_sent instead of disconnecting
it. Taking bh_lock_sock(sk) in afiucv_hs_callback_txnotify() would order the
two paths so either the forged SYN|ACK is dropped or the socket is moved to
IUCV_DISCONN.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-disp-8029c32d-v5-0-0bce531e20d0@proton.me?part=10
next prev parent reply other threads:[~2026-12-05 3:02 UTC|newest]
Thread overview: 21+ 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 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 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 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 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 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 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 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 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 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 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 via B4 Relay
2026-12-05 3:02 ` sashiko-bot [this message]
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-250971@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