[PATCH] security: apparmor: Fix a possible sleep-in-atomic-context bug in find_attach()

Jia-Ju Bai baijiaju1990 at gmail.com
Tue Dec 17 13:12:20 UTC 2019


The kernel may sleep while holding a RCU lock.
The function call path (from bottom to top) in Linux 4.19 is:

security/apparmor/domain.c, 331: 
	vfs_getxattr_alloc(GFP_KERNEL) in aa_xattrs_match
security/apparmor/domain.c, 425: 
	aa_xattrs_match in __attach_match
security/apparmor/domain.c, 485: 
	__attach_match in find_attach
security/apparmor/domain.c, 484:
    rcu_read_lock in find_attach

vfs_getxattr_alloc(GFP_KERNEL) can sleep at runtime.

To fix this possible bug, GFP_KERNEL is replaced with GFP_ATOMIC for
vfs_getxattr_alloc().

This bug is found by a static analysis tool STCheck written by myself. 

Signed-off-by: Jia-Ju Bai <baijiaju1990 at gmail.com>
---
 security/apparmor/domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c
index 9be7ccb8379e..60b54ce57d1f 100644
--- a/security/apparmor/domain.c
+++ b/security/apparmor/domain.c
@@ -325,7 +325,7 @@ static int aa_xattrs_match(const struct linux_binprm *bprm,
 
 	for (i = 0; i < profile->xattr_count; i++) {
 		size = vfs_getxattr_alloc(d, profile->xattrs[i], &value,
-					  value_size, GFP_KERNEL);
+					  value_size, GFP_ATOMIC);
 		if (size >= 0) {
 			u32 perm;
 
-- 
2.17.1



More information about the Linux-security-module-archive mailing list