Linux Security Modules development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: linux-security-module@vger.kernel.org
Subject: Re: [PATCH] apparmor: don't sleep in unix peer checks for path sockets
Date: Sat, 21 Nov 2026 21:42:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-227419@kernel.org> (raw)
In-Reply-To: <20261121-apparmor-unix-peer-v1-1-99dd1cdb1e27@gmail.com>

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@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

      reply	other threads:[~2026-11-21 21:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 21:29 [PATCH] apparmor: don't sleep in unix peer checks for path sockets Arun Iyengar via B4 Relay
2026-11-21 21:42 ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-227419@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox