Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bryam Vargas" <hexlabsecurity@proton.me>
Cc: linux-rdma@vger.kernel.org, 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 net v3 6/7] net/smc: update the urgent state under the socket spinlock
Date: Fri, 04 Dec 2026 09:15:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-249478@kernel.org> (raw)
In-Reply-To: <20261203-b4-disp-ba1ad55e-v3-6-6834ff90c5d0@proton.me>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] net/smc: unlocked SIOCATMARK urgent state read in smc_ioctl()
- [Low] net/smc: unmarked lockless conn->urg_state access in
  smc_rx_update_consumer()
--

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

net/smc: update the urgent state under the socket spinlock

This commit takes bh_lock_sock() around the urgent state checks and updates
in smc_rx_update_consumer() and smc_rx_recv_urg() to serialize them with
smc_cdc_msg_recv_action().

> Take the socket spinlock around both test-and-set sequences.

[Severity: Medium]
Does smc_ioctl() also need bh_lock_sock() around its SIOCATMARK read of
conn->urg_curs and conn->urg_state?

Earlier in this series, commit "net/smc: order the urgent mark across the
cursor wrap rollover" updated the SIOCATMARK path to check conn->urg_state
alongside conn->urg_curs while holding only lock_sock():

net/smc/af_smc.c:smc_ioctl() {
	...
			smc_curs_copy(&cons, &conn->local_tx_ctrl.cons, conn);
			smc_curs_copy(&urg, &conn->urg_curs, conn);
			answ = (conn->urg_state == SMC_URG_VALID ||
				conn->urg_rx_skip_pend) &&
			       smc_curs_sdiff(conn->rmb_desc->len,
					      &cons, &urg) == 1;
	...
}

Because smc_ioctl() copies conn->urg_curs before testing conn->urg_state, it
reads them in the opposite order from smc_cdc_handle_urg_data_arrival():

CPU0 (user)                       CPU1 (softirq)
smc_ioctl(SIOCATMARK)
  lock_sock(&smc->sk)
  urg = conn->urg_curs
                                  smc_cdc_msg_recv()
                                    bh_lock_sock(&smc->sk)
                                    smc_cdc_handle_urg_data_arrival()
                                      conn->urg_curs = prod
                                      conn->urg_state = SMC_URG_VALID
                                    bh_unlock_sock(&smc->sk)
  test conn->urg_state
    <-- pairs stale urg with new SMC_URG_VALID

As a result, ioctl(SIOCATMARK) can observe a torn snapshot and return a false
positive or false negative, in addition to an unmarked data race on
conn->urg_state.  Taking local_bh_disable() and bh_lock_sock(&smc->sk) around
the SIOCATMARK read would fix both.

[ ... ]

> diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c
> index 564b976426caa..2680b91e882b9 100644
> --- a/net/smc/smc_rx.c
> +++ b/net/smc/smc_rx.c
> @@ -67,26 +67,38 @@ static int smc_rx_update_consumer(struct smc_sock *smc,
>  
>  	smc_curs_add(conn->rmb_desc->len, &cons, len);
>  
> -	/* did we process urgent data? */
> +	/* did we process urgent data? smc_cdc_msg_recv_action() sets a new
> +	 * mark under the socket spinlock, even while we own the socket:
> +	 * test again under it. A mark set after the first test is left to
> +	 * the next call, like one set after the unlock.
> +	 */
>  	if (conn->urg_state == SMC_URG_VALID || conn->urg_rx_skip_pend) {
> -		diff = smc_curs_sdiff(conn->rmb_desc->len, &cons,
> -				      &conn->urg_curs);
> -		if (sock_flag(sk, SOCK_URGINLINE)) {
> -			if (diff == 0) {
> -				force = true;
> -				rc = 1;
> -				conn->urg_state = SMC_URG_READ;
> +		local_bh_disable();
> +		bh_lock_sock(sk);
> +		if (conn->urg_state == SMC_URG_VALID ||
> +		    conn->urg_rx_skip_pend) {

[Severity: Low]
Should this lockless fast-path read use READ_ONCE(conn->urg_state) paired
with WRITE_ONCE() on the writers?

smc_cdc_handle_urg_data_arrival() and smc_cdc_msg_recv_action() update
conn->urg_state under bh_lock_sock(sk) only, concurrently with this plain
unlocked load, which causes KCSAN data-race reports.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me?part=6

  reply	other threads:[~2026-12-04  9:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  9:15 [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
2026-12-03  9:15 ` [PATCH net v3 1/7] net/smc: take the socket spinlock across the failover cursor switch Bryam Vargas via B4 Relay
2026-12-03  9:15 ` [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch Bryam Vargas via B4 Relay
2026-12-04  9:15   ` sashiko-bot
2026-12-04  9:49   ` netdev-bot+sashiko
2026-12-03  9:15 ` [PATCH net v3 3/7] net/smc: store each cursor once in smc_switch_cursor() Bryam Vargas via B4 Relay
2026-12-04  9:15   ` sashiko-bot
2026-12-03  9:15 ` [PATCH net v3 4/7] net/smc: fix the failover catch-up across the cursor wrap rollover Bryam Vargas via B4 Relay
2026-12-04  9:15   ` sashiko-bot
2026-12-03  9:15 ` [PATCH net v3 5/7] net/smc: order the urgent mark " Bryam Vargas via B4 Relay
2026-12-04  9:15   ` sashiko-bot
2026-12-03  9:15 ` [PATCH net v3 6/7] net/smc: update the urgent state under the socket spinlock Bryam Vargas via B4 Relay
2026-12-04  9:15   ` sashiko-bot [this message]
2026-12-04  9:49   ` netdev-bot+sashiko
2026-12-03  9:15 ` [PATCH net v3 7/7] net/smc: skip the urgent byte when it is the next unread byte Bryam Vargas via B4 Relay
2026-12-04  9:49   ` netdev-bot+sashiko
2026-12-04  9:15 ` [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover 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-249478@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-rdma@vger.kernel.org \
    --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