Re:Re: Re: Re: [PATCH] RDMA/rtrs: Fix potential use-after-free on client sysfs setup failure

From: 李广硕

Date: Tue Nov 24 2026 - 09:05:33 EST


Hi Haris,

Thanks for checking this internally.

发件人:Haris Iqbal <haris.iqbal@xxxxxxxxxxxxxxx>
发送日期:2026-11-19 22:35:23
收件人:"李广硕" <liguangshuo@xxxxxxxxxxxxxxx>
抄送人:Leon Romanovsky <leon@xxxxxxxxxx>,Jason Gunthorpe <jgg@xxxxxxxx>,stable@xxxxxxxxxxxxxxx,Jack Wang <jinpu.wang@xxxxxxxxx>,linux-rdma@xxxxxxxxxxxxxxx,linux-kernel@xxxxxxxxxxxxxxx
主题:Re: Re: Re: [PATCH] RDMA/rtrs: Fix potential use-after-free on client sysfs setup failure>On Thu, Nov 19, 2026 at 1:41 PM 李广硕 <liguangshuo@xxxxxxxxxxxxxxx> wrote:
>>
>>
>> Hi Leon,
>>
>> Thanks for the review.
>>
>> 发件人:Leon Romanovsky <leon@xxxxxxxxxx>
>> 发送日期:2026-11-13 03:09:48
>> 收件人:"李广硕" <liguangshuo@xxxxxxxxxxxxxxx>
>> 抄送人:Jason Gunthorpe <jgg@xxxxxxxx>,stable@xxxxxxxxxxxxxxx,"Md. Haris Iqbal" <haris.iqbal@xxxxxxxxx>,Jack Wang <jinpu.wang@xxxxxxxxx>,linux-rdma@xxxxxxxxxxxxxxx,linux-kernel@xxxxxxxxxxxxxxx
>> 主题:Re: Re: [PATCH] RDMA/rtrs: Fix potential use-after-free on client sysfs setup failure>On Mon, Nov 09, 2026 at 08:56:46PM +0800, 李广硕 wrote:
>> >> Hi Leon,
>> >>
>> >> Thanks for reviewing.
>> >>
>> >> From: Leon Romanovsky <leon@xxxxxxxxxx>
>> >> Date: 2026-11-09 19:16:52
>> >> To: Guangshuo Li <liguangshuo@xxxxxxxxxxxxxxx>
>> >> Cc: Jason Gunthorpe <jgg@xxxxxxxx>,stable@xxxxxxxxxxxxxxx,"Md. Haris Iqbal" <haris.iqbal@xxxxxxxxx>,Jack Wang <jinpu.wang@xxxxxxxxx>,linux-rdma@xxxxxxxxxxxxxxx,linux-kernel@xxxxxxxxxxxxxxx
>> >> Subject: Re: [PATCH] RDMA/rtrs: Fix potential use-after-free on client sysfs setup failure>On Sat, Oct 31, 2026 at 10:14:46PM +0800, Guangshuo Li wrote:
>> >> >> rtrs_clt_create_path_files() drops the path reference on failure, but
>> >> >> its callers still close connections and free the path. This can access
>> >> >> freed memory and free the path twice.
>> >> >
>> >> >Sorry, but how?
>> >> >
>> >> Consider an allocation failure while setting the name of the path
>> >> kobject in rtrs_clt_create_path_files(). kobject_init_and_add() has
>> >> already initialized the reference count to one when setting the name
>> >> fails with -ENOMEM. The stats kobject has not been created yet, and
>> >> adding the path to clt->paths_list did not take a kobject reference.
>> >>
>> >> The error branch then calls kobject_put(&clt_path->kobj). This drops
>> >> the only reference. With CONFIG_DEBUG_KOBJECT_RELEASE=n,
>> >> rtrs_clt_path_release() runs synchronously and calls free_path(), which
>> >> does kfree(clt_path).
>> >>
>> >> Back in rtrs_clt_open(), the first statement on that error path is:
>> >>
>> >> list_del_rcu(&clt_path->s.entry);
>> >>
>> >> That accesses the list node embedded in the path that was just freed.
>> >> This is the use-after-free I meant.
>> >
>> >The error handling appears to be incorrect. rtrs_clt_create_path_files()
>> >should undo only the changes it made internally and error handling of
>> >call to rtrs_clt_create_path_files() should undo what was done in
>> >rtrs_clt_open().
>> >
>> >Thanks
>> >
>> >>
>> >> Thanks,
>> >> Guangshuo
>> >
>>
>> My understanding is that rtrs_clt_create_path_files() should undo its
>> own sysfs setup on failure. The caller still needs the path to unlink
>> it and close the connections, so it should hold its reference until
>> both are done.
>>
>> Is that the split you meant? If so, I'll send a v2 using it in both
>> rtrs_clt_open() and rtrs_clt_create_path_from_sysfs().
>
>Thank you Guangshuo for the patch and Leon for the review.
>The bug is real. We verified it internally, and somewhere between this
>patch and the first one Guangshuo sent in May, we solved this
>internally but missed sending it upstream. It was a miss from us,
>apologies for that.
>
>We will send the version we have soon, alongside with other fixes.
>
>>
>> Thanks,
>> Guangshuo
>
>
>
>--
>
>Regards
>-Haris
>

I understand that you already have a fix and will send it with the
other changes. I'll wait for your series and review that version.

Thanks,
Guangshuo