From: Leon Romanovsky <leon@kernel.org>
To: Md Haris Iqbal <haris.iqbal@ionos.com>
Cc: linux-rdma@vger.kernel.org, Jason Gunthorpe <jgg@ziepe.ca>,
Shuangpeng Bai <shuangpeng.kernel@gmail.com>
Subject: Re: [PATCH 9/9] RDMA/rtrs-clt: Close all paths before freeing any in rtrs_clt_close()
Date: Thu, 26 Nov 2026 14:04:24 +0200 [thread overview]
Message-ID: <20261126120424.GJ774860@unreal> (raw)
In-Reply-To: <20261123143719.938876-10-haris.iqbal@ionos.com>
On Mon, Nov 23, 2026 at 03:37:19PM +0100, Md Haris Iqbal wrote:
> rtrs_clt_close() closes and frees the paths one at a time. Meanwhile, the
> paths that are not closed yet can still walk clt->paths_list: a reconnect
> fires link_ev(RECONNECTED), whose handler calls rtrs_clt_query(), and a
> closing path fails its requests over through rtrs_clt_failover_req().
> Either can then touch a path that is already freed:
>
> BUG: KASAN: slab-use-after-free in rtrs_clt_query
> Workqueue: rtrs_client_wq rtrs_clt_reconnect_work
> rtrs_clt_query
> rnbd_clt_link_ev
> init_path
> rtrs_clt_reconnect_work
Please include the full dmesg stack trace in commit messages for RDMA-related changes.
Thanks
>
> Move every path to CLOSING first, wait for all close works, and only then
> unlink and free the paths. A close work cancels the reconnect work of its
> path synchronously, so no path is freed while another one still uses the
> list.
>
> rtrs_clt_open() tears down its paths on error the same way, so move the
> sequence into rtrs_clt_destroy_all_paths() and use it from both, with
> sysfs torn down first.
>
> Fixes: 6a98d71daea1 ("RDMA/rtrs: client: main functionality")
> Reported-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
> Closes: https://lore.kernel.org/linux-rdma/20261105202939.3104321-1-shuangpeng.kernel@gmail.com/
> Signed-off-by: Md Haris Iqbal <haris.iqbal@ionos.com>
> ---
> drivers/infiniband/ulp/rtrs/rtrs-clt.c | 49 ++++++++++++++++++--------
> 1 file changed, 34 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> index 7930039dcd32..760ae71c9230 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> @@ -2862,6 +2862,38 @@ static void free_clt(struct rtrs_clt_sess *clt)
> device_unregister(&clt->dev);
> }
>
> +/*
> + * Close and free every path of @clt. The caller has torn down sysfs, so
> + * no paths can be added or removed, and does not use the session any more
> + * (no IO, no rtrs_clt_query()).
> + *
> + * Until its close work has finished, a path can still reconnect (firing
> + * link_ev, whose user may call rtrs_clt_query()) or fail requests over,
> + * and both walk clt->paths_list. So move every path to CLOSING first,
> + * which keeps further reconnect attempts from starting, wait for all of
> + * them, and only then free.
> + */
> +static void rtrs_clt_destroy_all_paths(struct rtrs_clt_sess *clt)
> +{
> + struct rtrs_clt_path *clt_path, *tmp;
> +
> + list_for_each_entry(clt_path, &clt->paths_list, s.entry)
> + rtrs_clt_close_conns(clt_path, false);
> + list_for_each_entry(clt_path, &clt->paths_list, s.entry)
> + flush_work(&clt_path->close_work);
> +
> + /*
> + * The close works have flushed every reconnect and stopped the
> + * heartbeat, and the caller issues nothing, so nobody walks the list
> + * any more and no grace period is needed.
> + */
> + list_for_each_entry_safe(clt_path, tmp, &clt->paths_list, s.entry) {
> + list_del(&clt_path->s.entry);
> + rtrs_clt_destroy_path_files(clt_path, NULL);
> + kobject_put(&clt_path->kobj);
> + }
> +}
> +
> /**
> * rtrs_clt_open() - Open a path to an RTRS server
> * @ops: holds the link event callback and the private pointer.
> @@ -2887,7 +2919,6 @@ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops,
> size_t pdu_sz, u8 reconnect_delay_sec,
> s16 max_reconnect_attempts, u32 nr_poll_queues)
> {
> - struct rtrs_clt_path *clt_path, *tmp;
> struct rtrs_clt_sess *clt;
> int err, i;
>
> @@ -2943,12 +2974,8 @@ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops,
> return clt;
>
> close_all_path:
> - list_for_each_entry_safe(clt_path, tmp, &clt->paths_list, s.entry) {
> - rtrs_clt_destroy_path_files(clt_path, NULL);
> - rtrs_clt_close_conns(clt_path, true);
> - kobject_put(&clt_path->kobj);
> - }
> rtrs_clt_destroy_sysfs_root(clt);
> + rtrs_clt_destroy_all_paths(clt);
> free_clt(clt);
>
> out:
> @@ -2962,17 +2989,9 @@ EXPORT_SYMBOL(rtrs_clt_open);
> */
> void rtrs_clt_close(struct rtrs_clt_sess *clt)
> {
> - struct rtrs_clt_path *clt_path, *tmp;
> -
> /* Firstly forbid sysfs access */
> rtrs_clt_destroy_sysfs_root(clt);
> -
> - /* Now it is safe to iterate over all paths without locks */
> - list_for_each_entry_safe(clt_path, tmp, &clt->paths_list, s.entry) {
> - rtrs_clt_close_conns(clt_path, true);
> - rtrs_clt_destroy_path_files(clt_path, NULL);
> - kobject_put(&clt_path->kobj);
> - }
> + rtrs_clt_destroy_all_paths(clt);
> free_permits(clt);
> free_clt(clt);
> }
> --
> 2.43.0
>
>
next prev parent reply other threads:[~2026-11-26 12:04 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 14:37 [PATCH 0/9] Misc patches for RTRS Md Haris Iqbal
2026-11-23 14:37 ` [PATCH 1/9] RDMA/rtrs-clt: Add mpath_policy module parameter Md Haris Iqbal
2026-11-23 14:44 ` sashiko-bot
2026-11-26 11:59 ` Leon Romanovsky
2026-11-23 14:37 ` [PATCH 2/9] RDMA/rtrs-clt: Fix refcount imbalance in rtrs_clt_write_req error path Md Haris Iqbal
2026-11-23 14:37 ` [PATCH 3/9] RDMA/rtrs-clt: Trigger error recovery when posting LOCAL_INV fails Md Haris Iqbal
2026-11-23 15:02 ` sashiko-bot
2026-11-24 14:44 ` Haris Iqbal
2026-11-23 14:37 ` [PATCH 4/9] RDMA/rtrs-srv: Fix processing messages for Big-Endian archs Md Haris Iqbal
2026-11-23 14:37 ` [PATCH 5/9] RDMA/rtrs-clt: rename pathname parameter to sessname in rtrs_clt_open() Md Haris Iqbal
2026-11-23 14:42 ` sashiko-bot
2026-11-24 15:03 ` Haris Iqbal
2026-11-23 14:37 ` [PATCH 6/9] RDMA/rtrs-clt: Fix reconnect jitter being applied in milliseconds Md Haris Iqbal
2026-11-23 14:37 ` [PATCH 7/9] RDMA/rtrs-clt: Back off the reconnect delay exponentially Md Haris Iqbal
2026-11-26 12:03 ` Leon Romanovsky
2026-11-23 14:37 ` [PATCH 8/9] RDMA/rtrs-srv: Snapshot the READ request header instead of reusing it Md Haris Iqbal
2026-11-23 14:37 ` [PATCH 9/9] RDMA/rtrs-clt: Close all paths before freeing any in rtrs_clt_close() Md Haris Iqbal
2026-11-26 12:04 ` Leon Romanovsky [this message]
2026-11-23 15:02 ` [PATCH 0/9] Misc patches for RTRS sashiko-bot
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=20261126120424.GJ774860@unreal \
--to=leon@kernel.org \
--cc=haris.iqbal@ionos.com \
--cc=jgg@ziepe.ca \
--cc=linux-rdma@vger.kernel.org \
--cc=shuangpeng.kernel@gmail.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