From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796439751; b=oewIge4OfuhPVkWrbzfo3ETS+hEPWHIjoX4HqmBQKzCPSPQK6p8BEaYxyNBf95e0Mbdj edeIs4DrUOdIXGbj3UDPR5CH+R2wvgyX0G8vGdLpMANW2kqvs0eSbIDmripY5QabuBbw4 6WAmnL4b2e6xPhUjfP5vEtVyfNupx/Ow+R/O797vpKox7b67nazXDwgqKPqUIEfYHMe15 d3rL4hLKqQGx8CDZ4CqAAjyykVfKdAkEe1Ia6hbD6LOLfYMvvfiuwJQKWuEv264kUgu5z NMQ3go29wPLXxG7NHyqoQUuZiMTDUmlW2gyRrATdz+R2hwF1OC0XrQ3FKn9a87omI4g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796439751; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=NXQBHMbRRoWcE9XdK1KMwucUEN1sgdvr3hni9zZk5e8=; b=trRW7O5VWbVng8zUaMYYLC+3umA6cH2Qe6g2GJDMtk/9szKTkbsUBR+KN6nkegeeweP1 TVTgnx4yXD27xf1/HPc2YnlRA1zLuebic/VzNupWgQuxv2XYX+vU4ibDppDrMNHtNuQ3F d0GpyLG6iocDzTXmwQU4noCPl+FVdJCCHH29Q/nedJKtp/ibiAAui6R9zyvUUct28sBkM Kf25LIfLUOaacZAdpZy+kvjp5XwgthJg2at4HwCJs+9RwnbpTOp9Iq5z2Fn8V2NYUh0mt H1RmMYRS5+D8mFKXWQKOihpY4wVOjWbVt293TL6UpaLUK/V3GpC21lYcVqYdTzqfdXw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e3ALgv+j; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D229606A32D for ; Sat, 5 Dec 2026 03:02:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e3ALgv+j Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C5DB1F00A07; Sat, 5 Dec 2026 03:02:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796439751; bh=NXQBHMbRRoWcE9XdK1KMwucUEN1sgdvr3hni9zZk5e8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=e3ALgv+jEcCtTYWBLhvTYkKNMzkWKz9hG1kt++d+cWVvtEg8ai15vbiAQjTZ1oiMM ypPel7h3w45xyGt+nJlYOmzPOyH8eqkCbKilzBSRwERhrem9e6xEgmN3cN79oaZN4c tk7HoDjmhLO2VC+18uvUBHFoP+YkZZkQ5AuIigJONfReR93JzEdAB7RnqJ5OKtHDGJ Oa5rZve5CnG3T/z4vTqLzPj6z2mWV+wxPqeQpG/6aK75HBGnnl7aQ85M7zQKDkO+rl K7eGWoZbru+BVFdQK0/JoBL2gUb9vZ+Wnl3SitoLddHjVAjrW+nEykFxnE4jX0p32p PKSFJn1OZQI5Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RFC net v5 10/10] net/iucv: forget a SYN that the device reports unreachable Reply-To: sashiko-reviews@lists.linux.dev To: "Bryam Vargas" Cc: linux-s390@vger.kernel.org, "Heiko Carstens" , "Vasily Gorbik" , "Alexander Gordeev" , "Christian Borntraeger" In-Reply-To: <20261203-b4-disp-8029c32d-v5-10-0bce531e20d0@proton.me> References: <20261203-b4-disp-8029c32d-v5-0-0bce531e20d0@proton.me> <20261203-b4-disp-8029c32d-v5-10-0bce531e20d0@proton.me> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 03:02:30 +0000 X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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, str= uct sockaddr_unsized *addr, > =20 > lock_sock(sk); > =20 > - /* 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 =3D 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 |=3D 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 ma= sk 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 sendi= ng 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 =3D -EINVAL; > break; > } [Severity: Low] Does clearing syn_sent asynchronously introduce a data race on iucv->msglim= it 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_txnotif= y() 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 |=3D AF_IUCV_PEND_SYNACK afiucv_hs_callback_txnotify() WRITE_ONCE(iucv->syn_sent, false) READ_ONCE(iucv->syn_sent) iucv->msglimit =3D 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 inconsiste= nt 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 soc= k *sk, enum iucv_tx_notify n) > if (sk->sk_state =3D=3D IUCV_CONNECTED) { > sk->sk_state =3D IUCV_DISCONN; > sk->sk_state_change(sk); > + } else if ((n =3D=3D TX_NOTIFY_UNREACHABLE || > + n =3D=3D TX_NOTIFY_DELAYED_UNREACHABLE) && > + sk->sk_state =3D=3D 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 =3D=3D IUCV_CONNECTED) /* false: sees IUCV_BOUND */ afiucv_hs_synack() sk->sk_state =3D IUCV_CONNECTED; else if (... && sk->sk_state =3D=3D 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()) wou= ld 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 =3D=3D IUCV_BOUND /* true */ afiucv_hs_callback_synack() bh_lock_sock(sk) sk->sk_state =3D=3D IUCV_BOUND READ_ONCE(iucv->syn_sent) /* true */ afiucv_hs_synack() sk->sk_state =3D IUCV_CONNECTED; WRITE_ONCE(iucv->syn_sent, false) <-- connected with syn_sent =3D=3D false A remote peer on the HiperSockets LAN can thus move the socket to IUCV_CONNECTED while txnotify() only clears syn_sent instead of disconnecti= ng it. Taking bh_lock_sock(sk) in afiucv_hs_callback_txnotify() would order t= he two paths so either the forged SYN|ACK is dropped or the socket is moved to IUCV_DISCONN. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-b4-disp-80= 29c32d-v5-0-0bce531e20d0@proton.me?part=3D10