From: Jeffrey Hugo <quic_jhugo@quicinc.com>
To: "Christian König" <christian.koenig@amd.com>,
"Pranjal Ramajor Asha Kanojiya" <quic_pkanojiy@quicinc.com>,
"Sukrut Bellary" <sukrut.bellary@linux.com>,
"Oded Gabbay" <ogabbay@kernel.org>,
"Sumit Semwal" <sumit.semwal@linaro.org>
Cc: <linux-arm-msm@vger.kernel.org>,
<kernel-janitors@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<dri-devel@lists.freedesktop.org>,
<linaro-mm-sig@lists.linaro.org>, <linux-media@vger.kernel.org>
Subject: Re: [PATCH] accel/qaic: Fix dereferencing freed memory
Date: Mon, 12 Jun 2023 09:09:39 -0600 [thread overview]
Message-ID: <b5e5c141-b5df-e24d-8fa4-94297d561cec@quicinc.com> (raw)
In-Reply-To: <ff196b04-e8c5-52d9-852b-9a9cc7eecdd0@amd.com>
On 6/12/2023 7:21 AM, Christian König wrote:
> Am 12.06.23 um 15:03 schrieb Pranjal Ramajor Asha Kanojiya:
>>
>>
>> On 6/12/2023 4:52 PM, Christian König wrote:
>>>
>>>
>>> Am 10.06.23 um 04:12 schrieb Sukrut Bellary:
>>>> smatch warning:
>>>> drivers/accel/qaic/qaic_data.c:620 qaic_free_object() error:
>>>> dereferencing freed memory 'obj->import_attach'
>>>>
>>>> obj->import_attach is detached and freed using dma_buf_detach().
>>>> But used after free to decrease the dmabuf ref count using
>>>> dma_buf_put().
>>>>
>>>> Fixes: ff13be830333 ("accel/qaic: Add datapath")
>>>> Signed-off-by: Sukrut Bellary <sukrut.bellary@linux.com>
>>>> ---
>>>> drivers/accel/qaic/qaic_data.c | 4 +++-
>>>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/accel/qaic/qaic_data.c
>>>> b/drivers/accel/qaic/qaic_data.c
>>>> index e42c1f9ffff8..7cba4d680ea8 100644
>>>> --- a/drivers/accel/qaic/qaic_data.c
>>>> +++ b/drivers/accel/qaic/qaic_data.c
>>>> @@ -613,11 +613,13 @@ static int qaic_gem_object_mmap(struct
>>>> drm_gem_object *obj, struct vm_area_struc
>>>> static void qaic_free_object(struct drm_gem_object *obj)
>>>> {
>>>> struct qaic_bo *bo = to_qaic_bo(obj);
>>>> + struct dma_buf *dmabuf;
>>>
>>> Maybe move that variable into the if.
>>>
>>>> if (obj->import_attach) {
>>>> /* DMABUF/PRIME Path */
>>>> + dmabuf = obj->import_attach->dmabuf;
>>>> dma_buf_detach(obj->import_attach->dmabuf,
>>>> obj->import_attach);
>>>> - dma_buf_put(obj->import_attach->dmabuf);
>>>> + dma_buf_put(dmabuf);
>>>
>>> I strongly assume you are not using the GEM prime helpers for this?
>>>
>>> Christian.
>>
>> Driver uses drm_gem_prime_fd_to_handle() helper function but it also
>> registers for ->gem_prime_import() which is internally called by
>> drm_gem_prime_fd_to_handle(). All the operations done in
>> gem_prime_import() are undone here.
>
> Then why don't you use drm_prime_gem_destroy() which is the cleanup
> helper for imports created by ->gem_prime_import() ?
>
> That looks pretty much identical to what you do here manually.
I think destroy() wasn't used because we are new to DRM and sometimes
confused by the multitude of options. I appreciate the suggestion and
will follow up to see if destroy() will work here, or identify what
would prevent the use of it.
-Jeff
next prev parent reply other threads:[~2023-06-12 15:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-10 2:12 [PATCH] accel/qaic: Fix dereferencing freed memory Sukrut Bellary
2023-06-12 11:22 ` Christian König
2023-06-12 13:03 ` Pranjal Ramajor Asha Kanojiya
2023-06-12 13:21 ` Christian König
2023-06-12 15:09 ` Jeffrey Hugo [this message]
2023-06-12 15:47 ` Pranjal Ramajor Asha Kanojiya
2023-06-12 12:44 ` Pranjal Ramajor Asha Kanojiya
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=b5e5c141-b5df-e24d-8fa4-94297d561cec@quicinc.com \
--to=quic_jhugo@quicinc.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=ogabbay@kernel.org \
--cc=quic_pkanojiy@quicinc.com \
--cc=sukrut.bellary@linux.com \
--cc=sumit.semwal@linaro.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