All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: selinux@vger.kernel.org
Subject: Re: [PATCH 2/2] selinux: check FILE__MAP when rechecking remapped backing files
Date: Fri, 04 Dec 2026 20:57:54 +0000	[thread overview]
Message-ID: <sashiko-outbox-250645@kernel.org> (raw)
In-Reply-To: <20261204204354.18371-3-stephen.smalley.work@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] selinux: missing parentheses on if map in
  selinux_backing_file_recheck()
- [Low] selinux: duplicate FD__USE checks in
  selinux_backing_file_recheck()
--

commit d93cc885d4fd9bb55b9bed3112dd35ed2093c015
Author: Stephen Smalley <stephen.smalley.work@gmail.com>

selinux: check FILE__MAP when rechecking remapped backing files

This commit adds a map argument to selinux_backing_file_recheck() so that
remap_file_pages() checks FILE__MAP on the user-visible file, saved
mounter layers, and the lowest backing file, while mprotect() keeps its
existing checks.

Link: https://lore.kernel.org/lkml/CAEjxPJ5tOwBfXpqbb_pFkjtHGtrHYL_idAj=es9QDGE1qPLDBA@mail.gmail.com/#r

> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index c19ad72727062..f68a4a345345a 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -4149,22 +4149,43 @@ static inline int file_map_prot_check(const struct file *file,

[ ... ]

>  static int selinux_backing_file_recheck(const struct file *file,
> -					unsigned long prot, bool shared)
> +					unsigned long prot, bool shared,
> +					bool map)
>  {
> +	u32 av = file_map_prot_to_av(prot, shared);
>  	int rc;
>  
> +	/* the user-visible file with the caller's credentials */
> +	if (map) {
> +		rc = __file_has_perm(current_cred(), file, FILE__MAP, true);
> +		if (rc)
> +			return rc;
> +	}
>  	rc = __file_map_prot_check(file, prot, shared, false, true);
>  	if (rc)
>  		return rc;
>  
> -	rc = backing_mounters_has_perm(file, file_map_prot_to_av(prot, shared));
> +	/* every saved intermediate layer with its mounter's credentials */
> +	if map
> +		av |= FILE__MAP;

[Severity: High]
Are parentheses missing around map here?  Without them, "if map" fails to
compile when CONFIG_SECURITY_SELINUX is enabled.

> +	rc = backing_mounters_has_perm(file, av);
>  	if (rc)
>  		return rc;
>  
> +	/* the backing file itself with its mounter's credentials */
> +	if (map) {
> +		rc = file_has_perm(file->f_cred, file, FILE__MAP);
> +		if (rc)
> +			return rc;
> +	}
>  	return file_map_prot_check(file, prot, shared, true);
>  }

[Severity: Low]
Does calling __file_has_perm() before __file_map_prot_check() on the
user-visible file, and file_has_perm() before file_map_prot_check() on
the lowest backing file, evaluate FD__USE twice on each file?

Both __file_has_perm() and __file_map_prot_check() check FD__USE via
avc_has_perm() (and call bpf_fd_pass()).  During remap_file_pages(),
when the subject SID differs from the fd SID (such as after a domain
transition), this emits duplicate granted audit records under auditallow.

It also checks FD__USE before FILE__MAP, reversing the ordering used by
selinux_mmap_file_common().  Checking FILE__MAP with inode_has_perm() to
match selinux_mmap_file_common(), or folding FILE__MAP into a single
__file_has_perm() call, would avoid the duplicate checks.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204204354.18371-2-stephen.smalley.work@gmail.com?part=2

  reply	other threads:[~2026-12-04 20:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 20:43 [PATCH 1/2] selinux: recheck backing files on remap_file_pages() Stephen Smalley
2026-12-04 20:43 ` [PATCH 2/2] selinux: check FILE__MAP when rechecking remapped backing files Stephen Smalley
2026-12-04 20:57   ` sashiko-bot [this message]
2026-12-04 21:00 ` [PATCH 1/2] selinux: recheck backing files on remap_file_pages() sashiko-bot

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-250645@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=selinux@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.