From: sashiko-bot@kernel.org
To: "Guangshuo Li" <liguangshuo@mail.sdu.edu.cn>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH] RDMA/rtrs-srv: Fix potential session use-after-free on sysfs failure
Date: Thu, 03 Dec 2026 12:14:24 +0000 [thread overview]
Message-ID: <sashiko-outbox-247704@kernel.org> (raw)
In-Reply-To: <20261203115553.2318954-1-liguangshuo@mail.sdu.edu.cn>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] RDMA/rtrs-srv: dec_ref rollback allows re-adding deleted
srv->dev
--
commit be8058b540e2d69d724eccc0f72faf8f78caad2c
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
RDMA/rtrs-srv: Fix potential session use-after-free on sysfs failure
This commit moves the per-path get_device(&srv->dev) into
rtrs_srv_create_once_sysfs_root_folders(), removes put_device() from its
error paths while decrementing srv->dev_ref on failure, and unlocks
srv->paths_mutex before put_device() on teardown.
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c b/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c
> index 9dd9141c86a54..938082369b158 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c
[ ... ]
> @@ -177,19 +177,22 @@ static int rtrs_srv_create_once_sysfs_root_folders(struct rtrs_srv_path *srv_pat
> err = device_add(&srv->dev);
> if (err) {
> pr_err("device_add(): %pe\n", ERR_PTR(err));
> - put_device(&srv->dev);
> - goto unlock;
> + goto dec_ref;
> }
> srv->kobj_paths = kobject_create_and_add("paths", &srv->dev.kobj);
> if (!srv->kobj_paths) {
> err = -ENOMEM;
> pr_err("kobject_create_and_add(): %pe\n", ERR_PTR(err));
> device_del(&srv->dev);
> - put_device(&srv->dev);
> - goto unlock;
> + goto dec_ref;
> }
> dev_set_uevent_suppress(&srv->dev, false);
> kobject_uevent(&srv->dev.kobj, KOBJ_ADD);
> +get_ref:
> + get_device(&srv->dev);
> + goto unlock;
> +dec_ref:
> + srv->dev_ref--;
> unlock:
> mutex_unlock(&srv->paths_mutex);
[Severity: Medium]
Can rolling back srv->dev_ref here cause device_add() to be called more
than once on the same srv->dev?
When kobject_create_and_add() fails, device_del(&srv->dev) runs and
dec_ref resets srv->dev_ref to 0. Because srv is shared across all
paths of a multi-path session, another path entering this function will
see srv->dev_ref == 0 and call device_add(&srv->dev) a second time.
The driver core forbids calling device_add() more than once on a struct
device: device_del() leaves dev->p allocated with dev->p->dead set and
unlinks dev->p->knode_class asynchronously, so re-adding srv->dev leaves
it in a broken state and can corrupt the class klist on klist_add_tail().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203115553.2318954-1-liguangshuo@mail.sdu.edu.cn?part=1
prev parent reply other threads:[~2026-12-03 12:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 11:55 [PATCH] RDMA/rtrs-srv: Fix potential session use-after-free on sysfs failure Guangshuo Li
2026-12-03 12:14 ` 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=sashiko-outbox-247704@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=liguangshuo@mail.sdu.edu.cn \
--cc=linux-rdma@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