summaryrefslogtreecommitdiff
path: root/scripts/basic
diff options
context:
space:
mode:
authorCen Zhang (Microsoft) <cenzhang@linux.microsoft.com>2026-10-12 17:57:03 -0400
committerJohn Johansen <john.johansen@canonical.com>2026-10-29 09:25:25 -0700
commitd30844001360a403a511cf24fc75ecaa6a7a7544 (patch)
tree8d6cb9b93fb1f41e8bb972442411e2197c721d7a /scripts/basic
parent35b8ab3f36ac0fcd8fc910da0bed889b6c75c426 (diff)
downloadlinux-d30844001360a403a511cf24fc75ecaa6a7a7544.tar.gz
linux-d30844001360a403a511cf24fc75ecaa6a7a7544.zip
apparmor: fix query_data() output overlapping the lookup key
In query_data(), buf and query point into the same multi_transaction buffer: buf at the start, query a few bytes in, and the lookup key right after the label string that query points to. Reusing the buffer is by design and is safe as long as the query is fully parsed before buf is written to, but the key is not: it is dereferenced on every iteration of label_for_each_confined(), after output has already been written. So when the label has more than one profile with a data table, the data of the first matching profile is written to buf while the key is still needed, and overwrites it if the data is large enough. The later lookups then run on a corrupted key. Besides, if the data has no NUL byte from the key's position to the end of the allocation, strhash() -> strlen() -> jhash() reads past the 4096-byte slab object, triggering an out-of-bound read: BUG: KASAN: slab-out-of-bounds in jhash+0x595/0x5e0 Read of size 1 at addr ff1100001159d000 by task exploit/155 CPU: 0 UID: 1000 PID: 155 Comm: exploit Not tainted 7.3.0-rc7 #1 Call Trace: jhash+0x595/0x5e0 aa_write_access+0x880/0x1400 vfs_write+0x26f/0xd20 ksys_write+0x115/0x210 Writing to the .access file is unprivileged (0666), but triggering this requires loaded profiles that carry a data table, which needs CAP_MAC_ADMIN and is not the case on default distribution policies. Fix by copying the key with kstrdup() before writing any output to buf, so the key stays valid across all loop iterations regardless of what gets written to the overlapping buffer. Fixes: 317d9a054e1c ("apparmor: update query interface to support label queries") Cc: stable@vger.kernel.org # v4.13+ Cc: Francis Perron <francis@akrites.dev> Reported-by: AutonomousCodeSecurity@microsoft.com Signed-off-by: Cen Zhang (Microsoft) <cenzhang@linux.microsoft.com> Signed-off-by: John Johansen <john.johansen@canonical.com>
Diffstat (limited to 'scripts/basic')
0 files changed, 0 insertions, 0 deletions