Subject: CVE-2021-47305: dma-buf/sync_file: Don't leak fences on merge failure

From: Greg Kroah-Hartman <[email-masked]>

Description
===========

In the Linux kernel, the following vulnerability has been resolved:

dma-buf/sync_file: Don't leak fences on merge failure

Each add_fence() call does a dma_fence_get() on the relevant fence.  In
the error path, we weren't calling dma_fence_put() so all those fences
got leaked.  Also, in the krealloc_array failure case, we weren't
freeing the fences array.  Instead, ensure that i and fences are always
zero-initialized and dma_fence_put() all the fences and kfree(fences) on
every error path.

The Linux kernel CVE team has assigned CVE-2021-47305 to this issue.

Affected and fixed versions
===========================

	Issue introduced in 4.9 with commit a02b9dc90d84 and fixed in 4.14.241 with commit 19f51c252933
	Issue introduced in 4.9 with commit a02b9dc90d84 and fixed in 4.19.199 with commit e0355a0ad31a
	Issue introduced in 4.9 with commit a02b9dc90d84 and fixed in 5.4.135 with commit 41f45e91c92c
	Issue introduced in 4.9 with commit a02b9dc90d84 and fixed in 5.10.53 with commit 0d514185ae79
	Issue introduced in 4.9 with commit a02b9dc90d84 and fixed in 5.13.5 with commit 19edcd97727a
	Issue introduced in 4.9 with commit a02b9dc90d84 and fixed in 5.14 with commit ffe000217c50

Please see https://www.kernel.org for a full list of currently supported
kernel versions by the kernel community.

Unaffected versions might change over time as fixes are backported to
older supported kernel versions.  The official CVE entry at
	https://cve.org/CVERecord/?id=CVE-2021-47305
will be updated if fixes are backported, please check that for the most
up to date information about this issue.

Affected files
==============

The file(s) affected by this issue are:
	drivers/dma-buf/sync_file.c

Mitigation
==========

The Linux kernel CVE team recommends that you update to the latest
stable kernel version for this, and many other bugfixes.  Individual
changes are never tested alone, but rather are part of a larger kernel
release.  Cherry-picking individual commits is not recommended or
supported by the Linux kernel community at all.  If however, updating to
the latest release is impossible, the individual changes to resolve this
issue can be found at these commits:
	https://git.kernel.org/stable/c/19f51c2529339280d2c8c6427cd3e21ddf1ac3f8
	https://git.kernel.org/stable/c/e0355a0ad31a1d677b2a4514206de4902bd550e8
	https://git.kernel.org/stable/c/41f45e91c92c8480242ea448d54e28c753b13902
	https://git.kernel.org/stable/c/0d514185ae792d3a1903c8e1a83899aa996705ce
	https://git.kernel.org/stable/c/19edcd97727aae9362444a859a24d99a8730cb27
	https://git.kernel.org/stable/c/ffe000217c5068c5da07ccb1c0f8cce7ad767435