Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bryam Vargas" <hexlabsecurity@proton.me>
Cc: linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH RFC net v5 04/10] net/iucv: run recvmsg() under the socket lock
Date: Sat, 05 Dec 2026 03:02:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-250965@kernel.org> (raw)
In-Reply-To: <20261203-b4-disp-8029c32d-v5-4-0bce531e20d0@proton.me>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] net/iucv: busy-spin in iucv_sock_recv_skb() on peeked
  zero-length skb
- [Medium] net/iucv: iucv_sock_recv_skb() wakes on EPOLLOUT due to
  unfiltered wait
- [Low] net/iucv: unmarked lockless read of sk->sk_state in
  iucv_sock_recv_skb()
--

commit 274b7c63e2b5c54126741c2a48f6cd8e150d1e73
Author: Bryam Vargas <hexlabsecurity@proton.me>

net/iucv: run recvmsg() under the socket lock

This commit acquires lock_sock() in iucv_sock_recvmsg() and replaces its
blocking skb_recv_datagram() call with a new iucv_sock_recv_skb() helper
that sleeps in sk_wait_event() with the socket lock released.  It also
releases the socket lock in iucv_sock_sendmsg() while waiting for send
memory.

Link: https://lore.kernel.org/all/20260724222917.134769-1-hexlabsecurity@proton.me/

> diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
> index c955ecd0c5228..9c4bac738e67c 100644
> --- a/net/iucv/af_iucv.c
> +++ b/net/iucv/af_iucv.c

[ ... ]

> @@ -1266,6 +1276,54 @@ static void iucv_process_message_q(struct sock *sk)
>  	}
>  }

[ ... ]

> +static struct sk_buff *iucv_sock_recv_skb(struct sock *sk, int flags, int *err)
> +{
> +	long timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
> +	struct sk_buff_head *queue = &sk->sk_receive_queue;
> +	DEFINE_WAIT_FUNC(wait, woken_wake_function);

[Severity: Medium]
Does woken_wake_function() here cause spurious reader wakeups and
lock_sock() contention on full-duplex sockets?

Previously, skb_recv_datagram() waited with receiver_wake_function(), which
filtered out wakeups without EPOLLIN | EPOLLERR.  woken_wake_function()
ignores the poll key, while sock_def_write_space() sends EPOLLOUT on every
freed transmit skb whenever sk_wmem_alloc < sk_sndbuf / 2.

On classic z/VM IUCV with SO_IPRMDATA_MSG and skb->len <= 7,
iucv_sock_sendmsg() calls consume_skb() synchronously while holding
lock_sock().  That wakes sleeping readers on every send, forcing them to
contend on lock_sock(), check an empty receive queue, and sleep again.

Wrapping woken_wake_function() with a poll-key check for EPOLLIN | EPOLLERR,
like receiver_wake_function(), would avoid this regression.

> +	struct sk_buff *skb;
> +
> +	for (;;) {
> +		skb = skb_recv_datagram(sk, flags | MSG_DONTWAIT, err);
> +		if (skb || *err != -EAGAIN)
> +			break;
> +		if (sk->sk_shutdown & RCV_SHUTDOWN)
> +			break;
> +		if (!timeo)
> +			break;
> +		if (sk->sk_state != IUCV_CONNECTED) {
> +			*err = -ENOTCONN;
> +			break;
> +		}
> +		if (signal_pending(current)) {
> +			*err = sock_intr_errno(timeo);
> +			break;
> +		}
> +		add_wait_queue(sk_sleep(sk), &wait);
> +		sk_wait_event(sk, &timeo,
> +			      !skb_queue_empty_lockless(queue) ||

[Severity: Medium]
Can !skb_queue_empty_lockless(queue) cause a blocking MSG_PEEK read to
busy-spin forever if a zero-length shutdown skb is left on the queue?

On classic z/VM IUCV, peer shutdown(SHUT_RDWR) queues a zero-length skb and
runs iucv_callback_shutdown() in tasklet context.  iucv_sock_recvmsg()
updates sk_shutdown under lock_sock() only, while iucv_callback_shutdown()
uses bh_lock_sock() without checking sock_owned_by_user():

CPU0                              CPU1 (tasklet)
iucv_sock_recvmsg(MSG_PEEK)
  lock_sock(sk)
  __skb_try_recv_from_queue()
    skb->peeked = 1
                                  iucv_callback_shutdown()
                                    bh_lock_sock(sk)
                                    load sk_shutdown (0)
  sk_shutdown |= RCV_SHUTDOWN
                                    sk_shutdown = SEND_SHUTDOWN
                                    bh_unlock_sock(sk)
  release_sock(sk)

iucv_sock_recvmsg(MSG_PEEK)
  __skb_try_recv_from_queue()
    skips peeked 0-len skb -> -EAGAIN
  sk_wait_event(..., !skb_queue_empty_lockless(queue) || ...)
    condition true, skips wait_woken()  <-- spins forever

Because the peeked zero-length skb stays queued and RCV_SHUTDOWN was lost,
sk_wait_event() never sleeps or decrements timeo.  The caller spins at 100%
CPU, ignoring SO_RCVTIMEO and risking a soft lockup on non-preemptible
kernels, until a signal, disconnect, or new packet arrives.

Pre-patch skb_recv_datagram() avoided this regression by checking
READ_ONCE(queue->prev) != last.  Using __skb_try_recv_datagram() to check
READ_ONCE(queue->prev) != last here, and serializing sk_shutdown updates
with sk->sk_lock.slock, would fix both parts.

> +			      READ_ONCE(sk->sk_err) ||
> +			      (READ_ONCE(sk->sk_shutdown) & RCV_SHUTDOWN) ||
> +			      sk->sk_state != IUCV_CONNECTED, &wait);

[Severity: Low]
Should sk->sk_state use READ_ONCE() here?

sk_wait_event() releases the socket lock before evaluating the condition, so
sk->sk_state is read locklessly while __iucv_sock_close() or softirq
callbacks can update it, causing a KCSAN data race.  READ_ONCE(sk->sk_state)
would match the sibling sk_err and sk_shutdown checks.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-disp-8029c32d-v5-0-0bce531e20d0@proton.me?part=4

  reply	other threads:[~2026-12-05  3:02 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  3:02 [PATCH RFC net v5 00/10] net/iucv: serialize the HiperSockets receive path with the socket lock Bryam Vargas via B4 Relay
2026-12-04  3:02 ` [PATCH RFC net v5 01/10] net/iucv: record that a HiperSockets socket sent its SYN Bryam Vargas via B4 Relay
2026-12-04 18:58   ` Alexandra Winter
2026-12-04  3:02 ` [PATCH RFC net v5 02/10] net/iucv: do not clear SEND_SHUTDOWN to send a control frame Bryam Vargas via B4 Relay
2026-12-04  3:02 ` [PATCH RFC net v5 03/10] net/iucv: fail sendmsg() with EPIPE once sending is shut down Bryam Vargas via B4 Relay
2026-12-05  3:02   ` sashiko-bot
2026-12-04  3:02 ` [PATCH RFC net v5 04/10] net/iucv: run recvmsg() under the socket lock Bryam Vargas via B4 Relay
2026-12-05  3:02   ` sashiko-bot [this message]
2026-12-04  3:02 ` [PATCH RFC net v5 05/10] net/iucv: factor out the HiperSockets frame dispatch and state changes Bryam Vargas via B4 Relay
2026-12-04  3:02 ` [PATCH RFC net v5 06/10] net/iucv: serialize HiperSockets receive with the socket lock Bryam Vargas via B4 Relay
2026-12-05  3:02   ` sashiko-bot
2026-12-04  3:02 ` [PATCH RFC net v5 07/10] net/iucv: set RCV_SHUTDOWN under the socket spinlock Bryam Vargas via B4 Relay
2026-12-05  3:02   ` sashiko-bot
2026-12-04  3:02 ` [PATCH RFC net v5 08/10] net/iucv: return EOF to a reader parked when the peer closes Bryam Vargas via B4 Relay
2026-12-05  3:02   ` sashiko-bot
2026-12-04  3:02 ` [PATCH RFC net v5 09/10] net/iucv: decrement pendings when a pending frame's transmit fails Bryam Vargas via B4 Relay
2026-12-05  3:02   ` sashiko-bot
2026-12-04  3:02 ` [PATCH RFC net v5 10/10] net/iucv: forget a SYN that the device reports unreachable Bryam Vargas via B4 Relay
2026-12-05  3:02   ` sashiko-bot
2026-12-04 11:05 ` [PATCH RFC net v5 00/10] net/iucv: serialize the HiperSockets receive path with the socket lock Hidayath Khan
2026-12-05  3:02 ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-250965@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=hexlabsecurity@proton.me \
    --cc=linux-s390@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox