LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Casey Schaufler <casey@schaufler-ca.com>
To: Mimi Zohar <zohar@linux.vnet.ibm.com>, linux-integrity@vger.kernel.org
Cc: linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org, David Howells <dhowells@redhat.com>,
	"Luis R . Rodriguez" <mcgrof@kernel.org>,
	Eric Biederman <ebiederm@xmission.com>,
	kexec@lists.infradead.org, Andres Rodriguez <andresx7@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH v2 3/9] security: define security_kernel_read_blob() wrapper
Date: Thu, 17 May 2018 17:24:36 -0700	[thread overview]
Message-ID: <74c096ca-1ad1-799e-df3d-7b1b099333a7@schaufler-ca.com> (raw)
In-Reply-To: <1526568530-9144-4-git-send-email-zohar@linux.vnet.ibm.com>

On 5/17/2018 7:48 AM, Mimi Zohar wrote:
> In order for LSMs and IMA-appraisal to differentiate between the original
> and new syscalls (eg. kexec, kernel modules, firmware), both the original
> and new syscalls must call an LSM hook.
>
> Commit 2e72d51b4ac3 ("security: introduce kernel_module_from_file hook")
> introduced calling security_kernel_module_from_file() in both the original
> and new syscalls.  Commit a1db74209483 ("module: replace
> copy_module_from_fd with kernel version") replaced these LSM calls with
> security_kernel_read_file().
>
> Commit e40ba6d56b41 ("firmware: replace call to fw_read_file_contents()
> with kernel version") and commit b804defe4297  ("kexec: replace call to
> copy_file_from_fd() with kernel version") replaced their own version of
> reading a file from the kernel with the generic
> kernel_read_file_from_path/fd() versions, which call the pre and post
> security_kernel_read_file LSM hooks.
>
> Missing are LSM calls in the original kexec syscall and firmware sysfs
> fallback method.  From a technical perspective there is no justification
> for defining a new LSM hook, as the existing security_kernel_read_file()
> works just fine.  The original syscalls, however, do not read a file, so
> the security hook name is inappropriate.  Instead of defining a new LSM
> hook, this patch defines security_kernel_read_blob() as a wrapper for
> the existing LSM security_kernel_file_read() hook.

What a marvelous opportunity to bikeshed!

I really dislike adding another security_ interface just because
the name isn't quite right. Especially a wrapper, which is just
code and execution overhead. Why not change security_kernel_read_file()
to security_kernel_read_blob() everywhere and be done?

>
> Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
> Cc: Eric Biederman <ebiederm@xmission.com>
> Cc: Luis R. Rodriguez <mcgrof@kernel.org>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: David Howells <dhowells@redhat.com>
> Cc: Casey Schaufler <casey@schaufler-ca.com>
>
> Changelog v2:
> - Define a generic wrapper named security_kernel_read_blob() for
> security_kernel_read_file().
>
> Changelog v1:
> - Define and call security_kexec_load(), a wrapper for
> security_kernel_read_file().
> ---
>  include/linux/security.h | 6 ++++++
>  security/security.c      | 6 ++++++
>  2 files changed, 12 insertions(+)
>
> diff --git a/include/linux/security.h b/include/linux/security.h
> index 63030c85ee19..4db1967a688b 100644
> --- a/include/linux/security.h
> +++ b/include/linux/security.h
> @@ -323,6 +323,7 @@ int security_kernel_module_request(char *kmod_name);
>  int security_kernel_read_file(struct file *file, enum kernel_read_file_id id);
>  int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
>  				   enum kernel_read_file_id id);
> +int security_kernel_read_blob(enum kernel_read_file_id id);
>  int security_task_fix_setuid(struct cred *new, const struct cred *old,
>  			     int flags);
>  int security_task_setpgid(struct task_struct *p, pid_t pgid);
> @@ -922,6 +923,11 @@ static inline int security_kernel_post_read_file(struct file *file,
>  	return 0;
>  }
>  
> +static inline int security_kernel_read_blob(enum kernel_read_file_id id)
> +{
> +	return 0;
> +}
> +
>  static inline int security_task_fix_setuid(struct cred *new,
>  					   const struct cred *old,
>  					   int flags)
> diff --git a/security/security.c b/security/security.c
> index 68f46d849abe..8f199b2bf4a2 100644
> --- a/security/security.c
> +++ b/security/security.c
> @@ -1044,6 +1044,12 @@ int security_kernel_read_file(struct file *file, enum kernel_read_file_id id)
>  }
>  EXPORT_SYMBOL_GPL(security_kernel_read_file);
>  
> +int security_kernel_read_blob(enum kernel_read_file_id id)
> +{
> +	return security_kernel_read_file(NULL, id);
> +}
> +EXPORT_SYMBOL_GPL(security_kernel_read_blob);
> +
>  int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
>  				   enum kernel_read_file_id id)
>  {

  reply	other threads:[~2018-05-18  0:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-17 14:48 [PATCH v2 0/9] kexec/firmware: support system wide policy requiring signatures Mimi Zohar
2018-05-17 14:48 ` [PATCH v2 1/9] ima: based on policy verify firmware signatures (pre-allocated buffer) Mimi Zohar
2018-05-17 14:48 ` [PATCH v2 2/9] ima: fix updating the ima_appraise flag Mimi Zohar
2018-05-17 14:48 ` [PATCH v2 3/9] security: define security_kernel_read_blob() wrapper Mimi Zohar
2018-05-18  0:24   ` Casey Schaufler [this message]
2018-05-18  3:37     ` Eric W. Biederman
2018-05-18 11:30       ` Mimi Zohar
2018-05-18 14:58         ` Casey Schaufler
2018-05-18 15:29           ` Mimi Zohar
2018-05-18 17:13       ` James Morris
2018-05-18 17:55         ` Mimi Zohar
2018-05-17 14:48 ` [PATCH v2 4/9] kexec: add call to LSM hook in original kexec_load syscall Mimi Zohar
2018-05-17 14:48 ` [PATCH v2 5/9] ima: based on policy require signed kexec kernel images Mimi Zohar
2018-05-17 14:48 ` [PATCH v2 6/9] firmware: add call to LSM hook before firmware sysfs fallback Mimi Zohar
2018-05-17 14:48 ` [PATCH v2 7/9] ima: based on policy require signed firmware (sysfs fallback) Mimi Zohar
2018-05-17 14:48 ` [PATCH v2 8/9] ima: add build time policy Mimi Zohar
2018-05-17 14:48 ` [PATCH v2 9/9] ima: based on policy prevent loading firmware (pre-allocated buffer) Mimi Zohar

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=74c096ca-1ad1-799e-df3d-7b1b099333a7@schaufler-ca.com \
    --to=casey@schaufler-ca.com \
    --cc=andresx7@gmail.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=dhowells@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=kexec@lists.infradead.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=zohar@linux.vnet.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).