mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: vulab@iscas.ac.cn
Cc: alibuda@linux.alibaba.com, davem@davemloft.net,
	dust.li@linux.alibaba.com, edumazet@google.com,
	guwen@linux.alibaba.com, horms@kernel.org, kgraul@linux.ibm.com,
	kuba@kernel.org, linux-kernel@vger.kernel.org,
	linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org,
	mjambigi@linux.ibm.com, netdev@vger.kernel.org,
	pabeni@redhat.com, sidraya@linux.ibm.com,
	tonylu@linux.alibaba.com, wenjia@linux.ibm.com,
	stable@vger.kernel.org
Subject: Re: [PATCH] net/smc: Fix socket use-after-free in smc_shutdown()
Date: Mon, 21 Sep 2026 17:34:15 +0000	[thread overview]
Message-ID: <179001205598.2160803.12068131189751847433@kernel.org> (raw)
In-Reply-To: <20260917163956.2162779-1-vulab@iscas.ac.cn>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] net/smc/af_smc.c:smc_shutdown() — the commit claims to fix a
  use-after-free where the passive-closing sock_put() frees sk before…

--

net/smc: Fix socket use-after-free in smc_shutdown()

This moves the passive-closing sock_put() in the smc->use_fallback branch
of smc_shutdown() past release_sock(), using a new passive_close flag, on
the grounds that the put could otherwise free sk before release_sock()
runs.  It carries a Fixes: tag and Cc: stable.

> diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
> index e9f93b3ab435b..70d6da4c6267d 100644
> --- a/net/smc/af_smc.c
> +++ b/net/smc/af_smc.c
> @@ -2946,6 +2946,7 @@ int smc_shutdown(struct socket *sock, int how)
>  {
>  	struct sock *sk = sock->sk;
>  	bool do_shutdown = true;
> +	bool passive_close = false;
>  	struct smc_sock *smc;
>  	int rc = -EINVAL;
>  	int old_state;
> @@ -2983,7 +2984,7 @@ int smc_shutdown(struct socket *sock, int how)
>  		if (sk->sk_shutdown == SHUTDOWN_MASK) {
>  			sk->sk_state = SMC_CLOSED;
>  			sk->sk_socket->state = SS_UNCONNECTED;
> -			sock_put(sk);
> +			passive_close = true;
>  		}
>  		goto out;
>  	}

[Severity: High]
Can the use-after-free described in the changelog actually happen here?

smc_shutdown() is only installed as proto_ops->shutdown (af_smc.c and
smc_inet.c), so it is entered from __sys_shutdown() or
kernel_sock_shutdown() while a struct socket/file reference is alive.  The
socket's own reference on sk is dropped only in smc_release():

net/smc/af_smc.c:smc_release() {
	...
	sock_orphan(sk);
	sock->sk = NULL;
	release_sock(sk);

	sock_put(sk); /* sock_hold above */
	sock_put(sk); /* final sock_put */
}

and smc_release() cannot run while the shutdown syscall holds the fd.  With
that reference plus the passive-closing reference, wouldn't sk_refcnt be at
least 2 at the old sock_put(), making the release_sock()-on-freed-sk path
unreachable?

The commit message also states the reference may be gone because "the
passive closing reference was already consumed by an abort of the active
link group".  Can that state be reached in this branch?  This branch runs
only for smc->use_fallback sockets, and the abort paths leave sk_state at
SMC_CLOSED, SMC_PEERABORTWAIT or SMC_PROCESSABORT:

net/smc/smc_close.c:smc_close_active_abort() {
	case SMC_ACTIVE:
	case SMC_APPCLOSEWAIT1:
	case SMC_APPCLOSEWAIT2:
		sk->sk_state = SMC_PEERABORTWAIT;
		...
		sk->sk_state = SMC_CLOSED;
		sock_put(sk); /* (postponed) passive closing */
}

net/smc/smc_close.c:smc_close_passive_abort_received() {
	case SMC_INIT:
	case SMC_ACTIVE:
	case SMC_APPCLOSEWAIT1:
		sk->sk_state = SMC_PROCESSABORT;
		sock_put(sk); /* passive closing */
}

All three of those states are rejected earlier in smc_shutdown() with
-ENOTCONN:

	rc = -ENOTCONN;
	if ((sk->sk_state != SMC_ACTIVE) &&
	    (sk->sk_state != SMC_PEERCLOSEWAIT1) &&
	    (sk->sk_state != SMC_PEERCLOSEWAIT2) &&
	    (sk->sk_state != SMC_APPCLOSEWAIT1) &&
	    (sk->sk_state != SMC_APPCLOSEWAIT2) &&
	    (sk->sk_state != SMC_APPFINCLOSEWAIT))
		goto out;

so the fallback branch is never reached after such an abort.  Could a
reachable path (ideally a KASAN splat) be added to the changelog?

> @@ -3014,6 +3015,8 @@ int smc_shutdown(struct socket *sock, int how)
>  		sock->state = SS_DISCONNECTING;
>  out:
>  	release_sock(sk);
> +	if (passive_close)
> +		sock_put(sk); /* passive closing */
>  	return rc ? rc : rc1;
>  }

[Severity: High]
If the premise in the changelog did hold, does this reordering remove the
problem or just move it?

passive_close is derived solely from sk_shutdown == SHUTDOWN_MASK, which
says nothing about whether this call still owns the passive-closing
reference.  The same unconditional decrement therefore still runs, just
later.

If it drops the last reference, sk is freed while sock->sk still points at
it for an open fd, and the next fd operation touches freed memory:

net/smc/af_smc.c:smc_release() {
	struct sock *sk = sock->sk;
	...
	sock_hold(sk); /* sock_put below */

Wouldn't an ownership check (or bracketing the region with
sock_hold()/sock_put() as smc_release() does) be needed instead of a
reordering, if there really is a stray put to fix?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260917163956.2162779-1-vulab%40iscas.ac.cn

      parent reply	other threads:[~2026-09-21 17:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 16:39 Wentao Liang
2026-09-21  8:18 ` Dust Li
2026-09-21 15:04 ` krzk
2026-09-21 15:08 ` krzk
2026-09-21 15:16 ` krzk
2026-09-21 17:34 ` netdev-bot+sashiko [this message]

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=179001205598.2160803.12068131189751847433@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alibuda@linux.alibaba.com \
    --cc=davem@davemloft.net \
    --cc=dust.li@linux.alibaba.com \
    --cc=edumazet@google.com \
    --cc=guwen@linux.alibaba.com \
    --cc=horms@kernel.org \
    --cc=kgraul@linux.ibm.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjambigi@linux.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sidraya@linux.ibm.com \
    --cc=stable@vger.kernel.org \
    --cc=tonylu@linux.alibaba.com \
    --cc=vulab@iscas.ac.cn \
    --cc=wenjia@linux.ibm.com \
    /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

all inboxes | Powered by JetHome®