lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ff196b04-e8c5-52d9-852b-9a9cc7eecdd0@amd.com>
Date:   Mon, 12 Jun 2023 15:21:58 +0200
From:   Christian König <christian.koenig@....com>
To:     Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@...cinc.com>,
        Sukrut Bellary <sukrut.bellary@...ux.com>,
        Jeffrey Hugo <quic_jhugo@...cinc.com>,
        Oded Gabbay <ogabbay@...nel.org>,
        Sumit Semwal <sumit.semwal@...aro.org>
Cc:     linux-arm-msm@...r.kernel.org, kernel-janitors@...r.kernel.org,
        linux-kernel@...r.kernel.org, dri-devel@...ts.freedesktop.org,
        linaro-mm-sig@...ts.linaro.org, linux-media@...r.kernel.org
Subject: Re: [PATCH] accel/qaic: Fix dereferencing freed memory

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@...ux.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.

Regards,
Christian.

>
>>
>>>       } else {
>>>           /* Private buffer allocation path */
>>>           qaic_free_sgt(bo->sgt);
>>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ