Re: [PATCH RFC net v4 1/8] net/iucv: keep the window given to the peer in a field of its own
From: Bryam Vargas
Date: Wed Dec 02 2026 - 22:41:46 EST
On 01.12.26 18:13, Alexandra Winter wrote:
> I reproduced both scenarios via real HiperSockets connection, and
> both issues went away with this patch:
> Without the patch the fail immediately;
> with the patch: ran 100x without the issue.
Thanks for the repro on real HiperSockets.
> Would it be more consistent to reject a set_msglimit after first SYN has
> been sent, if you introduce special handling of this case anyhow?
> (Noticing, that this first-SYN recording already provides some logic of
> a CONNECTING state, right?)
[...]
> If you just reject the set_msglimit, maybe you don't even need to record
> the msglimit, just record first_syn_sent?
> Maybe that would even be a smaller patch?
Yes to all of it, and I have it that way here now: one flag, set when
the SYN is handed to the device. Once it is set, setting SO_MSGLIMIT
fails with -EINVAL, the errno a connected socket already gives.
af_iucv(7) says the limit has to be set before connect(). The window
field and its helper are gone, and getsockopt() returns the value in
use. The patch is 28 lines added and 3 removed, against 33 and 3 in
v4.
In the emulated setup, with the SYN out and the minimum SO_RCVBUF,
net reads 2 of 8 frames when the limit is lowered from 8 to 2, and
then fails with -EFAULT and the WARN_ON() in iucv_sock_recvmsg(). When
the limit is raised from 2 to 8, the peer's writer stops after 2
frames. With the flag, both setsockopt() calls fail and all 8 frames
are read.
> Even this situation could check first_syn_sent, right?
> And ignore the SYN|ACK if !first_syn_sent.
Done, and for a SYN|FIN too. On net, a forged SYN|FIN for a socket
that only called bind() leaves it in IUCV_DISCONN, and listen() then
fails with -EINVAL. With the check, the frame is dropped and listen()
works.
> See above. Recording first_syn_sent and then refusing further
> SO_MSGLIMIT and further connects, would make this patch uneccessary and
> would not be more complex than this, would it?
"Further connects" is the part I'd like your call on before I post v5.
Not sending a second SYN is clearly right: the listener cannot tell
it from the first and makes a second child. A second connect() before
the reply comes in gives two children on net and one with the flag.
The open question is what that second connect() returns. I ran it
both ways.
Refusing it, -EALREADY once the SYN is out:
- A connect() interrupted by a signal returns -EINTR and is not
restarted, because the socket's send timeout is 40 s by default. A
caller that retries on EINTR then gets -EALREADY, and the socket
connects later, when the SYN|ACK comes in. Same for a retry after
the timeout. With SO_SNDTIMEO 0 and SA_RESTART, the kernel itself
restarts the call, and the one connect() the caller made returns
-EALREADY.
- A non-blocking caller that calls connect() again before the reply
comes in gets -EAGAIN on net. With the refusal, that becomes
-EALREADY. poll() does not help: it reports EPOLLOUT for a socket
in IUCV_BOUND.
So the caller gets an error for a connect() that then goes through,
and poll() cannot tell it when.
FWIW, POSIX agrees with the refusal (EALREADY for a later call while
the first is in progress), but it counts on poll() to say when the
connection is up.
Waiting instead: a later connect() that names the same peer sends
nothing and waits for the reply to the first SYN, as a second blocking
connect() does on TCP. A non-blocking one returns -EAGAIN, as on net.
One that names another peer fails with -EALREADY, and the first peer
still connects. That is what my draft does now, in 10 lines in
connect(). With it, a retry after EINTR or after the timeout waits
and returns 0 when the SYN|ACK comes in. So does the restarted call.
Each of those ends with one child.
Either way, with one SYN per socket the retry is lost: a socket whose
SYN got no reply cannot connect any more. By default connect() gives
up after 40 s with -EAGAIN, and on net the next call sends a new SYN.
When the first SYN is dropped in transit, the second connect()
connects on net. With my draft the second connect() times out too,
and a new socket bound to the same name connects. With the refusal it
would be -EALREADY at once; I did not run that case. IOW the caller has
to close the socket and make a new one, which is what POSIX advises
after a failed connect().
One case could keep the retry. For a SYN to a user ID that is not on
the LAN, af_iucv gets TX_NOTIFY_UNREACHABLE in the emulated setup and
ignores it. It ignores every failed-tx notification for a socket in
IUCV_BOUND. Clearing the flag there would let the next connect() send
a SYN again. That is not in the draft, and I can't tell from here
whether a real device reports the same.
So: refuse or wait? I'd take waiting, as in the draft, but it's your
call. And is the lost retry fine for the users you know of? If
something else was behind refusing further connects, I'd like to hear
it, so the patch does what you had in mind.
> This warning situation could also be prevented with a check for
> first_syn_sent?
Yes. The forged SYN|ACK is dropped, so the socket stays in IUCV_BOUND
and the byte sent after it is never read.
Thanks,
Bryam