From: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>,
dri-devel@lists.freedesktop.org, david1.zhou@amd.com
Subject: Re: [PATCH] dma-buf: fix stack corruption in dma_fence_chain_release
Date: Mon, 5 Aug 2019 15:03:50 +0300 [thread overview]
Message-ID: <1ad7ef20-0207-7f80-ee12-ec98c1d5dfcb@intel.com> (raw)
In-Reply-To: <20190805073657.1389-1-christian.koenig@amd.com>
By any change, did you run into this with a CTS test whose name ends
with ".chain" ? :)
-Lionel
On 05/08/2019 10:36, Christian König wrote:
> We can't free up the chain using recursion or we run into a stack overflow.
>
> Manually free up the dangling chain nodes to avoid recursion.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/dma-buf/dma-fence-chain.c | 24 +++++++++++++++++++++++-
> 1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/dma-buf/dma-fence-chain.c b/drivers/dma-buf/dma-fence-chain.c
> index b5089f64be2a..44a741677d25 100644
> --- a/drivers/dma-buf/dma-fence-chain.c
> +++ b/drivers/dma-buf/dma-fence-chain.c
> @@ -178,8 +178,30 @@ static bool dma_fence_chain_signaled(struct dma_fence *fence)
> static void dma_fence_chain_release(struct dma_fence *fence)
> {
> struct dma_fence_chain *chain = to_dma_fence_chain(fence);
> + struct dma_fence *prev;
> +
> + /* Manually unlink the chain as much as possible to avoid recursion
> + * and potential stack overflow.
> + */
> + while ((prev = rcu_dereference_protected(chain->prev, true))) {
> + struct dma_fence_chain *prev_chain;
> +
> + if (kref_read(&prev->refcount) > 1)
> + break;
> +
> + prev_chain = to_dma_fence_chain(prev);
> + if (!prev_chain)
> + break;
> +
> + /* No need for atomic operations since we hold the last
> + * reference to prev_chain.
> + */
> + chain->prev = prev_chain->prev;
> + RCU_INIT_POINTER(prev_chain->prev, NULL);
> + dma_fence_put(prev);
> + }
> + dma_fence_put(prev);
>
> - dma_fence_put(rcu_dereference_protected(chain->prev, true));
> dma_fence_put(chain->fence);
> dma_fence_free(fence);
> }
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2019-08-05 12:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190805073657.1389-1-christian.koenig@amd.com>
2019-08-05 8:23 ` [PATCH] dma-buf: fix stack corruption in dma_fence_chain_release Lionel Landwerlin
2019-08-05 12:03 ` Lionel Landwerlin [this message]
2019-08-05 13:02 ` Christian König
2019-08-05 13:32 ` Lionel Landwerlin
2019-08-05 16:30 ` Daniel Vetter
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=1ad7ef20-0207-7f80-ee12-ec98c1d5dfcb@intel.com \
--to=lionel.g.landwerlin@intel.com \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=david1.zhou@amd.com \
--cc=dri-devel@lists.freedesktop.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