Skip to content

Commit 1342ad7

Browse files
pchelkin91jrjohansen
authored andcommitted
apparmor: fix possible memory leak in unpack_trans_table
If we fail to unpack the transition table then the table elements which have been already allocated are not freed on error path. unreferenced object 0xffff88802539e000 (size 128): comm "apparmor_parser", pid 903, jiffies 4294914938 (age 35.085s) hex dump (first 32 bytes): 20 73 6f 6d 65 20 6e 61 73 74 79 20 73 74 72 69 some nasty stri 6e 67 20 73 6f 6d 65 20 6e 61 73 74 79 20 73 74 ng some nasty st backtrace: [<ffffffff81ddb312>] __kmem_cache_alloc_node+0x1e2/0x2d0 [<ffffffff81c47194>] __kmalloc_node_track_caller+0x54/0x170 [<ffffffff81c225b9>] kmemdup+0x29/0x60 [<ffffffff83e1ee65>] aa_unpack_strdup+0xe5/0x1b0 [<ffffffff83e20808>] unpack_pdb+0xeb8/0x2700 [<ffffffff83e23567>] unpack_profile+0x1507/0x4a30 [<ffffffff83e27bfa>] aa_unpack+0x36a/0x1560 [<ffffffff83e194c3>] aa_replace_profiles+0x213/0x33c0 [<ffffffff83de9461>] policy_update+0x261/0x370 [<ffffffff83de978e>] profile_replace+0x20e/0x2a0 [<ffffffff81eac8bf>] vfs_write+0x2af/0xe00 [<ffffffff81eaddd6>] ksys_write+0x126/0x250 [<ffffffff88f34fb6>] do_syscall_64+0x46/0xf0 [<ffffffff890000ea>] entry_SYSCALL_64_after_hwframe+0x6e/0x76 Call aa_free_str_table() on error path as was done before the blamed commit. It implements all necessary checks, frees str_table if it is available and nullifies the pointers. Found by Linux Verification Center (linuxtesting.org). Fixes: a0792e2 ("apparmor: make transition table unpack generic so it can be reused") Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru> Signed-off-by: John Johansen <john.johansen@canonical.com>
1 parent 1af5aa8 commit 1342ad7

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

security/apparmor/lib.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void aa_free_str_table(struct aa_str_table *t)
4141
kfree_sensitive(t->table[i]);
4242
kfree_sensitive(t->table);
4343
t->table = NULL;
44+
t->size = 0;
4445
}
4546
}
4647

security/apparmor/policy_unpack.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ static bool unpack_trans_table(struct aa_ext *e, struct aa_str_table *strs)
478478
if (!table)
479479
goto fail;
480480

481+
strs->table = table;
482+
strs->size = size;
481483
for (i = 0; i < size; i++) {
482484
char *str;
483485
int c, j, pos, size2 = aa_unpack_strdup(e, &str, NULL);
@@ -520,14 +522,11 @@ static bool unpack_trans_table(struct aa_ext *e, struct aa_str_table *strs)
520522
goto fail;
521523
if (!aa_unpack_nameX(e, AA_STRUCTEND, NULL))
522524
goto fail;
523-
524-
strs->table = table;
525-
strs->size = size;
526525
}
527526
return true;
528527

529528
fail:
530-
kfree_sensitive(table);
529+
aa_free_str_table(strs);
531530
e->pos = saved_pos;
532531
return false;
533532
}

0 commit comments

Comments
 (0)