Skip to contentSkip to conversation

CVE-2021-47081: habanalabs/gaudi: Fix a potential use after free in gaudi_memset_device_memory

DISCUSSION Greg Kroah-Hartman 1 participant 1 message Mar 1, 2024

lore
Share & tools
lore
#0 lore raw

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

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

habanalabs/gaudi: Fix a potential use after free in gaudi_memset_device_memory

Our code analyzer reported a uaf.

In gaudi_memset_device_memory, cb is get via hl_cb_kernel_create() with 2 refcount.
If hl_cs_allocate_job() failed, the execution runs into release_cb branch. One ref of cb is dropped by hl_cb_put(cb) and could be freed if other thread also drops one ref. Then cb is used by cb->id later, which is a potential uaf.

My patch add a variable 'id' to accept the value of cb->id before the hl_cb_put(cb) is called, to avoid the potential uaf.

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

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

	Issue introduced in 5.12 with commit 423815bf02e25 and fixed in 5.12.7 with commit b49f5af30b0e
	Issue introduced in 5.12 with commit 423815bf02e25 and fixed in 5.13 with commit 115726c5d312

Please see https://www.kernel.org or 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-47081

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/misc/habanalabs/gaudi/gaudi.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/b49f5af30b0e4064fbd91e83823a4bfcb2c7a3e7
	https://git.kernel.org/stable/c/115726c5d312b462c9d9931ea42becdfa838a076