All of lore.kernel.org
 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 07/10] net/iucv: set RCV_SHUTDOWN under the socket spinlock
Date: Sat, 05 Dec 2026 03:02:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-250968@kernel.org> (raw)
In-Reply-To: <20261203-b4-disp-8029c32d-v5-7-0bce531e20d0@proton.me>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net/iucv: iucv_sock_shutdown() holds sk_lock.slock across
  skb_queue_purge()
--

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

net/iucv: set RCV_SHUTDOWN under the socket spinlock

This commit updates iucv_sock_shutdown() to set sk->sk_shutdown and purge
sk->sk_receive_queue under sk->sk_lock.slock for HiperSockets sockets, and
annotates concurrent sk_shutdown accesses with WRITE_ONCE() and READ_ONCE().

> diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
> index bf97b8c62eb2e..b9eecebbdff10 100644
> --- a/net/iucv/af_iucv.c
> +++ b/net/iucv/af_iucv.c

[ ... ]

> @@ -1715,16 +1715,28 @@ static int iucv_sock_shutdown(struct socket *sock, int how)
>  			iucv_send_ctrl(sk, AF_IUCV_FLAG_SHT);
>  	}
>  
> -	sk->sk_shutdown |= how;
> -	if (how == RCV_SHUTDOWN || how == SHUTDOWN_MASK) {
> -		if ((iucv->transport == AF_IUCV_TRANS_IUCV) &&
> -		    iucv->path) {
> -			err = pr_iucv->path_quiesce(iucv->path, NULL);
> -			if (err)
> -				err = -ENOTCONN;
> -/*			skb_queue_purge(&sk->sk_receive_queue); */
> +	if (iucv->transport == AF_IUCV_TRANS_HIPER) {
> +		/* Set the bit and purge under sk_lock.slock: a frame handled
> +		 * on arrival tests RCV_SHUTDOWN under it, also while this
> +		 * task owns the socket, and one that passed the test would
> +		 * be queued after the purge. A frame that waited runs when
> +		 * the owner releases the socket, not in between.
> +		 */
> +		spin_lock_bh(&sk->sk_lock.slock);
> +		WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | how);
> +		if (how == RCV_SHUTDOWN || how == SHUTDOWN_MASK)
> +			skb_queue_purge(&sk->sk_receive_queue);
> +		spin_unlock_bh(&sk->sk_lock.slock);
> +	} else {
> +		sk->sk_shutdown |= how;
> +		if (how == RCV_SHUTDOWN || how == SHUTDOWN_MASK) {
> +			if (iucv->path) {
> +				err = pr_iucv->path_quiesce(iucv->path, NULL);
> +				if (err)
> +					err = -ENOTCONN;
> +			}
> +			skb_queue_purge(&sk->sk_receive_queue);
>  		}
> -		skb_queue_purge(&sk->sk_receive_queue);
>  	}
>  
>  	/* Wake up anyone sleeping in poll */

[Severity: Medium]
Does skb_queue_purge(&sk->sk_receive_queue) need to run under
sk->sk_lock.slock?

skb_queue_purge() frees every queued skb before returning, holding
sk->sk_lock.slock with bottom halves disabled across the whole loop.  When
shutdown(SHUT_RD) runs with queued frames, any CPU running afiucv_hs_rcv()
in softirq context for that socket spins on bh_lock_sock(sk).

afiucv_hs_rcv() holds sk->sk_lock.slock across both the RCV_SHUTDOWN check
and enqueueing in afiucv_hs_callback_rx().  Once sk->sk_shutdown is updated
and sk->sk_lock.slock is released, earlier frames are already queued, later
ones see RCV_SHUTDOWN and drop, and backlog frames wait for release_sock().

Releasing sk->sk_lock.slock right after WRITE_ONCE(sk->sk_shutdown, ...)
and purging under lock_sock(sk) avoids holding the spinlock during the
purge and removes the duplicated RCV_SHUTDOWN check and skb_queue_purge()
across the two transport branches.

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

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

Thread overview: 32+ 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
2026-12-04  3:02 ` 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
2026-12-04  3:02   ` 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
2026-12-04  3:02   ` 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
2026-12-04  3:02   ` 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
2026-12-04  3:02   ` Bryam Vargas via B4 Relay
2026-12-05  3:02   ` sashiko-bot
2026-12-04  3:02 ` [PATCH RFC net v5 05/10] net/iucv: factor out the HiperSockets frame dispatch and state changes Bryam Vargas
2026-12-04  3:02   ` 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
2026-12-04  3:02   ` 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
2026-12-04  3:02   ` Bryam Vargas via B4 Relay
2026-12-05  3:02   ` sashiko-bot [this message]
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
2026-12-04  3:02   ` 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
2026-12-04  3:02   ` 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
2026-12-04  3:02   ` 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-250968@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.