From: Matthias Kaehlcke <mka@chromium.org>
To: Sujit Kautkar <sujitka@chromium.org>
Cc: Andy Gross <agross@kernel.org>, Ohad Ben-Cohen <ohad@wizery.com>,
Stephen Boyd <swboyd@chromium.org>,
Sibi Sankar <sibis@codeaurora.org>,
Bjorn Andersson <bjorn.andersson@linaro.org>,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-remoteproc@vger.kernel.org
Subject: Re: [PATCH v2 1/2] rpmsg: glink: Fix use-after-free in qcom_glink_rpdev_release()
Date: Mon, 25 Oct 2021 17:29:13 -0700 [thread overview]
Message-ID: <YXdL2RfdYwy2g+kr@google.com> (raw)
In-Reply-To: <20211025163739.v2.1.Id19324ea36b4cf89faf98bf520bc6b6f01240433@changeid>
On Mon, Oct 25, 2021 at 04:37:52PM -0700, Sujit Kautkar wrote:
> qcom_glink_rpdev_release() sets channel->rpdev to NULL. However, with
> debug enabled kernel, qcom_glink_rpdev_release() gets delayed due to
> delayed kobject release and channel gets released by that time and
> triggers below kernel warning. To avoid this use-after-free, add a
> condition to checks if channel was already released.
>
> | BUG: KASAN: use-after-free in qcom_glink_rpdev_release+0x54/0x70
> | Write of size 8 at addr ffffffaba438e8d0 by task kworker/6:1/54
> |
> | CPU: 6 PID: 54 Comm: kworker/6:1 Not tainted 5.4.109-lockdep #16
> | Hardware name: Google Lazor (rev3+) with KB Backlight (DT)
> | Workqueue: events kobject_delayed_cleanup
> | Call trace:
> | dump_backtrace+0x0/0x284
> | show_stack+0x20/0x2c
> | dump_stack+0xd4/0x170
> | print_address_description+0x3c/0x4a8
> | __kasan_report+0x144/0x168
> | kasan_report+0x10/0x18
> | __asan_report_store8_noabort+0x1c/0x24
> | qcom_glink_rpdev_release+0x54/0x70
> | device_release+0x68/0x14c
> | kobject_delayed_cleanup+0x158/0x2cc
> | process_one_work+0x7cc/0x10a4
> | worker_thread+0x80c/0xcec
> | kthread+0x2a8/0x314
> | ret_from_fork+0x10/0x18
>
> Signed-off-by: Sujit Kautkar <sujitka@chromium.org>
> ---
>
> (no changes since v1)
>
> drivers/rpmsg/qcom_glink_native.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c
> index e1444fefdd1c0..cc3556a9385a9 100644
> --- a/drivers/rpmsg/qcom_glink_native.c
> +++ b/drivers/rpmsg/qcom_glink_native.c
> @@ -270,6 +270,7 @@ static void qcom_glink_channel_release(struct kref *ref)
> spin_unlock_irqrestore(&channel->intent_lock, flags);
>
> kfree(channel->name);
> + channel = NULL;
This doesn't make much sense, 'channel' is a local variable, the only effect
this has is that the memory of 'channel' isn't freed by the 'kfree' below.
Maybe this is debug code and wasn't intended to be part of this patch?
> kfree(channel);
> }
>
> @@ -1372,8 +1373,10 @@ static void qcom_glink_rpdev_release(struct device *dev)
> {
> struct rpmsg_device *rpdev = to_rpmsg_device(dev);
> struct glink_channel *channel = to_glink_channel(rpdev->ept);
> + if (channel) {
> + channel->rpdev = NULL;
> + }
Remove curly braces for single line branch.
>
> - channel->rpdev = NULL;
> kfree(rpdev);
> }
>
> --
> 2.31.0
>
prev parent reply other threads:[~2021-10-26 0:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-25 23:37 [PATCH v2 0/2] Fix two kernel warnings in glink driver Sujit Kautkar
2021-10-25 23:37 ` [PATCH v2 1/2] rpmsg: glink: Fix use-after-free in qcom_glink_rpdev_release() Sujit Kautkar
2021-10-26 0:29 ` Matthias Kaehlcke [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=YXdL2RfdYwy2g+kr@google.com \
--to=mka@chromium.org \
--cc=agross@kernel.org \
--cc=bjorn.andersson@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=ohad@wizery.com \
--cc=sibis@codeaurora.org \
--cc=sujitka@chromium.org \
--cc=swboyd@chromium.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