[PATCH RFC net v5 10/10] net/iucv: forget a SYN that the device reports unreachable
From: Bryam Vargas via B4 Relay
Date: Thu Dec 03 2026 - 22:03:31 EST
From: Bryam Vargas <hexlabsecurity@xxxxxxxxx>
When a HiperSockets device cannot reach the target of a frame, qeth
reports TX_NOTIFY_UNREACHABLE, or its delayed form. af_iucv acts on it
only for a connected socket. For a SYN it is ignored: connect() waits
until its timeout and returns -EAGAIN. A HiperSockets socket now sends
only one SYN ("net/iucv: record that a HiperSockets socket sent its
SYN"), so a later connect() on it sends nothing and waits again, for a
reply that cannot come.
Clear syn_sent when the SYN is reported unreachable. A socket in
IUCV_BOUND has sent no other frame, so the report is about the SYN. The
next connect() sends a SYN again, and SO_MSGLIMIT can be set before it.
The connect() that sent the SYN still waits for its timeout. Any other
notification of a transmit error leaves the flag set: it does not say
whether the peer got the SYN, and a second SYN could make a second
child.
The flag is now also written outside the socket lock: read it with
READ_ONCE() where the owner reads it.
Cc: stable@xxxxxxxxxxxxxxx # 6.18.x, with the whole series
Signed-off-by: Bryam Vargas <hexlabsecurity@xxxxxxxxx>
---
v5: new. It is a patch of its own, and last, so that 1/10 stays as
small as Alexandra asked. It needs 1/10. Without 9/10 it still applies,
but then a SYN that was first reported as pending leaves a socket that
connects and cannot send.
checkpatch asks for a Fixes: tag because of the stable line. There is
none to give: what this patch repairs comes with 1/10, and on net
without 1/10 it changes nothing a caller can see.
Why: with one SYN per socket (1/10), a socket whose SYN was not answered
cannot connect again. The device reports one cause of that: qeth
maps the completion codes 4, 16, 17 and 18 to TX_NOTIFY_UNREACHABLE,
and af_iucv ignores the notification unless the socket is connected.
What I could find about callers that retry on the same socket: the
z/VSE Linux Fast Path has Linux on the listening side; iucvconn in
s390-tools calls connect() once and exits on any error; af_iucv(7)
says of -EAGAIN that "the application might try again after some
time", and a connect() that times out returns -EAGAIN. After a
SYN|FIN the socket is IUCV_DISCONN and cannot connect again on net
either.
Emulated setup. The peer's user ID is not on the LAN at first, so the
adapter reports the SYN unreachable (completion code 4). The first
connect() has a timeout of 300 ms. "Without this patch" is 1/10 to
9/10; 1/10 to 8/10 gives the same results:
- two connect() calls, the peer never there. Two SYNs leave the socket
on net and with the series, one without this patch. Both calls
return -EAGAIN on every kernel
- the peer's device comes up and the peer listens, then connect()
again on the same socket. net and the series: it returns 0, the peer
has one child, and a byte sent afterwards arrives. Without this
patch: -EAGAIN, no second SYN, no child
- the SYN reported as pending first and then unreachable (the setup
under 9/10, the peer listening): with the series the second connect()
returns 0 and the byte arrives. With the series but without 9/10 it
returns 0 and send() returns -EAGAIN
- the first connect() takes its whole timeout on every kernel, 300 to
307 ms. The notification does not wake it
- SO_MSGLIMIT lowered from 8 to 2 after the notification, then the
peer comes up as above: setsockopt() returns 0 on net and with the
series, and the second connect() gives the peer a window of 2.
Without this patch: -EINVAL
- a forged SYN|ACK and one byte of data after the notification, and no
second connect(). net, and the series without this patch: the socket
is connected and reads the byte. With the series the SYN|ACK answers
no SYN and is dropped, and the socket stays IUCV_BOUND
- TX_NOTIFY_GENERALERROR for the SYN (the adapter refuses it with
another code): the flag stays. Two connect() calls send one SYN with
the series, as without this patch; net sends two. That notification
does not say whether the peer got the frame
- two kernels with this patch changed. One also forgets on
TX_NOTIFY_OK: connect() to a listening peer times out, because the
SYN|ACK finds no SYN recorded, and two calls leave the peer with two
children. The other forgets on any transmit error: it sends a second
SYN after TX_NOTIFY_GENERALERROR
- two tests under 1/10, a second connect() before the reply and
connect() restarted by the kernel, give one SYN and one child with
this patch as without it
- a KCSAN build of the series ran the first three cases above, and the
case of 9/10 with the other error, once each: no report
I can't tell from here which of the four codes a real device gives for a
user ID that is not on the LAN, nor whether it gives one when the peer's
device is there and af_iucv is not loaded. Alexandra, Hidayath: could
one of you check a connect() to a user ID that does not exist?
Not changed: a SYN that the device delivered and nobody answered, or
one lost with no report, still leaves a socket that cannot connect.
connect() still waits for its timeout after the notification; it is
not woken.
---
net/iucv/af_iucv.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
index 1f1f6f698648..8f0bc2d806e6 100644
--- a/net/iucv/af_iucv.c
+++ b/net/iucv/af_iucv.c
@@ -93,8 +93,8 @@ static void afiucv_hs_fin(struct sock *sk)
* @mask: the AF_IUCV_PEND_* bits to apply
*
* A socket closed meanwhile takes none. The test is SOCK_ZAPPED, since
- * __iucv_sock_close() leaves IUCV_BOUND as it is. A socket whose SYN could
- * not be sent after all takes no reply to it.
+ * __iucv_sock_close() leaves IUCV_BOUND as it is. A socket that has no SYN
+ * out takes no reply to one.
*
* Context: Process context, under sk_lock.slock.
*/
@@ -106,7 +106,7 @@ static void afiucv_hs_apply(struct sock *sk, u8 mask)
iucv->hs_pending &= ~pending;
if (sock_flag(sk, SOCK_ZAPPED))
return;
- if (!iucv->syn_sent)
+ if (!READ_ONCE(iucv->syn_sent))
pending &= ~AF_IUCV_PEND_SYNREPLY;
if ((pending & AF_IUCV_PEND_SYNACK) && sk->sk_state == IUCV_BOUND)
afiucv_hs_synack(sk, iucv->hs_pending_window);
@@ -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))
@@ -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;
}
@@ -2326,7 +2326,7 @@ static int afiucv_hs_callback_rx(struct sock *sk, struct sk_buff *skb)
* as it is. A frame finds such a socket only if it was looked up before
* close() cleared hs_dev. A SYN is one outside IUCV_LISTEN; a full accept
* queue is not tested here. A SYN|ACK or SYN|FIN is one outside IUCV_BOUND
- * or for a socket that sent no SYN.
+ * or for a socket that has no SYN out.
* A FIN, data, SHT or WIN frame is one unless the socket is connected or a
* recorded SYN|ACK is about to connect it. Data, SHT and WIN are strays too
* once the peer's FIN is recorded: the socket stays IUCV_CONNECTED until
@@ -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) {
+ /* 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);
}
}
--
2.56.1