From: "wanghai (M)" <wanghai38@huawei.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: <dledford@redhat.com>, <leon@kernel.org>, <markzhang@nvidia.com>,
<liangwenpeng@huawei.com>, <liweihang@huawei.com>,
<haakon.bugge@oracle.com>, <rolandd@cisco.com>,
<sean.hefty@intel.com>, <linux-rdma@vger.kernel.org>,
<linux-ide@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] IB/cm: Fix possible use-after-free in ib_cm_cleanup()
Date: Thu, 14 Oct 2021 21:19:07 +0800 [thread overview]
Message-ID: <787f463c-85e9-c1f3-c772-1233e82a71b5@huawei.com> (raw)
In-Reply-To: <20211013182448.GA3489723@nvidia.com>
在 2021/10/14 2:24, Jason Gunthorpe 写道:
> On Wed, Oct 13, 2021 at 05:30:16PM +0800, Wang Hai wrote:
>> This module's remove path calls cancel_delayed_work(). However, that
>> function does not wait until the work function finishes. This means
>> that the callback function may still be running after the driver's
>> remove function has finished, which would result in a use-after-free.
>>
>> Fix by calling cancel_delayed_work_sync(), which ensures that
>> the work is properly cancelled, no longer running, and unable
>> to re-schedule itself.
>>
>> Fixes: 8575329d4f85 ("IB/cm: Fix timewait crash after module unload")
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Wang Hai <wanghai38@huawei.com>
>> drivers/infiniband/core/cm.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
>> index c903b74f46a4..ae0af63f3271 100644
>> +++ b/drivers/infiniband/core/cm.c
>> @@ -4508,7 +4508,7 @@ static void __exit ib_cm_cleanup(void)
>>
>> spin_lock_irq(&cm.lock);
>> list_for_each_entry(timewait_info, &cm.timewait_list, list)
>> - cancel_delayed_work(&timewait_info->work.work);
>> + cancel_delayed_work_sync(&timewait_info->work.work);
>> spin_unlock_irq(&cm.lock);
> No, this will deadlock:
>
> static int cm_timewait_handler(struct cm_work *work)
> {
> struct cm_timewait_info *timewait_info;
> struct cm_id_private *cm_id_priv;
>
> timewait_info = container_of(work, struct cm_timewait_info, work);
> spin_lock_irq(&cm.lock);
> ^^^^^^^^^^^^
>
> Holds the same lock
>
> What is your bug? The destroy_wq() a few lines below will flush out
> all the work so it is already not possible that work can still exist
> after the driver's remove function has finished.
>
> Jason
> .
Sorry, this is a wrong bugfix, thank you for pointing it out.
I was studying the code here and thought there might be a null
pointer reference problem.
You are right, I didn't take into account destroy_workqueue().
There are no bugs here. sorry for making this problematic patch.
Please ignore this patch.
--
Wang Hai
prev parent reply other threads:[~2021-10-14 13:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-13 9:30 [PATCH] IB/cm: Fix possible use-after-free in ib_cm_cleanup() Wang Hai
2021-10-13 18:24 ` Jason Gunthorpe
2021-10-14 13:19 ` wanghai (M) [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=787f463c-85e9-c1f3-c772-1233e82a71b5@huawei.com \
--to=wanghai38@huawei.com \
--cc=dledford@redhat.com \
--cc=haakon.bugge@oracle.com \
--cc=jgg@nvidia.com \
--cc=leon@kernel.org \
--cc=liangwenpeng@huawei.com \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=liweihang@huawei.com \
--cc=markzhang@nvidia.com \
--cc=rolandd@cisco.com \
--cc=sean.hefty@intel.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