From: Yu Wang <quic_yyuwang@quicinc.com>
To: Johannes Berg <johannes@sipsolutions.net>,
Greg KH <gregkh@linuxfoundation.org>
Cc: <rafael@kernel.org>, <linux-kernel@vger.kernel.org>,
<kernel@quicinc.com>
Subject: Re: [PATCH] Devcoredump: fix use-after-free issue when releasing devcd device
Date: Tue, 31 Oct 2023 16:29:43 +0800 [thread overview]
Message-ID: <ab509035-cf3c-4902-87a8-cbba03ac948c@quicinc.com> (raw)
In-Reply-To: <22ab53d1ae36d4925732e6e1dc989dc75af126da.camel@sipsolutions.net>
Thanks for your comments :)
On 10/27/2023 8:45 PM, Johannes Berg wrote:
> On Fri, 2023-10-27 at 13:11 +0200, Greg KH wrote:
>>>
>>> static void my_coredump()
>>> {
>>> struct my_coredump_state dump_state;
>>> struct device *new_device =
>>> kzalloc(sizeof(*new_device), GFP_KERNEL);
>>>
>>> ...
>>> new_device->release = my_dev_release;
>>> device_initialize(new_device);
>>> ...
>>> device_add(new_device);
>>> ...
>>> init_completion(&dump_state.dump_done);
>>> dev_coredumpm(new_device, NULL, &dump_state, datalen, GFP_KERNEL,
>>> my_coredump_read, my_coredump_free);
>>> wait_for_completion(&dump_state.dump_done);
>>> device_del(new_device);
>>> put_device(new_device);
>>> }
>>
>> Is there any in-kernel user like this? If so, why not fix them up to
>> not do this?
In this case, the device is temporarily added for dump only, so we need to
delete it when dump is completed.
The other users doesn't add/delete the device like this.
>>
>
> Maybe this is only a simplified scenario and whenever you remove a
> device when a coredump is still pending this can happen?
It removes the device when the @free function has been called, I think
the @free function should be considered as a completion signal, and so
we need to put @free at the end of falling-device-related-clean-up in
devcoredump framework (the change in the patch).
>
> Actually, no, wait, what is this doing??? Why is there a completion and
> all that stuff there? You shouldn't really care about the dump once you
> have created it, and not pass NULL for the struct module pointer
> either?!
Yes, I know we don't need to care about the dump data, but as mentioned
upon, the device is locally and temporarily created for this one-time dump
only, we need to free it when dump is completed, so introduce this completion.
Refer to drivers/remoteproc/remoteproc_coredump.c.
Regarding NULL for the struct module pointer, looks it's allowed for this
API (<remoteproc_coredump.c> also pass NULL)? But yes, it's not nice indeed,
we need this to get a reference of the calling module for safety.
Will correct in the next patch set.
>
> johannes
Best Regards,
Yu
next prev parent reply other threads:[~2023-10-31 8:30 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-27 5:55 Yu Wang
2023-10-27 6:22 ` Mukesh Ojha
2023-10-28 9:20 ` Mukesh Ojha
2023-10-27 6:23 ` Mukesh Ojha
2023-10-27 6:55 ` Mukesh Ojha
2023-10-27 11:11 ` Greg KH
[not found] ` <22ab53d1ae36d4925732e6e1dc989dc75af126da.camel@sipsolutions.net>
2023-10-31 8:29 ` Yu Wang [this message]
2023-10-31 8:59 ` Johannes Berg
2023-10-31 12:46 ` Mukesh Ojha
2023-10-31 13:02 ` Greg KH
2023-10-27 11:12 ` Greg KH
2023-10-31 7:15 ` Yu Wang
2023-10-31 7:39 ` Greg KH
2023-10-31 9:41 ` Yu Wang
2023-10-31 9:50 ` Greg KH
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=ab509035-cf3c-4902-87a8-cbba03ac948c@quicinc.com \
--to=quic_yyuwang@quicinc.com \
--cc=gregkh@linuxfoundation.org \
--cc=johannes@sipsolutions.net \
--cc=kernel@quicinc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@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
all inboxes | Powered by JetHome®