Skip to contentSkip to conversation

CVE-2026-63827: apparmor: fix use-after-free in rawdata dedup loop

DISCUSSION Greg Kroah-Hartman 1 participant 1 message Jul 19

lore
Share & tools
lore
#0 lore raw

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

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

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

apparmor: fix use-after-free in rawdata dedup loop

aa_replace_profiles() walks ns->rawdata_list to dedup the incoming policy blob against entries already attached to existing profiles. Per the kernel-doc on struct aa_loaddata, list membership does not hold a reference: profiles hold pcount, and when the last pcount drops, do_ploaddata_rmfs() is queued on a workqueue that takes ns->lock and removes the entry. Between dropping the last pcount and the workqueue running, an entry remains on the list with pcount == 0.

aa_get_profile_loaddata() is an unconditional kref_get() on pcount, so when the dedup loop hits such an entry, refcount hardening reports

refcount_t: addition on 0; use-after-free.

inside aa_replace_profiles(), and the poisoned counter then trips "saturated" and "underflow" warnings on the subsequent uses of the same loaddata.

Before commit a0b7091c4de4 ("apparmor: fix race on rawdata dereference") the dedup path used a get_unless_zero-style helper on a single counter, so the existing "if (tmp)" guard was meaningful. The split-refcount refactor introduced aa_get_profile_loaddata(), which has plain kref_get() semantics, and the guard quietly became a no-op.

Introduce aa_get_profile_loaddata_not0(), matching the existing _not0 convention used by aa_get_profile_not0(), and use it for the rawdata_list dedup lookup so dying entries are skipped.

Reproduced on x86_64 with v7.1-rc5 in QEMU+KVM running Ubuntu 24.04 + stress-ng 0.17.06:

  stress-ng --apparmor 1 --klog-check --timeout 60s

Without this patch the three refcount_t warnings fire within a few seconds. With it the same 60 s run is clean. Coverage is a smoke-test only; a longer soak with CONFIG_KASAN, CONFIG_KCSAN and CONFIG_PROVE_LOCKING would be welcome from anyone with the cycles.

The Linux kernel CVE team has assigned CVE-2026-63827 to this issue.

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

	Issue introduced in 6.1.169 with commit 6b6ba87579c7e7c669e0bec91823e7fb693bc5df and fixed in 6.1.177 with commit a7a2890028f16e5b0af0bb005d80fcb32559cca3
	Issue introduced in 6.6.130 with commit 6ef1f2926c41ab96952d9696d55a052f1b3a9418 and fixed in 6.6.144 with commit 15fd83a1e42ede15070968806bb6c8b1a5170688
	Issue introduced in 6.12.77 with commit f9761add6d100962a23996cb68f3d6abdd4d1815 and fixed in 6.12.95 with commit ce261a20b41db522e320a41bbf1292bf85af66df
	Issue introduced in 6.18.18 with commit af782cc8871e3683ddd5a3cd2f7df526599863a9 and fixed in 6.18.38 with commit c3ca2631073b2cef06824fd2bfc452ff7a1023de
	Issue introduced in 7.0 with commit a0b7091c4de45a7325c8780e6934a894f92ac86b and fixed in 7.1.3 with commit 5e34fa9f6f7cd688ae153fff13139a5cf2d42339
	Issue introduced in 7.0 with commit a0b7091c4de45a7325c8780e6934a894f92ac86b and fixed in 7.2-rc1 with commit 6f060496d03e4dc560a40f73770bd08335cb7a27
	Issue introduced in 5.10.253 with commit 3b8e77c7abab40e6de9ad9de730d77984a498840
	Issue introduced in 5.15.203 with commit d9d8560b9b7932f8cffc4c068c14289220900f79
	Issue introduced in 6.19.8 with commit 763e838adc3c7ec5a7df2990ce84cad951e42721

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-2026-63827

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/apparmor/include/policy_unpack.h
security/apparmor/policy.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/a7a2890028f16e5b0af0bb005d80fcb32559cca3
	https://git.kernel.org/stable/c/15fd83a1e42ede15070968806bb6c8b1a5170688
	https://git.kernel.org/stable/c/ce261a20b41db522e320a41bbf1292bf85af66df
	https://git.kernel.org/stable/c/c3ca2631073b2cef06824fd2bfc452ff7a1023de
	https://git.kernel.org/stable/c/5e34fa9f6f7cd688ae153fff13139a5cf2d42339
	https://git.kernel.org/stable/c/6f060496d03e4dc560a40f73770bd08335cb7a27