linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Fan Wu <wufan@linux.microsoft.com>
Cc: corbet@lwn.net, zohar@linux.ibm.com, jmorris@namei.org,
	serge@hallyn.com, tytso@mit.edu, axboe@kernel.dk, agk@redhat.com,
	snitzer@kernel.org, mpatocka@redhat.com, eparis@redhat.com,
	paul@paul-moore.com, linux-doc@vger.kernel.org,
	linux-integrity@vger.kernel.org,
	linux-security-module@vger.kernel.org, fsverity@lists.linux.dev,
	linux-block@vger.kernel.org, dm-devel@lists.linux.dev,
	audit@vger.kernel.org, linux-kernel@vger.kernel.org,
	Deven Bowers <deven.desai@linux.microsoft.com>
Subject: Re: [PATCH v19 11/20] block,lsm: add LSM blob and new LSM hooks for block device
Date: Fri, 31 May 2024 20:48:42 +0000	[thread overview]
Message-ID: <20240531204842.GA2838215@google.com> (raw)
In-Reply-To: <1716583609-21790-12-git-send-email-wufan@linux.microsoft.com>

On Fri, May 24, 2024 at 01:46:40PM -0700, Fan Wu wrote:
> From: Deven Bowers <deven.desai@linux.microsoft.com>
> 
> Some block devices have valuable security properties that is only
> accessible during the creation time.
>
> For example, when creating a dm-verity block device, the dm-verity's
> roothash and roothash signature, which are extreme important security
> metadata, are passed to the kernel. However, the roothash will be saved
> privately in dm-verity, which prevents the security subsystem to easily
> access that information. Worse, in the current implementation the
> roothash signature will be discarded after the verification, making it
> impossible to utilize the roothash signature by the security subsystem.

This patch seems to be assuming that creating the block device == setting up
dm-verity.  That's not how it actually works.  The way that device-mapper works
is that first a device-mapper device is created, and then targets are loaded
into it.  The targets can be changed later, any number of times.

So, while the creation of the block device is when the LSM blob is allocated,
it's not when the actual contents of it are initialized.  And its contents can
vary over the lifetime of the block device, including changing from something
the LSM "trusts" to something it doesn't "trust".

I'm not sure if this is "just" a documentation issue or if there are bugs
resulting from not handling changes properly.  The code itself *looks* correct,
but seeing it's not clear how much this has been considered and that getting
this wrong would allow the LSM checks to be bypassed, I thought I'd draw
attention to it.  This is really something that ought to be called out
explicitly in comments, for example.

> For example, LSM can use the new LSM blob to save the roothash signature of a
> dm-verity, and LSM can make access decision based on the data inside the
> signature, like the signer certificate.

This isn't what IPE actually does, though.  So this doesn't seem like a
particularly useful example in this context.

> For example, for dm-verity, LSMs can use this hook to save
> the roothash signature of a dm-verity into the security blob,
> and LSMs can make access decisions based on the data inside
> the signature, like the signer certificate.

Likewise.

> diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
> index 781c4500491b..eaa28f366d98 100644
> --- a/include/linux/blk_types.h
> +++ b/include/linux/blk_types.h
> @@ -71,6 +71,9 @@ struct block_device {
>  
>  	struct partition_meta_info *bd_meta_info;
>  	int			bd_writers;
> +#ifdef CONFIG_SECURITY
> +	void			*security;
> +#endif

All the other fields in struct block_device are prefixed with "bd_", so please
use the same pattern for this new field (bd_security).

> diff --git a/security/security.c b/security/security.c
> index b419166979da..743652e5e893 100644
> --- a/security/security.c
> +++ b/security/security.c
[...]
> +/**
> + * security_bdev_setintegrity() - Set the device's integrity data
> + * @bdev: block device
> + * @type: type of integrity, e.g. hash digest, signature, etc
> + * @value: the integrity value
> + * @size: size of the integrity value
> + *
> + * Register a verified integrity measurement of a bdev with LSMs.
> + * LSMs should free the previously saved data if @value is NULL.
> + *
> + * Return: Returns 0 on success, negative values on failure.
> + */
> +int security_bdev_setintegrity(struct block_device *bdev,
> +			       enum lsm_integrity_type type, const void *value,
> +			       size_t size)
> +{
> +	return call_int_hook(bdev_setintegrity, bdev, type, value, size);
> +}
> +EXPORT_SYMBOL(security_bdev_setintegrity);

This might be a good place to explicitly document that the block device's
integrity properties may change over the lifetime of the block device and that
LSMs *must* (not "should") handle all possible types of updates, including
updates from a non-NULL value of a property to a NULL value.

- Eric

  reply	other threads:[~2024-05-31 20:48 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-24 20:46 [PATCH v19 00/20] Integrity Policy Enforcement LSM (IPE) Fan Wu
2024-05-24 20:46 ` [PATCH v19 01/20] security: add ipe lsm Fan Wu
2024-05-24 20:46 ` [PATCH v19 02/20] ipe: add policy parser Fan Wu
2024-05-24 20:46 ` [PATCH v19 03/20] ipe: add evaluation loop Fan Wu
2024-05-24 20:46 ` [PATCH v19 04/20] ipe: add LSM hooks on execution and kernel read Fan Wu
2024-05-24 20:46 ` [PATCH v19 05/20] initramfs|security: Add a security hook to do_populate_rootfs() Fan Wu
2024-05-24 20:46 ` [PATCH v19 06/20] ipe: introduce 'boot_verified' as a trust provider Fan Wu
2024-05-24 20:46 ` [PATCH v19 07/20] security: add new securityfs delete function Fan Wu
2024-05-24 20:46 ` [PATCH v19 08/20] ipe: add userspace interface Fan Wu
2024-05-24 20:46 ` [PATCH v19 09/20] uapi|audit|ipe: add ipe auditing support Fan Wu
2024-05-24 20:46 ` [PATCH v19 10/20] ipe: add permissive toggle Fan Wu
2024-05-24 20:46 ` [PATCH v19 11/20] block,lsm: add LSM blob and new LSM hooks for block device Fan Wu
2024-05-31 20:48   ` Eric Biggers [this message]
2024-05-24 20:46 ` [PATCH v19 12/20] dm verity: expose root hash digest and signature data to LSMs Fan Wu
2024-05-25  9:02   ` Mikulas Patocka
2024-05-31 21:07   ` Eric Biggers
2024-05-24 20:46 ` [PATCH v19 13/20] ipe: add support for dm-verity as a trust provider Fan Wu
2024-05-30  1:44   ` Paul Moore
2024-05-30  3:58     ` Fan Wu
2024-05-30  5:53       ` Jarkko Sakkinen
2024-05-30  5:49     ` Jarkko Sakkinen
2024-05-24 20:46 ` [PATCH v19 14/20] security: add security_inode_setintegrity() hook Fan Wu
2024-05-24 20:46 ` [PATCH v19 15/20] fsverity: expose verified fsverity built-in signatures to LSMs Fan Wu
2024-05-30  1:44   ` Paul Moore
2024-05-30  5:51     ` Jarkko Sakkinen
2024-05-30  6:01       ` Eric Biggers
2024-05-30  6:07         ` Jarkko Sakkinen
2024-05-30  1:46   ` Paul Moore
2024-05-30  3:06     ` Eric Biggers
2024-05-30  3:38       ` Fan Wu
2024-05-30 20:54       ` Paul Moore
2024-05-31  0:43         ` Eric Biggers
2024-05-31 15:51           ` Paul Moore
2024-05-31 17:47             ` Eric Biggers
2024-06-03  1:40               ` Paul Moore
2024-05-24 20:46 ` [PATCH v19 16/20] ipe: enable support for fs-verity as a trust provider Fan Wu
2024-05-24 20:46 ` [PATCH v19 17/20] scripts: add boot policy generation program Fan Wu
2024-05-24 20:46 ` [PATCH v19 18/20] ipe: kunit test for parser Fan Wu
2024-05-24 20:46 ` [PATCH v19 19/20] Documentation: add ipe documentation Fan Wu
2024-05-24 20:46 ` [PATCH v19 20/20] MAINTAINERS: ipe: add ipe maintainer information Fan Wu

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=20240531204842.GA2838215@google.com \
    --to=ebiggers@kernel.org \
    --cc=agk@redhat.com \
    --cc=audit@vger.kernel.org \
    --cc=axboe@kernel.dk \
    --cc=corbet@lwn.net \
    --cc=deven.desai@linux.microsoft.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=eparis@redhat.com \
    --cc=fsverity@lists.linux.dev \
    --cc=jmorris@namei.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=serge@hallyn.com \
    --cc=snitzer@kernel.org \
    --cc=tytso@mit.edu \
    --cc=wufan@linux.microsoft.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).