Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jiri Pirko" <jiri@resnulli.us>
Cc: tj@kernel.org, "Alexander Gordeev" <agordeev@linux.ibm.com>,
	hannes@cmpxchg.org, mkoutny@suse.com,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	linux-s390@vger.kernel.org
Subject: Re: [PATCH rdma-next v3 06/14] net/smc: Look up the pnetid ib device within the net namespace
Date: Fri, 17 Jul 2026 13:24:27 +0000	[thread overview]
Message-ID: <20260717132427.82BA81F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260716132316.1495242-7-jiri@resnulli.us>

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

Pre-existing issues:
- [Critical] `smc_pnet_find_ib()` and `smc_pnet_find_smcd()` return unreferenced pointers leading to a Use-After-Free during concurrent device removal.
--

--- Patch [6]: [PATCH rdma-next v3 06/14] net/smc: Look up the pnetid ib device within the net namespace ---
commit 22bac16fe9606993a05fb72609386eb7b37fed92
Author: Jiri Pirko <jiri@resnulli.us>

net/smc: Look up the pnetid ib device within the net namespace

Scope smc_pnet_find_ib() to the caller's net namespace so pnetid setup
cannot bind to a same-named RDMA device from another namespace once names
become per-netns.

> diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c
> index 63e286e2dfaa8..ff9c9c35cc2f5 100644
> --- a/net/smc/smc_pnet.c
> +++ b/net/smc/smc_pnet.c

[ ... ]

> @@ -408,8 +413,8 @@ static int smc_pnet_add_eth(struct smc_pnettable *pnettable, struct net *net,
>  	return rc;
>  }
>  
> -static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
> -			   u8 ib_port, char *pnet_name)
> +static int smc_pnet_add_ib(struct smc_pnettable *pnettable, struct net *net,
> +			   char *ib_name, u8 ib_port, char *pnet_name)
>  {
>  	struct smc_pnetentry *tmp_pe, *new_pe;
>  	struct smc_ib_device *ib_dev;
> @@ -419,7 +424,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
>  	bool new_ibdev;
>  
>  	/* try to apply the pnetid to active devices */
> -	ib_dev = smc_pnet_find_ib(ib_name);
> +	ib_dev = smc_pnet_find_ib(net, ib_name);

[Severity: Critical]
This isn't a bug introduced by this patch, but does returning an unreferenced
pointer from smc_pnet_find_ib() create a use-after-free window?

Looking at smc_pnet_find_ib(), the function holds smc_ib_devices.mutex while
finding the device, but then drops the lock and returns the raw ibdev pointer:

net/smc/smc_pnet.c:smc_pnet_find_ib() {
    ...
    out:
        mutex_unlock(&smc_ib_devices.mutex);
        return ibdev;
}

If a concurrent device removal path acquires the mutex, removes the device
from the list, and frees the struct smc_ib_device via kfree(), could the
netlink thread subsequently dereference the freed pointer?

>  	if (ib_dev) {
>  		ibdev_applied = smc_pnet_apply_ib(ib_dev, ib_port, pnet_name);
>  		if (ibdev_applied)

For example, smc_pnet_apply_ib() re-acquires the mutex and writes to
ib_dev->pnetid, and the caller then reads ib_dev->ibdev->name for logging.

Does this same unreferenced pointer pattern also affect smc_pnet_find_smcd()
when it is called immediately after?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260716132316.1495242-1-jiri@resnulli.us?part=6

  reply	other threads:[~2026-07-17 13:24 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16 13:23 [PATCH rdma-next v3 00/14] RDMA: Make device names unique per net namespace Jiri Pirko
2026-07-16 13:23 ` [PATCH rdma-next v3 01/14] RDMA/core: Pass the net namespace to the device name lookups Jiri Pirko
2026-07-16 13:23 ` [PATCH rdma-next v3 02/14] RDMA/core: Handle device name conflicts when changing net namespace Jiri Pirko
2026-07-17 13:24   ` sashiko-bot
2026-07-17 14:06     ` Jiri Pirko
2026-07-16 13:23 ` [PATCH rdma-next v3 03/14] RDMA/core: Support renaming a device when changing its " Jiri Pirko
2026-07-17 13:24   ` sashiko-bot
2026-07-16 13:23 ` [PATCH rdma-next v3 04/14] RDMA/nldev: Report net namespace move errors through extack Jiri Pirko
2026-07-17 13:24   ` sashiko-bot
2026-07-16 13:23 ` [PATCH rdma-next v3 05/14] RDMA/nldev: Allow setting the device name while changing net namespace Jiri Pirko
2026-07-16 13:23 ` [PATCH rdma-next v3 06/14] net/smc: Look up the pnetid ib device within the " Jiri Pirko
2026-07-17 13:24   ` sashiko-bot [this message]
2026-07-17 14:08     ` Jiri Pirko
2026-07-16 13:23 ` [PATCH rdma-next v3 07/14] RDMA/srp: Make the SRP sysfs class net namespace aware Jiri Pirko
2026-07-16 13:23 ` [PATCH rdma-next v3 08/14] RDMA/cgroup: Disambiguate devices across net namespaces Jiri Pirko
2026-07-16 13:23 ` [PATCH rdma-next v3 09/14] RDMA/cma: Document that CM configfs cannot be net namespace scoped Jiri Pirko
2026-07-16 13:23 ` [PATCH rdma-next v3 10/14] RDMA/core: Document the SELinux ibendport net namespace limitation Jiri Pirko
2026-07-16 13:23 ` [PATCH rdma-next v3 11/14] RDMA/core: Make device names unique per net namespace Jiri Pirko
2026-07-16 13:23 ` [PATCH rdma-next v3 12/14] RDMA/rxe: Allow queue VMAs to outlive ucontexts Jiri Pirko
2026-07-16 13:23 ` [PATCH rdma-next v3 13/14] RDMA/rxe: Implement disassociate_ucontext callback Jiri Pirko
2026-07-16 13:23 ` [PATCH rdma-next v3 14/14] RDMA/selftests: Add rxe_netns_names test Jiri Pirko
2026-07-17  4:22   ` Zhu Yanjun
2026-07-17 13:24   ` sashiko-bot
2026-07-17 14:09     ` Jiri Pirko

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=20260717132427.82BA81F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hannes@cmpxchg.org \
    --cc=hca@linux.ibm.com \
    --cc=jiri@resnulli.us \
    --cc=linux-s390@vger.kernel.org \
    --cc=mkoutny@suse.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tj@kernel.org \
    /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