From: Matt Evans <matt@ozlabs.org>
To: Alex Mastro <amastro@fb.com>
Cc: "Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Zack Rusin" <zack.rusin@broadcom.com>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Tvrtko Ursulin" <tursulin@ursulin.net>,
linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org,
"Alex Williamson" <alex@shazbot.org>
Subject: Re: [PATCH] dma-buf: Annul dmabuf->file on file release
Date: Wed, 7 Oct 2026 15:42:54 +0100 [thread overview]
Message-ID: <88a14307-37a2-4081-b5b1-039d4f64a6da@ozlabs.org> (raw)
In-Reply-To: <asYOmaPqwUOBdz0x@devgpu015.cco6.facebook.com>
Hi Alex,
On 07/10/2026 10:19, Alex Mastro wrote:
> On Tue, Oct 06, 2026 at 08:15:26PM +0100, Matt Evans wrote:
>> static int dma_buf_file_release(struct inode *inode, struct file *file)
>> {
>> + struct dma_buf *dmabuf = file->private_data;
>
> I think dmabuf can be NULL here if the dmabuf allocation fails during
> dma_buf_export().
>
>> +
>> if (!is_dma_buf_file(file))
>> return -EINVAL;
>> - __dma_buf_list_del(file->private_data);
>> + __dma_buf_list_del(dmabuf);
>> + /* Must be observed by __get_file_rcu() before file_free() */
>> + smp_store_mb(dmabuf->file, NULL);
>
> Resulting in NULL deref here -- guard with null check?
Oof, yes! Thanks for catching this. __dma_buf_list_del() protects
itself against a NULL arg. Done.
Thanks,
Matt
>
>> return 0;
>> }
>
> via this path
>
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index d504c636dc29..557cd7a4c971 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -725,6 +725,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
> if (!try_module_get(exp_info->owner))
> return ERR_PTR(-ENOENT);
>
> + // succeeds
> file = dma_buf_getfile(exp_info->size, exp_info->flags);
> if (IS_ERR(file)) {
> ret = PTR_ERR(file);
> @@ -739,6 +740,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
> dmabuf = kzalloc(alloc_size, GFP_KERNEL);
> if (!dmabuf) {
> ret = -ENOMEM;
> + // go here
> goto err_file;
> }
>
> @@ -771,6 +773,7 @@ struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info)
> return dmabuf;
>
> err_file:
> + // ends up calling dma_buf_file_release()
> fput(file);
> err_module:
> module_put(exp_info->owner);
>
next prev parent reply other threads:[~2026-10-07 14:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 19:15 Matt Evans
2026-10-07 7:51 ` Christian König
2026-10-07 14:29 ` Matt Evans
2026-10-07 14:46 ` Christian König
2026-10-07 9:19 ` Alex Mastro
2026-10-07 14:42 ` Matt Evans [this message]
2026-10-07 15:24 ` Zack Rusin
2026-10-08 13:41 ` Matt Evans
2026-10-12 16:03 ` Matt Evans
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=88a14307-37a2-4081-b5b1-039d4f64a6da@ozlabs.org \
--to=matt@ozlabs.org \
--cc=alex@shazbot.org \
--cc=amastro@fb.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=sumit.semwal@linaro.org \
--cc=tursulin@ursulin.net \
--cc=zack.rusin@broadcom.com \
/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®