All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sechang Lim" <rhkrqnwk98@gmail.com>
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
	bpf@vger.kernel.org, linux-s390@vger.kernel.org,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH net v2] net/smc: fix out-of-bounds read when sk_user_data holds a sk_psock
Date: Sat, 20 Jun 2026 15:04:01 +0000	[thread overview]
Message-ID: <20260620150401.716451F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260619150342.3626224-1-rhkrqnwk98@gmail.com>

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

Pre-existing issues:
- [Critical] Overwriting `sk_user_data` during SMC fallback destroys BPF `psock` tags, leading to an infinite loop in `sock_map_close`.
--

commit cfd1a0bff0746ee614e26837804e04bb4e94ae6c
Author: Sechang Lim <rhkrqnwk98@gmail.com>

net/smc: fix out-of-bounds read when sk_user_data holds a sk_psock

This commit modifies smc_clcsock_user_data() and its RCU variant to
only return the smc_sock when the sk_user_data field carries SMC's tag
alone. This prevents SMC from interpreting a sk_psock structure placed
in sk_user_data by sockmap as an smc_sock, which was leading to
out-of-bounds reads.

> diff --git a/net/smc/smc.h b/net/smc/smc.h
> index 52145df83f6e7..88dfb459b7cc4 100644
> --- a/net/smc/smc.h
> +++ b/net/smc/smc.h
> @@ -342,13 +342,25 @@ static inline void smc_init_saved_callbacks(struct smc_sock *smc)
>  
>  static inline struct smc_sock *smc_clcsock_user_data(const struct sock *clcsk)
>  {
> -	return (struct smc_sock *)
> -	       ((uintptr_t)clcsk->sk_user_data & ~SK_USER_DATA_NOCOPY);
> +	uintptr_t data = (uintptr_t)clcsk->sk_user_data;
> +
> +	/*
> +	 * Return the smc_sock only if the slot carries SMC's tag alone.
> +	 * sockmap stores a sk_psock here tagged SK_USER_DATA_PSOCK; it is
> +	 * not an smc_sock and must not be dereferenced as one.
> +	 */
> +	if ((data & ~SK_USER_DATA_PTRMASK) != SK_USER_DATA_NOCOPY)
> +		return NULL;
> +	return (struct smc_sock *)(data & SK_USER_DATA_PTRMASK);
>  }

[Severity: Critical]
This isn't a bug introduced by this patch, but the patch fails to address
the interaction between SMC and sockmap during fallback.

When an SMC socket falls back to TCP, smc_fback_replace_callbacks()
unconditionally overwrites the inner TCP socket's sk_user_data:

net/smc/af_smc.c:smc_fback_replace_callbacks() {
    ...
    __rcu_assign_sk_user_data_with_flags(clcsk, smc, SK_USER_DATA_NOCOPY);
    ...
}

If a BPF sock_ops program had previously attached the inner TCP socket to a
sockmap, this overwrite erases the SK_USER_DATA_PSOCK tag and leaks the
psock pointer.

Later, when the inner TCP socket is closed, its sk_prot->close function
(modified by BPF to sock_map_close) is executed. Inside sock_map_close(),
sk_psock_get(sk) returns NULL because the tag is missing, and the function
evaluates saved_close = READ_ONCE(sk->sk_prot)->close:

net/core/sock_map.c:sock_map_close() {
    ...
    if (unlikely(saved_close == sock_map_close))
        goto retry;
    ...
}

Since the protocol was never restored via sk_psock_drop, saved_close
evaluates to sock_map_close.

Could this cause an infinite goto retry loop and a lockup if triggered by
userspace? Is there a way to handle the fallback case without dropping the
existing psock tag?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260619150342.3626224-1-rhkrqnwk98@gmail.com?part=1

      reply	other threads:[~2026-06-20 15:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-19 15:03 [PATCH net v2] net/smc: fix out-of-bounds read when sk_user_data holds a sk_psock Sechang Lim
2026-06-20 15:04 ` sashiko-bot [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=20260620150401.716451F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-s390@vger.kernel.org \
    --cc=rhkrqnwk98@gmail.com \
    --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.