Subject: CVE-2024-39494: ima: Fix use-after-free on a dentry's dname.name

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

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

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

ima: Fix use-after-free on a dentry's dname.name

->d_name.name can change on rename and the earlier value can be freed;
there are conditions sufficient to stabilize it (->d_lock on dentry,
->d_lock on its parent, ->i_rwsem exclusive on the parent's inode,
rename_lock), but none of those are met at any of the sites. Take a stable
snapshot of the name instead.

The Linux kernel CVE team has assigned CVE-2024-39494 to this issue.

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

	Fixed in 6.1.97 with commit 7fb374981e31
	Fixed in 6.6.35 with commit dd431c3ac1fc
	Fixed in 6.9.6 with commit a78a6f0da57d
	Fixed in 6.10 with commit be84f32bb2c9

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-2024-39494
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:
	security/integrity/ima/ima_api.c
	security/integrity/ima/ima_template_lib.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/7fb374981e31c193b1152ed8d3b0a95b671330d4
	https://git.kernel.org/stable/c/dd431c3ac1fc34a9268580dd59ad3e3c76b32a8c
	https://git.kernel.org/stable/c/a78a6f0da57d058e2009e9958fdcef66f165208c
	https://git.kernel.org/stable/c/be84f32bb2c981ca670922e047cdde1488b233de