From: Jiri Pirko <jiri@resnulli.us>
To: sashiko-reviews@lists.linux.dev
Cc: Heiko Carstens <hca@linux.ibm.com>,
tj@kernel.org, mkoutny@suse.com, hannes@cmpxchg.org,
linux-s390@vger.kernel.org, Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>
Subject: Re: [PATCH rdma-next v3 02/14] RDMA/core: Handle device name conflicts when changing net namespace
Date: Fri, 17 Jul 2026 16:06:57 +0200 [thread overview]
Message-ID: <alo27vVuMMAb303f@FV6GYCPJ69> (raw)
In-Reply-To: <20260717132424.DD4661F000E9@smtp.kernel.org>
Fri, Jul 17, 2026 at 03:24:24PM +0200, sashiko-bot@kernel.org wrote:
>Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
>Pre-existing issues:
>- [High] Skipping device_rename() during namespace teardown fallback leaves the sysfs kobject tagged with a dying namespace, leading to Use-After-Free.
>--
>
>--- Patch [2]: [PATCH rdma-next v3 02/14] RDMA/core: Handle device name conflicts when changing net namespace ---
>commit 8e5328bda494a60bcfbc9c96c81fb95f503e0fdd
>Author: Jiri Pirko <jiri@resnulli.us>
>
>RDMA/core: Handle device name conflicts when changing net namespace
>
>Prepare namespace moves for per-netns names. Check user-initiated moves for
>destination-name conflicts before disabling the device, keep same-netns
>moves as no-ops, and make teardown moves detach from the exiting namespace
>even if fallback naming fails.
>
>> diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
>> index de610f52c9b23..b55fb075d0aef 100644
>> --- a/drivers/infiniband/core/device.c
>> +++ b/drivers/infiniband/core/device.c
>[ ... ]
>> @@ -1704,30 +1778,63 @@ static int rdma_dev_change_netns(struct ib_device *device, struct net *cur_net,
>> goto out;
>> }
>>
>[ ... ]
>> /*
>> - * At this point no one can be using the device, so it is safe to
>> - * change the namespace.
>> + * Recompute the destination name under the write side of devices_rwsem
>> + * now that the device is disabled, closing races with a concurrent
>> + * registration or rename, then publish the new namespace at the sysfs
>> + * level.
>> */
>> - write_pnet(&device->coredev.rdma_net, net);
>> + down_write(&devices_rwsem);
>> + ret = rdma_dev_pick_netns_name(device, net, fallback_pattern, buf,
>> + sizeof(buf), &new_name);
>> + if (ret) {
>> + if (fallback_pattern) {
>> + WARN(1,
>> + "%s: failed to pick device name during namespace teardown: %d\n",
>> + __func__, ret);
>> + write_pnet(&device->coredev.rdma_net, net);
>> + ret = 0;
>> + }
>> + goto rename_done;
>> + }
>>
>> - down_read(&devices_rwsem);
>> - /*
>> - * Currently rdma devices are system wide unique. So the device name
>> - * is guaranteed free in the new namespace. Publish the new namespace
>> - * at the sysfs level.
>> - */
>> - ret = device_rename(&device->dev, dev_name(&device->dev));
>> - up_read(&devices_rwsem);
>> + write_pnet(&device->coredev.rdma_net, net);
>> + ret = device_rename(&device->dev, new_name);
>> if (ret) {
>> - dev_warn(&device->dev,
>> - "%s: Couldn't rename device after namespace change\n",
>> - __func__);
>> - /* Try and put things back and re-enable the device */
>> - write_pnet(&device->coredev.rdma_net, cur_net);
>> + if (fallback_pattern) {
>> + WARN(1,
>> + "%s: failed to rename device during namespace teardown: %d\n",
>> + __func__, ret);
>> + ret = 0;
>> + } else {
>
>[Severity: High]
>This isn't a bug introduced by this patch, but does skipping device_rename()
>during namespace teardown fallback leave the sysfs kobject tagged with a dying
>namespace?
>
>If rdma_dev_pick_netns_name() fails and the code jumps to rename_done, or if
>device_rename() fails and the error is suppressed by setting ret = 0, the
>kernfs_node->ns tag for the device's sysfs directory would appear to remain
>pointing to the dying network namespace.
>
>Once the network namespace is freed, couldn't a subsequent sysfs traversal or
>lookup calling kernfs_ns_id(kn->ns) dereference the freed pointer and result
>in a use-after-free?
unrelated to this patch/set. Ignoring.
>
>> + dev_warn(&device->dev,
>> + "%s: Couldn't rename device after namespace change\n",
>> + __func__);
>> + /* Try and put things back and re-enable the device */
>> + write_pnet(&device->coredev.rdma_net, cur_net);
>> + }
>> + } else {
>> + strscpy(device->name, dev_name(&device->dev),
>> + IB_DEVICE_NAME_MAX);
>> }
>> +rename_done:
>> + up_write(&devices_rwsem);
>>
>> ret2 = enable_device_and_get(device);
>> if (ret2) {
>
>--
>Sashiko AI review · https://sashiko.dev/#/patchset/20260716132316.1495242-1-jiri@resnulli.us?part=2
next prev parent reply other threads:[~2026-07-17 14:07 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 [this message]
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
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=alo27vVuMMAb303f@FV6GYCPJ69 \
--to=jiri@resnulli.us \
--cc=agordeev@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hannes@cmpxchg.org \
--cc=hca@linux.ibm.com \
--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