From: "Serge E. Hallyn" <serge@hallyn.com>
To: Kees Cook <keescook@chromium.org>
Cc: Paul Moore <paul@paul-moore.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
linux-security-module@vger.kernel.org,
Mimi Zohar <zohar@linux.ibm.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] LoadPin: Ignore the "contents" argument of the LSM hooks
Date: Mon, 12 Dec 2022 15:13:19 -0600 [thread overview]
Message-ID: <20221212211319.GA15511@mail.hallyn.com> (raw)
In-Reply-To: <20221209195453.never.494-kees@kernel.org>
On Fri, Dec 09, 2022 at 11:54:57AM -0800, Kees Cook wrote:
> LoadPin only enforces the read-only origin of kernel file reads. Whether
> or not it was a partial read isn't important. Remove the overly
> conservative checks so that things like partial firmware reads will
> succeed (i.e. reading a firmware header).
>
> Fixes: 2039bda1fa8d ("LSM: Add "contents" flag to kernel_read_file hook")
> Cc: Paul Moore <paul@paul-moore.com>
> Cc: James Morris <jmorris@namei.org>
> Cc: "Serge E. Hallyn" <serge@hallyn.com>
Acked-by: Serge Hallyn <serge@hallyn.com>
Seems reasonable.
So the patch which introduced this was
2039bda1f: LSM: Add "contents" flag to kernel_read_file hook
It sounds like the usage of @contents which it added to ima still
makes sense. But what about the selinux_kernel_read_file() one?
> Cc: linux-security-module@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> security/loadpin/loadpin.c | 30 ++++++++++++++++++------------
> 1 file changed, 18 insertions(+), 12 deletions(-)
>
> diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c
> index de41621f4998..110a5ab2b46b 100644
> --- a/security/loadpin/loadpin.c
> +++ b/security/loadpin/loadpin.c
> @@ -122,21 +122,11 @@ static void loadpin_sb_free_security(struct super_block *mnt_sb)
> }
> }
>
> -static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
> - bool contents)
> +static int loadpin_check(struct file *file, enum kernel_read_file_id id)
> {
> struct super_block *load_root;
> const char *origin = kernel_read_file_id_str(id);
>
> - /*
> - * If we will not know that we'll be seeing the full contents
> - * then we cannot trust a load will be complete and unchanged
> - * off disk. Treat all contents=false hooks as if there were
> - * no associated file struct.
> - */
> - if (!contents)
> - file = NULL;
> -
> /* If the file id is excluded, ignore the pinning. */
> if ((unsigned int)id < ARRAY_SIZE(ignore_read_file_id) &&
> ignore_read_file_id[id]) {
> @@ -192,9 +182,25 @@ static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
> return 0;
> }
>
> +static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
> + bool contents)
> +{
> + /*
> + * LoadPin only cares about the _origin_ of a file, not its
> + * contents, so we can ignore the "are full contents available"
> + * argument here.
> + */
> + return loadpin_check(file, id);
> +}
> +
> static int loadpin_load_data(enum kernel_load_data_id id, bool contents)
> {
> - return loadpin_read_file(NULL, (enum kernel_read_file_id) id, contents);
> + /*
> + * LoadPin only cares about the _origin_ of a file, not its
> + * contents, so a NULL file is passed, and we can ignore the
> + * state of "contents".
> + */
> + return loadpin_check(NULL, (enum kernel_read_file_id) id);
> }
>
> static struct security_hook_list loadpin_hooks[] __lsm_ro_after_init = {
> --
> 2.34.1
next prev parent reply other threads:[~2022-12-12 21:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-09 19:54 [PATCH] LoadPin: Ignore the "contents" argument of the LSM hooks Kees Cook
2022-12-12 21:13 ` Serge E. Hallyn [this message]
2022-12-14 4:06 ` Kees Cook
2022-12-15 20:16 ` Paul Moore
2022-12-14 4:06 ` Kees Cook
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=20221212211319.GA15511@mail.hallyn.com \
--to=serge@hallyn.com \
--cc=gregkh@linuxfoundation.org \
--cc=jmorris@namei.org \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--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;
as well as URLs for NNTP newsgroup(s).