[PATCH] apparmor: don't sleep in unix peer checks for path sockets
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Sat Nov 21 21:42:45 UTC 2026
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] apparmor: unsafe RCU label reference acquisition in
aa_unix_file_perm() [1]
--
commit effda5eb5a50afb4aa0bf1fcfad7c08d47306526
Author: Arun Iyengar <aiyengar1990 at gmail.com>
apparmor: don't sleep in unix peer checks for path sockets
This commit passes an in_atomic parameter through unix_fs_perm() to
aa_path_perm() so that unix peer checks performed under unix_state_lock()
allocate buffers without sleeping.
> diff --git a/security/apparmor/af_unix.c b/security/apparmor/af_unix.c
> index 58c638830afc4..ff851ddd43b44 100644
> --- a/security/apparmor/af_unix.c
> +++ b/security/apparmor/af_unix.c
[ ... ]
> @@ -775,7 +776,7 @@ int aa_unix_file_perm(const struct cred *subj_cred, struct aa_label *label,
>
> last_error(error,
> unix_fs_perm(op, request, subj_cred, label,
> - &peer_path));
> + &peer_path, false));
> if (peer_path.dentry)
> path_put(&peer_path);
> } else {
[Severity: Critical]
This problem wasn't introduced by this patch, but in the else branch right
below, can passing pctx->label directly to aa_get_newest_label() cause a
use-after-free [1]?
security/apparmor/af_unix.c:aa_unix_file_perm() {
...
} else {
struct aa_sk_ctx *pctx = aa_sock(peer_sk);
rcu_read_lock();
plabel = aa_get_newest_label(pctx->label);
rcu_read_unlock();
...
}
aa_get_newest_label() assumes the caller already holds a reference to the
label and calls aa_get_label() (an unconditional kref_get()) when
label_is_stale() is false. Because pctx->label is only RCU-protected here,
a concurrent profile update and socket label update can drop its refcount
to zero before kref_get() runs:
CPU0 CPU1
aa_unix_file_perm()
rcu_read_lock()
aa_get_newest_label(pctx->label)
label_is_stale(l) -> false
__aa_proxy_redirect()
l->flags |= FLAG_STALE
aa_put_label(l)
update_sk_ctx()
aa_put_label(sk_ctx->label)
/* refcount reaches 0 */
aa_get_label(l)
kref_get() <-- refcount addition on zero
rcu_read_unlock()
/* plabel used after RCU grace period <-- use-after-free */
Should this use aa_get_newest_rcu_label(&pctx->label) instead?
[1] https://sashiko.dev/#/bug/linux-43381a05-e5da-4626-9e59-010765c6af53
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121-apparmor-unix-peer-v1-1-99dd1cdb1e27@gmail.com?part=1
More information about the Linux-security-module-archive
mailing list