linux/security/apparmor
John Johansen 667df93769 apparmor: fix race between freeing data and fs accessing it
commit 8e135b8aee upstream.

Backport for conflicts introdued by
- conversion from sha1 to sha256 introduced in
   e44a4dc4b3 ("apparmor: switch SECURITY_APPARMOR_HASH from sha1 to sha256
")

- adding of conditioanl that nests the conflicting code inside an if
  condition
  d61c57fde8 ("apparmor: make export of raw binary profile to userspace optional")

AppArmor was putting the reference to i_private data on its end after
removing the original entry from the file system. However the inode
can and does live beyond that point and it is possible that some of
the fs call back functions will be invoked after the reference has
been put, which results in a race between freeing the data and
accessing it through the fs.

While the rawdata/loaddata is the most likely candidate to fail the
race, as it has the fewest references. If properly crafted it might be
possible to trigger a race for the other types stored in i_private.

Fix this by moving the put of i_private referenced data to the correct
place which is during inode eviction.

Fixes: c961ee5f21 ("apparmor: convert from securityfs to apparmorfs for policy ns files")
Reported-by: Qualys Security Advisory <qsa@qualys.com>
Reviewed-by: Georgia Garcia <georgia.garcia@canonical.com>
Reviewed-by: Maxime Bélair <maxime.belair@canonical.com>
Reviewed-by: Cengiz Can <cengiz.can@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-04-18 10:33:36 +02:00
..
include apparmor: fix race between freeing data and fs accessing it 2026-04-18 10:33:36 +02:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
apparmorfs.c apparmor: fix race between freeing data and fs accessing it 2026-04-18 10:33:36 +02:00
audit.c ima: Avoid blocking in RCU read-side critical section 2024-07-18 13:07:34 +02:00
capability.c apparmor: fix 'Do simple duplicate message elimination' 2024-12-14 19:51:11 +01:00
crypto.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 441 2019-06-05 17:37:17 +02:00
domain.c apparmor: fix overlapping attachment computation 2022-08-25 11:40:00 +02:00
file.c apparmor: handle idmapped mounts 2021-01-24 14:27:20 +01:00
ipc.c audit: purge audit_log_string from the intra-kernel audit API 2020-07-21 11:12:31 -04:00
Kconfig Minor fixes for v5.9. 2020-08-11 14:30:36 -07:00
label.c apparmor: fix race between freeing data and fs accessing it 2026-04-18 10:33:36 +02:00
lib.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
lsm.c apparmor: Fix null pointer deref when receiving skb during sock creation 2024-08-19 05:45:25 +02:00
Makefile apparmor: add base infastructure for socket mediation 2018-03-13 17:25:48 -07:00
match.c apparmor: fix differential encoding verification 2026-04-18 10:33:36 +02:00
mount.c apparmor: fix reference count leak in aa_pivotroot() 2022-08-25 11:40:01 +02:00
net.c apparmor: fix NULL sock in aa_sock_file_perm 2026-03-04 07:19:53 -05:00
nulldfa.in apparmor: cleanup add proper line wrapping to nulldfa.in 2018-02-09 11:30:01 -08:00
path.c AppArmor: Remove semicolon 2020-01-18 15:36:58 -08:00
policy.c apparmor: fix race on rawdata dereference 2026-04-18 10:33:36 +02:00
policy_ns.c apparmor: fix: limit the number of levels of policy namespaces 2026-04-18 10:33:36 +02:00
policy_unpack.c apparmor: fix race between freeing data and fs accessing it 2026-04-18 10:33:36 +02:00
policy_unpack_test.c apparmor: test: Fix memory leak for aa_unpack_strdup() 2024-12-14 19:51:14 +01:00
procattr.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 441 2019-06-05 17:37:17 +02:00
resource.c apparmor: fix rlimit for posix cpu timers 2026-03-04 07:19:53 -05:00
secid.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 441 2019-06-05 17:37:17 +02:00
stacksplitdfa.in apparmor: use the dfa to do label parse string splitting 2018-02-09 11:30:01 -08:00
task.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 441 2019-06-05 17:37:17 +02:00