1
From 5d05f2909c12f6f03581bca9c1fa52dafa10fb0f Mon Sep 17 00:00:00 2001
2
From: John Johansen <john.johansen@canonical.com>
3
Date: Wed, 10 Aug 2011 22:02:41 -0700
4
Subject: [PATCH 3/3] AppArmor: Allow dfa backward compatibility with broken
7
The apparmor_parser when compiling policy could generate invalid dfas
8
that did not have sufficient padding to avoid invalid references, when
9
used by the kernel. The kernels check to verify the next/check table
10
size was broken meaning invalid dfas were being created by userspace
13
To remain compatible with old tools that are not fixed, pad the loaded
14
dfas next/check table. The dfa's themselves are valid except for the
15
high padding for potentially invalid transitions (high bounds error),
16
which have a maximimum is 256 entries. So just allocate an extra null filled
17
256 entries for the next/check tables. This will guarentee all bounds
18
are good and invalid transitions go to the null (0) state.
20
Signed-off-by: John Johansen <john.johansen@canonical.com>
22
security/apparmor/match.c | 17 +++++++++++++++++
23
1 file changed, 17 insertions(+)
25
diff --git a/security/apparmor/match.c b/security/apparmor/match.c
26
index 94de6b4..081491e 100644
27
--- a/security/apparmor/match.c
28
+++ b/security/apparmor/match.c
29
@@ -57,8 +57,17 @@ static struct table_header *unpack_table(char *blob, size_t bsize)
33
+ /* Pad table allocation for next/check by 256 entries to remain
34
+ * backwards compatible with old (buggy) tools and remain safe without
37
+ if (th.td_id == YYTD_ID_NXT || th.td_id == YYTD_ID_CHK)
38
+ tsize += 256 * th.td_flags;
40
table = kvmalloc(tsize);
42
+ /* ensure the pad is clear, else there will be errors */
43
+ memset(table, 0, tsize);
45
if (th.td_flags == YYTD_DATA8)
46
UNPACK_ARRAY(table->td_data, blob, th.td_lolen,
47
@@ -134,11 +143,19 @@ static int verify_dfa(struct aa_dfa *dfa, int flags)
50
if (flags & DFA_FLAG_VERIFY_STATES) {
52
for (i = 0; i < state_count; i++) {
53
if (DEFAULT_TABLE(dfa)[i] >= state_count)
55
/* TODO: do check that DEF state recursion terminates */
56
if (BASE_TABLE(dfa)[i] + 255 >= trans_count) {
59
+ printk(KERN_WARNING "AppArmor DFA next/check "
60
+ "upper bounds error fixed, upgrade "
61
+ "user space tools \n");
63
+ } else if (BASE_TABLE(dfa)[i] >= trans_count) {
64
printk(KERN_ERR "AppArmor DFA next/check upper "