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=1796439750; b=QMAWDzbvh/5XPfEQNV9mQL8c7rJgRn+gibfg/HaW5cmhdsdnVWx2oyOb3r/Fu02grhv4 muALuxbhQnpiDCcc39T18Z+XI1Fu58hAMHnsoCprqBNLr3xhb6mXtXJG7rNVGUu4I2N0w 5rc/b/itl/H193GFDMYcXun1voeRFmccDtdzgi20IOXM+pKqFTirARSAAByvAxAaRPHzo TW/SdA90ON270a1MyEp7Lu/k8MHO9IMJ2xkaOTpjHfIAlJZdYyfX6IxyT4ROiy+Fl5d44 eM6CPQHq4CrXinGMMnxft2XlwzuomeWM0qaqN8uckTTRJlBq1q/9fvwut4ZRtPDaGCA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796439750; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=WBTZURNduWfnOPJ5rQo7H10FreGHZkS/kgCA3P2X4Ho=; b=HsKApBq9YOkIQ+vq2lDTxHRENOznhRR9iE1FJVXLBxNLorIFq0YL/nzmT20JugdcIPLs D/ixVZ44+sD5cnd2f9dSL6ZTYF9hYuNjvoTBXWgM0EOQ/CFmjDHR5F6Dj9bJsnvqgY82L OS6/TsqPbCbiemsx4Jd3TkKSRagphpQvFIr45upmRXnIbyNT4WTLFY6OF6mo7/QiZbds7 3AA6pHtzHNxH7dEquELLRGMU63H06k/QP6jpGmLBlbOce/SiyQh5b76VP1+Xo4k7lcxva OlJgGEyOOMVzxNa8EdeXkQcXyZrcRawzZrtblV1aC639S5iLO5QFKgwjLvtxZYNXH2w== 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=KftX+mvI; 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 3F0AC606A322 for ; Sat, 5 Dec 2026 03:02:30 +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=KftX+mvI Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF4941F00936; Sat, 5 Dec 2026 03:02:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796439750; bh=WBTZURNduWfnOPJ5rQo7H10FreGHZkS/kgCA3P2X4Ho=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=KftX+mvIUh6plLWH8Oehc4tTfLkYMOjfSPMYyke7ge3LYg5b/rv+MEP9S+6VHPjWx 4mJum0cM7iprXIkVqN7EFxfxYfAETM5kKa7qQgzPb7EGgUGpoFPngQ1/n5eoK1k3RK 7eGVHN27YPz/yVtHM6Jwmec9/be6M5WfTIVS4yywdWiNov0Q517BBYD7Kjc5a8F6ZF qjFyA4Rih44LlRV0ouNMK6jsNlvuwkM7e+TC8kvHn/0gGLY0pdeMim6ldl5df4WfPp Gu9xf0+uenZwqifl8BO9FolsHbqS015nJ03z2Qv0Yxq27mFP/GyKFB/yxYYL/L1jqs 6MtelDE001pvQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RFC net v5 08/10] net/iucv: return EOF to a reader parked when the peer closes 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-8-0bce531e20d0@proton.me> References: <20261203-b4-disp-8029c32d-v5-0-0bce531e20d0@proton.me> <20261203-b4-disp-8029c32d-v5-8-0bce531e20d0@proton.me> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 03:02:29 +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: spurious -ENOTCONN with unread skb in iucv_sock_recv_skb() - [Medium] net/iucv: premature EOF race with afiucv_hs_callback_rx() in wait loop - [Medium] net/iucv: inverted sk_state and sk_shutdown write order in afiucv_hs_fin() - [Low] net/iucv: unlocked plain queue and state reads in iucv_sock_recv_skb() -- commit 6854a3fcb4e6608b2df648d05777c99e3260a82a Author: Bryam Vargas net/iucv: return EOF to a reader parked when the peer closes This commit sets RCV_SHUTDOWN when applying a HiperSockets FIN so poll() reports EPOLLRDHUP, and changes iucv_sock_recv_skb() to return EOF instead of -ENOTCONN when the socket is IUCV_DISCONN with empty queues. Link: https://lore.kernel.org/netdev/51a4a40a-f34b-4d41-b049-69aa53f4dcf5@l= inux.ibm.com/ > diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c > index b9eecebbdff10..8336f7056d49c 100644 > --- a/net/iucv/af_iucv.c > +++ b/net/iucv/af_iucv.c > @@ -75,6 +75,8 @@ static void afiucv_hs_synfin(struct sock *sk) > static void afiucv_hs_fin(struct sock *sk) > { > sk->sk_state =3D IUCV_DISCONN; > + /* as a TCP FIN: EOF for a reader, EPOLLRDHUP for poll() */ > + WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN); > sk->sk_state_change(sk); > } [Severity: Medium] Can writing sk->sk_state before RCV_SHUTDOWN cause a concurrent poll() to miss EPOLLRDHUP, EPOLLRDNORM, and EPOLLHUP on a peer FIN? iucv_sock_poll() runs without locks and reads sk->sk_shutdown before testing sk->sk_state =3D=3D IUCV_DISCONN: CPU0 CPU1 iucv_sock_poll() reads sk->sk_shutdown (0) afiucv_hs_fin() sk->sk_state =3D IUCV_DISCONN sk->sk_state =3D=3D IUCV_DISCONN returns EPOLLIN only <-- misses EPOLLRDHUP/EPOLLRDNORM sk->sk_shutdown |=3D RCV_SHUTDOWN sk->sk_state_change(sk) If SEND_SHUTDOWN was already set, poll() misses EPOLLHUP as well. Setting RCV_SHUTDOWN before sk->sk_state =3D IUCV_DISCONN with release/ acquire (or smp_wmb()/smp_rmb()) ordering, as tcp_fin() and tcp_poll() do, would prevent poll() from observing IUCV_DISCONN before RCV_SHUTDOWN. [ ... ] > @@ -1459,7 +1462,16 @@ static struct sk_buff *iucv_sock_recv_skb(struct s= ock *sk, int flags, int *err) > if (!timeo) > break; > if (sk->sk_state !=3D IUCV_CONNECTED) { > - *err =3D -ENOTCONN; > + /* disconnected and nothing left to read: EOF, as at > + * the top of iucv_sock_recvmsg() > + */ > + if (sk->sk_state =3D=3D IUCV_DISCONN && > + skb_queue_empty(&iucv_sk(sk)->backlog_skb_q) && > + skb_queue_empty(&sk->sk_receive_queue) && > + list_empty(&iucv_sk(sk)->message_q.list)) > + *err =3D 0; > + else > + *err =3D -ENOTCONN; > break; > } > if (signal_pending(current)) { [Severity: Medium] Should this branch retry dequeuing instead of returning -ENOTCONN when sk->sk_receive_queue is no longer empty? Even with lock_sock(sk) held, afiucv_hs_callback_rx() can queue a frame onto sk->sk_receive_queue and afiucv_netdev_event() can set sk->sk_state =3D IUCV_DISCONN without RCV_SHUTDOWN between skb_recv_datagram() and the sk_state check. This code then sees sk_receive_queue is non-empty and falls into the else branch, returning -ENOTCONN while an unread skb is sitting on the queue; callers that treat -ENOTCONN as fatal will close the socket and drop that message. Checking !skb_queue_empty_lockless(queue) and continuing the loop, as __skb_wait_for_more_packets() does in net/core/datagram.c, would deliver the queued skb before checking sk_state. [Severity: Medium] Can this check return a premature EOF while afiucv_hs_callback_rx() is still enqueuing an already-accepted frame? CPU0 CPU1 CPU2 iucv_sock_recv_skb() afiucv_hs_callback_rx() sk_state =3D=3D CONNECTED skb_pull()/sk_filter() afiucv_netdev_event() sk_state =3D IUCV_DISCONN sk_state =3D=3D IUCV_DISCONN all queues empty *err =3D 0 <-- EOF __sock_queue_rcv_skb() afiucv_netdev_event() sets sk->sk_state =3D IUCV_DISCONN without taking lock_sock(sk), bh_lock_sock(sk), or iucv->message_q.lock. Because iucv_sock_recv_skb() holds only lock_sock(sk), it can observe IUCV_DISCONN and empty queues before afiucv_hs_callback_rx() queues the frame onto sk->sk_receive_queue, silently losing the message when userspace closes on EOF. [Severity: Low] Should these checks use READ_ONCE(sk->sk_state) and skb_queue_empty_lockless()? iucv_sock_recv_skb() holds only lock_sock(sk), while afiucv_hs_callback_rx() and iucv_callback_rx() concurrently modify backlog_skb_q and sk_receive_queue without it, and afiucv_netdev_event() updates sk->sk_state without it as well. skb_queue_empty() does a plain load of list->next (unlike skb_queue_empty_lockless() later in this function and list_empty() below it), and sk->sk_state is read twice without READ_ONCE(). These unlocked plain loads are data races that will trigger KCSAN reports and allow the compiler to reload sk->sk_state between the two checks. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-b4-disp-80= 29c32d-v5-0-0bce531e20d0@proton.me?part=3D8