apparmor: fix PROFILE_MEDIATES for untrusted input
authorJohn Johansen <john.johansen@canonical.com>
Sun, 26 May 2019 13:42:23 +0000 (06:42 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 25 Jun 2019 03:35:54 +0000 (11:35 +0800)
commiteb2b0bf5c4a4afc4a761550af1da7da8444803b8
treebaf0596e21d15c592547a02168159663263051d3
parent1d08fe254fd6c6dc4b18d2390ed0d02eb2be85bb
apparmor: fix PROFILE_MEDIATES for untrusted input

commit 23375b13f98c5464c2b4d15f983cc062940f1f4e upstream.

While commit 11c236b89d7c2 ("apparmor: add a default null dfa") ensure
every profile has a policy.dfa it does not resize the policy.start[]
to have entries for every possible start value. Which means
PROFILE_MEDIATES is not safe to use on untrusted input. Unforunately
commit b9590ad4c4f2 ("apparmor: remove POLICY_MEDIATES_SAFE") did not
take into account the start value usage.

The input string in profile_query_cb() is user controlled and is not
properly checked to be within the limited start[] entries, even worse
it can't be as userspace policy is allowed to make us of entries types
the kernel does not know about. This mean usespace can currently cause
the kernel to access memory up to 240 entries beyond the start array
bounds.

Cc: stable@vger.kernel.org
Fixes: b9590ad4c4f2 ("apparmor: remove POLICY_MEDIATES_SAFE")
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
security/apparmor/include/policy.h