From: Oded Gabbay <oded.gabbay@gmail.com>
To: Tomer Tayar <ttayar@habana.ai>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] habanalabs: Avoid double free in error flow
Date: Thu, 1 Aug 2019 17:13:41 +0300 [thread overview]
Message-ID: <CAFCwf12jg7mS5wB05pfawOPrNC4rXXuSc=yJub5eWQBeHTTOQA@mail.gmail.com> (raw)
In-Reply-To: <20190801135721.13211-1-ttayar@habana.ai>
On Thu, Aug 1, 2019 at 4:57 PM Tomer Tayar <ttayar@habana.ai> wrote:
>
> In case kernel context init fails during device initialization, both
> hl_ctx_put() and kfree() are called, ending with a double free of the
> kernel context.
> Calling kfree() is needed only when a failure happens between the
> allocation of the kernel context and its initialization, so move it to
> there and remove it from the error flow.
>
> Signed-off-by: Tomer Tayar <ttayar@habana.ai>
> ---
> drivers/misc/habanalabs/device.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/misc/habanalabs/device.c b/drivers/misc/habanalabs/device.c
> index 0c4894dd9c02..7a8f9d0b71b5 100644
> --- a/drivers/misc/habanalabs/device.c
> +++ b/drivers/misc/habanalabs/device.c
> @@ -970,7 +970,8 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass)
> rc = hl_ctx_init(hdev, hdev->kernel_ctx, true);
> if (rc) {
> dev_err(hdev->dev, "failed to initialize kernel context\n");
> - goto free_ctx;
> + kfree(hdev->kernel_ctx);
> + goto mmu_fini;
> }
>
> rc = hl_cb_pool_init(hdev);
> @@ -1053,8 +1054,6 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass)
> if (hl_ctx_put(hdev->kernel_ctx) != 1)
> dev_err(hdev->dev,
> "kernel ctx is still alive on initialization failure\n");
> -free_ctx:
> - kfree(hdev->kernel_ctx);
> mmu_fini:
> hl_mmu_fini(hdev);
> eq_fini:
> --
> 2.17.1
>
This patch is:
Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com>
Applied to -fixed
Oded
prev parent reply other threads:[~2019-08-01 14:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-01 13:57 [PATCH] habanalabs: Avoid double free in error flow Tomer Tayar
2019-08-01 14:13 ` Oded Gabbay [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='CAFCwf12jg7mS5wB05pfawOPrNC4rXXuSc=yJub5eWQBeHTTOQA@mail.gmail.com' \
--to=oded.gabbay@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ttayar@habana.ai \
/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;
as well as URLs for NNTP newsgroup(s).