linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: sergeh@kernel.org
To: Roberto Sassu <roberto.sassu@huaweicloud.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>,
	Kees Cook <kees@kernel.org>, Paul Moore <paul@paul-moore.com>,
	James Morris <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	linux-integrity@vger.kernel.org, zohar@linux.ibm.com
Subject: Re: Credentials not fully initialized before bprm_check LSM hook
Date: Thu, 10 Apr 2025 17:24:08 +0000	[thread overview]
Message-ID: <Z_f-uBGhBq9CYmaw@lei> (raw)
In-Reply-To: <fb9f7900d411a3ab752759d818c3da78e2f8f0f1.camel@huaweicloud.com>

On Thu, Apr 10, 2025 at 01:47:07PM +0200, Roberto Sassu wrote:
> Hi everyone
> 
> recently I discovered a problem in the implementation of our IMA
> bprm_check hook, in particular when the policy is matched against the
> bprm credentials (to be committed later during execve().
> 
> Before commit 56305aa9b6fab ("exec: Compute file based creds only
> once"), bprm_fill_uid() was called in prepare_binprm() and filled the
> euid/egid before calling security_bprm_check(), which in turns calls
> IMA.
> 
> After that commit, bprm_fill_uid() was moved to begin_new_exec(), which
> is when the last interpreter is found.
> 
> The consequence is that IMA still sees the not yet ready credentials
> and an IMA rule like:
> 
> measure func=CREDS_CHECK euid=0

"IMA still sees" at which point exactly?

Do I understand right that the problem is that ima's version of
security_bprm_creds_for_exec() needs to run after
bprm_creds_from_file()?

Given that Eric's commit message said that no bprm handlers use
the uid, it seems it should be safe to just move that?

> will not be matched for sudo-like applications.
> 
> It does work however with SELinux, because it computes the transition
> before IMA in the bprm_creds_for_exec hook.
> 
> Since IMA needs to be involved for each execution in the chain of
> interpreters, we cannot move to the bprm_creds_from_file hook.
> 
> How do we solve this problem? The commit mentioned that it is an
> optimization, so probably would not be too hard to partially revert it
> (and keeping what is good).
> 
> Thanks
> 
> Roberto
> 


  reply	other threads:[~2025-04-10 17:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-10 11:47 Roberto Sassu
2025-04-10 17:24 ` sergeh [this message]
2025-04-11  9:07   ` Roberto Sassu
2025-04-11 22:14     ` Paul Moore

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=Z_f-uBGhBq9CYmaw@lei \
    --to=sergeh@kernel.org \
    --cc=brauner@kernel.org \
    --cc=ebiederm@xmission.com \
    --cc=jmorris@namei.org \
    --cc=kees@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=roberto.sassu@huaweicloud.com \
    --cc=serge@hallyn.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zohar@linux.ibm.com \
    /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