On 15.11.26 02:29, Bryam Vargas via B4 Relay wrote:
> From: Bryam Vargas <hexl…@proton.me> > > A HiperSockets SYN carries msglimit as the receive window, and > SO_MSGLIMIT is accepted while the socket is IUCV_BOUND, which it is > until the SYN|ACK arrives. A msglimit changed in between leaves the peer > with the window the SYN carried, while recvmsg() counts the frames it > reads against the new value: > > - Lowered, a peer that keeps to its window has the socket closed on it > once the receive buffer is full and frames wait in backlog_skb_q, > where no window update resets the count: WARN_ON(), -EFAULT, the rest > of the stream lost. > - Raised far enough, the threshold of the window update lies above the > window: the count never reaches it, the peer uses up its window and > its writer waits for an update that only a data frame from us would > carry. >
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. My understanding: `As AF_IUCV_TRANS_HIPER currently has no SS_CONNECTING state, a second connect can send another SYN before SYN|ACK is received and the socket state becomes IUCV_CONNECTED.`
> Record the window when the first SYN of a socket leaves, and in a > listener's SYN|ACK, and let recvmsg() count frames against it and take > the window-update threshold from it. A SYN that is not sent records > nothing, and a later SYN of the socket carries the recorded window. A> msglimit set after the first SYN no longer changes anything for that > socket; getsockopt() still returns it.
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?) Sounds suboptimal that getsockopt returns the value that is not used anywhere. 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? My understanding: 'As AF_IUCV_TRANS_HIPER currently does not check whether connect() has been called, a socket in IUCV_BOUND state can be connected by an unsolicited SYN|ACK, if the *name and *user_id fields match.' A socket connected by a SYN|ACK
> without having sent a SYN keeps msglimit as its window.
Even this situation could check first_syn_sent, right? And ignore the SYN|ACK if !first_syn_sent.
> > Fixes: 3881ac441f64 ("af_iucv: add HiperSockets transport") > Fixes: 800c5eb7b5eb ("af_iucv: change net_device handling for HS transport") > Cc: stab…@vger.kernel.org # 6.18.x > Signed-off-by: Bryam Vargas <hexl…@proton.me> > --- > v4 (AI review of v3, [3] in the cover letter): > - a later SYN of the socket carries the window the first one gave and > records nothing. v3 wrote the field for every SYN, so a second > connect() in IUCV_BOUND after a SO_MSGLIMIT change left the peer of > the first SYN with a window the socket no longer counted against > - the window is recorded when the first SYN is handed to the device, > after the device and MTU tests, and forgotten if that transmit fails. > v3 recorded it while building the header: a connect() that failed > with -ENETDOWN left a window nobody had received > - not changed: connect() still tests sk_state before lock_sock(), the > last case of that review. A SYN sent that way does not move the > window: it is recorded by then, or the socket was connected by a > SYN|ACK it never asked for and the SYN records the msglimit the > socket already counts against > v3: https://lore.kernel.org/netdev/2026…@proton.me/ > > It goes first because the backlog of 6/8 counts against this window: on > the live msglimit it would drop data without a trace, as in Hidayath's > SO_MSGLIMIT scenario on v1. > > Both cases in the message repro in the emulated setup, with the SYN|ACK > held back in the adapter while the limit changes: > > - SO_MSGLIMIT 8 when the SYN goes out, lowered to 2, minimum SO_RCVBUF, > the peer sends its 8 frames. net reads 2, then takes the WARN_ON() in > iucv_sock_recvmsg() and returns -EFAULT; with this patch all 8 arrive. > With the default SO_RCVBUF net delivers the 8 as well: a window update > goes out after each read and resets the count. > - SO_MSGLIMIT 2 when the SYN goes out, raised to 8. The peer sends 2 and > the socket reads both. On net no window update leaves and the peer's > next send returns -EAGAIN; with this patch the update leaves and the > send goes through. With the limit left at 2 both kernels send the > update. > > The v4 items, same setup: > > - The lowered case with a second connect() after the limit changed, so > that a second SYN leaves with the SYN|ACK of the first still held. The > child the first SYN made sends its 8 frames: net reads 2, WARN_ON() > and -EFAULT; this patch reads all 8. With the field written by every > SYN again the socket reads 2 and takes the -EFAULT whichever child > sends. net and this patch read all 8 from the child the second SYN > made; with the second SYN carrying the live msglimit that child stops > after 2 frames, as the socket counts against 8 and owes it no update. > - connect() with the interface down and SO_MSGLIMIT 1: -ENETDOWN, no SYN > leaves. Interface up, the limit raised to 8, then a forged SYN|ACK and > three frames. net and this patch read all three; with the window > recorded ahead of the device test, as in v3, the socket reads one and > the next read takes the WARN_ON() and returns -EFAULT. > - For a transmit that fails after the record I have no qdisc that drops > on demand, so a test kernel drops the SYN to a destination name that > begins with DSY: it frees the skb where dev_queue_xmit() would be > called and hands back NET_XMIT_DROP. The sequence above with that > SYN: the three frames are read; with the record left in place the > second read fails as above. > > Not changed, and for the maintainers to call: once a first SYN has > left, SO_MSGLIMIT is still accepted while the socket is IUCV_BOUND and > no longer moves the window, even when the next connect() names another > peer. The window given and the window counted agree, which is all this > patch is after. Refusing SO_MSGLIMIT once a SYN has left, or forgetting > the window when the destination changes, would each be a change of its > own.
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?
> > The last sentence of the message is the third item of the AI review of > v2. net connects an IUCV_BOUND socket on any SYN|ACK, whether or not it > sent a SYN. The series leaves that as it is. With a forged SYN|ACK and > one byte for a socket that never called connect(), net and this patch > return the byte; with the window left at 0, as in v2, the read takes > the WARN_ON() and returns -EFAULT. >
Understood. AF_IUCV_TRANS_HIPER doesn't authenticate the sender (except that it has to have access to this HS segment), so with a forged packet all kind of things can be done. This warning situation could also be prevented with a check for first_syn_sent?
> With afiucv_hs_window() back on the live msglimit, the lowered case > loses data in the backlog of 6/8 and the raised one stalls as on net. > None of this shows in the 53 default tests: with this patch the same > eight fail as on net, with the same result. > ---