apparmor: fix aa_xattrs_match() may sleep while holding a RCU lock
authorJohn Johansen <john.johansen@canonical.com>
Thu, 2 Jan 2020 13:31:22 +0000 (05:31 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Jan 2020 09:20:00 +0000 (10:20 +0100)
commite0d2bf5a012974c2f718ce41dbff185666eae11f
tree066f24802921bdcb06866592278ab81366f399c5
parent20170bfa3d9a58f788d5b4255c138ded5cefd7a1
apparmor: fix aa_xattrs_match() may sleep while holding a RCU lock

commit 8c62ed27a12c00e3db1c9f04bc0f272bdbb06734 upstream.

aa_xattrs_match() is unfortunately calling vfs_getxattr_alloc() from a
context protected by an rcu_read_lock. This can not be done as
vfs_getxattr_alloc() may sleep regardles of the gfp_t value being
passed to it.

Fix this by breaking the rcu_read_lock on the policy search when the
xattr match feature is requested and restarting the search if a policy
changes occur.

Fixes: 8e51f9087f40 ("apparmor: Add support for attaching profiles via xattr, presence and value")
Reported-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
security/apparmor/apparmorfs.c
security/apparmor/domain.c
security/apparmor/policy.c