linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v2] ima: export the measurement list when needed
       [not found] ` <CAE=NcrZrbRinOAbB+k1rjhcae3nqfJ8snC_EnY8njMDioM7=vg@mail.gmail.com>
@ 2020-02-06 14:13   ` Mimi Zohar
  2020-02-10  8:04     ` Janne Karhunen
  2020-02-10 18:18     ` david.safford
  0 siblings, 2 replies; 12+ messages in thread
From: Mimi Zohar @ 2020-02-06 14:13 UTC (permalink / raw)
  To: Janne Karhunen, linux-integrity, linux-security-module
  Cc: Ken Goldman, david.safford, monty.wiseman, Amir Goldstein, linux-fsdevel

Hi Janne,

On Fri, 2020-01-10 at 10:48 +0200, Janne Karhunen wrote:
> On Wed, Jan 8, 2020 at 1:18 PM Janne Karhunen <janne.karhunen@gmail.com> wrote:
> >
> > Some systems can end up carrying lots of entries in the ima
> > measurement list. Since every entry is using a bit of kernel
> > memory, allow the sysadmin to export the measurement list to
> > the filesystem to free up some memory.
> 
> Hopefully this addressed comments from everyone. The flush event can
> now be triggered by the admin anytime and unique file names can be
> used for each flush (log.1, log.2, ...) etc, so getting to the correct
> item should be easy.
> 
> While it can now be argued that since this is an admin-driven event,
> kernel does not need to write the file. However, the intention is to
> bring out a second patch a bit later that adds a variable to define
> the max number of entries to be kept in the kernel memory and
> workqueue based automatic flushing. In those cases the kernel has to
> be able to write the file without any help from the admin..

The implications of exporting and removing records from the IMA-
measurement list needs to be considered carefully.  Verifying a TPM
quote will become dependent on knowing where the measurements are
stored.  The existing measurement list is stored in kernel memory and,
barring a kernel memory attack, is protected from modification.
 Before upstreaming this or a similar patch, there needs to be a
discussion as to how the measurement list will be protected once is it
exported to userspace.

This patch now attempts to address two very different scenarios.  The
first scenario is where userspace is requesting exporting and removing
of the measurement list records.  The other scenario is the kernel
exporting and removing of the measurement list records.  Conflating
these two different use cases might not be the right solution, as we
originally thought.

The kernel already exports the IMA measurement list to userspace via a
securityfs file.  From a userspace perspective, missing is the ability
of removing N number of records.  In this scenario, userspace would be
responsible for safely storing the measurements (e.g. blockchain).
 The kernel would only be responsible for limiting permission, perhaps
based on a capability, before removing records from the measurement
list. 

In the kernel usecase, somehow the kernel would need to safely export
the measurement list, or some portion of the measurement list, to a
file and then delete that portion.  What protects the exported records
stored in a file from modification?

Instead of exporting the measurement records, one option as suggested
by Amir Goldstein, would be to use a vfs_tmpfile() to get an anonymous
file for backing store.  The existing securityfs measurement lists
would then read from this private copy of the anonymous file.

I've Cc'ed fsdevel for additional comments/suggestions.

thanks,

Mimi


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] ima: export the measurement list when needed
  2020-02-06 14:13   ` [PATCH v2] ima: export the measurement list when needed Mimi Zohar
@ 2020-02-10  8:04     ` Janne Karhunen
  2020-02-10 15:26       ` Mimi Zohar
  2020-02-10 18:18     ` david.safford
  1 sibling, 1 reply; 12+ messages in thread
From: Janne Karhunen @ 2020-02-10  8:04 UTC (permalink / raw)
  To: Mimi Zohar
  Cc: linux-integrity, linux-security-module, Ken Goldman,
	david.safford, Wiseman, Monty (GE Global Research, US),
	Amir Goldstein, linux-fsdevel

On Thu, Feb 6, 2020 at 4:14 PM Mimi Zohar <zohar@linux.ibm.com> wrote:

> The implications of exporting and removing records from the IMA-
> measurement list needs to be considered carefully.  Verifying a TPM
> quote will become dependent on knowing where the measurements are
> stored.  The existing measurement list is stored in kernel memory and,
> barring a kernel memory attack, is protected from modification.
>  Before upstreaming this or a similar patch, there needs to be a
> discussion as to how the measurement list will be protected once is it
> exported to userspace.
>
> This patch now attempts to address two very different scenarios.  The
> first scenario is where userspace is requesting exporting and removing
> of the measurement list records.  The other scenario is the kernel
> exporting and removing of the measurement list records.  Conflating
> these two different use cases might not be the right solution, as we
> originally thought.
>
> The kernel already exports the IMA measurement list to userspace via a
> securityfs file.  From a userspace perspective, missing is the ability
> of removing N number of records.  In this scenario, userspace would be
> responsible for safely storing the measurements (e.g. blockchain).
>  The kernel would only be responsible for limiting permission, perhaps
> based on a capability, before removing records from the measurement
> list.

This is a good point. I will adapt the patch to this.


> In the kernel usecase, somehow the kernel would need to safely export
> the measurement list, or some portion of the measurement list, to a
> file and then delete that portion.  What protects the exported records
> stored in a file from modification?

Are we looking at protecting this file from a root exploit and the
potential DOS it might cause? In the original patch the file was root
writable only. As far as further limitations go, the easiest would
probably be to use the file immutable bit. If the kernel opens the
file and sets the immutable bit, it is the only entity that can ever
write to it - not even another root task could directly write to it.
The kernel could, as long as it keeps the file open.


> Instead of exporting the measurement records, one option as suggested
> by Amir Goldstein, would be to use a vfs_tmpfile() to get an anonymous
> file for backing store.  The existing securityfs measurement lists
> would then read from this private copy of the anonymous file.
>
> I've Cc'ed fsdevel for additional comments/suggestions.

I didn't quickly see what the actual problem is that the vfs_tmpfile
solves in this context, will check.


--
Janne

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] ima: export the measurement list when needed
  2020-02-10  8:04     ` Janne Karhunen
@ 2020-02-10 15:26       ` Mimi Zohar
  0 siblings, 0 replies; 12+ messages in thread
From: Mimi Zohar @ 2020-02-10 15:26 UTC (permalink / raw)
  To: Janne Karhunen
  Cc: linux-integrity, linux-security-module, Ken Goldman,
	david.safford, Wiseman, Monty (GE Global Research, US),
	Amir Goldstein, linux-fsdevel

On Mon, 2020-02-10 at 10:04 +0200, Janne Karhunen wrote:
> On Thu, Feb 6, 2020 at 4:14 PM Mimi Zohar <zohar@linux.ibm.com> wrote:
> 
> > The implications of exporting and removing records from the IMA-
> > measurement list needs to be considered carefully.  Verifying a TPM
> > quote will become dependent on knowing where the measurements are
> > stored.  The existing measurement list is stored in kernel memory and,
> > barring a kernel memory attack, is protected from modification.
> >  Before upstreaming this or a similar patch, there needs to be a
> > discussion as to how the measurement list will be protected once is it
> > exported to userspace.
> >
> > This patch now attempts to address two very different scenarios.  The
> > first scenario is where userspace is requesting exporting and removing
> > of the measurement list records.  The other scenario is the kernel
> > exporting and removing of the measurement list records.  Conflating
> > these two different use cases might not be the right solution, as we
> > originally thought.
> >
> > The kernel already exports the IMA measurement list to userspace via a
> > securityfs file.  From a userspace perspective, missing is the ability
> > of removing N number of records.  In this scenario, userspace would be
> > responsible for safely storing the measurements (e.g. blockchain).
> >  The kernel would only be responsible for limiting permission, perhaps
> > based on a capability, before removing records from the measurement
> > list.
> 
> This is a good point. I will adapt the patch to this.
> 
> 
> > In the kernel usecase, somehow the kernel would need to safely export
> > the measurement list, or some portion of the measurement list, to a
> > file and then delete that portion.  What protects the exported records
> > stored in a file from modification?
> 
> Are we looking at protecting this file from a root exploit and the
> potential DOS it might cause? In the original patch the file was root
> writable only. As far as further limitations go, the easiest would
> probably be to use the file immutable bit. If the kernel opens the
> file and sets the immutable bit, it is the only entity that can ever
> write to it - not even another root task could directly write to it.
> The kernel could, as long as it keeps the file open.

The problem being addressed is freeing kernel memory instead of
letting the measurement list grow unbounded.  One solution is to
remove measurement list records, as you did, but that changes the
existing userspace expectations of returning the entire measurement
list.  In the userspace scenario, removing measurement list records is
the requirement.  For the kernel scenario, I don't think it is a
requirement.

> 
> > Instead of exporting the measurement records, one option as suggested
> > by Amir Goldstein, would be to use a vfs_tmpfile() to get an anonymous
> > file for backing store.  The existing securityfs measurement lists
> > would then read from this private copy of the anonymous file.
> >
> > I've Cc'ed fsdevel for additional comments/suggestions.
> 
> I didn't quickly see what the actual problem is that the vfs_tmpfile
> solves in this context, will check.

The existing IMA measurement list is by design, as coined by George
Wilson, a "deliberate memory leak".  Fixing the "Deliberate IMA event
log memory leak" should be the problem description.  Amir's suggestion
of using a vfs_tmpfile seems like a reasonable solution.

Mimi


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] ima: export the measurement list when needed
  2020-02-06 14:13   ` [PATCH v2] ima: export the measurement list when needed Mimi Zohar
  2020-02-10  8:04     ` Janne Karhunen
@ 2020-02-10 18:18     ` david.safford
  2020-02-10 20:24       ` Mimi Zohar
  1 sibling, 1 reply; 12+ messages in thread
From: david.safford @ 2020-02-10 18:18 UTC (permalink / raw)
  To: Mimi Zohar, Janne Karhunen, linux-integrity, linux-security-module
  Cc: Ken Goldman, monty.wiseman, Amir Goldstein, linux-fsdevel

On Thu, 2020-02-06 at 09:13 -0500, Mimi Zohar wrote:
> Hi Janne,
> 
> On Fri, 2020-01-10 at 10:48 +0200, Janne Karhunen wrote:
> > On Wed, Jan 8, 2020 at 1:18 PM Janne Karhunen <janne.karhunen@gmail.com> wrote:
> > > Some systems can end up carrying lots of entries in the ima
> > > measurement list. Since every entry is using a bit of kernel
> > > memory, allow the sysadmin to export the measurement list to
> > > the filesystem to free up some memory.
> > 
> > Hopefully this addressed comments from everyone. The flush event can
> > now be triggered by the admin anytime and unique file names can be
> > used for each flush (log.1, log.2, ...) etc, so getting to the correct
> > item should be easy.
> > 
> > While it can now be argued that since this is an admin-driven event,
> > kernel does not need to write the file. However, the intention is to
> > bring out a second patch a bit later that adds a variable to define
> > the max number of entries to be kept in the kernel memory and
> > workqueue based automatic flushing. In those cases the kernel has to
> > be able to write the file without any help from the admin..
> 
> The implications of exporting and removing records from the IMA-
> measurement list needs to be considered carefully.  Verifying a TPM
> quote will become dependent on knowing where the measurements are
> stored.  The existing measurement list is stored in kernel memory and,
> barring a kernel memory attack, is protected from modification.
>  Before upstreaming this or a similar patch, there needs to be a
> discussion as to how the measurement list will be protected once is it
> exported to userspace.

"Protected" here can mean two different aspects: cryptographically
protected from tampering, which is covered with the TPM_QUOTE, and
availability protected from even accidental deletion, which is what
I suspect you are concerned about. Certainly my original TLV patches
were too flippant about this, as userspace had to be trusted not to
drop any records. In this patch, the kernel writes the data in an
atomic fashion. Either all records are successfully written, or none
are, and an error is returned.

> This patch now attempts to address two very different scenarios.  The
> first scenario is where userspace is requesting exporting and removing
> of the measurement list records.  The other scenario is the kernel
> exporting and removing of the measurement list records.  Conflating
> these two different use cases might not be the right solution, as we
> originally thought.

Actually there are at least four significant use cases: userspace
requested, and kernel initiated, both for running out of memory or
for saving the list prior to a kexec. Exporting everything to a file
prior to kexec can really simplify all the vaious use cases of 
template vs TLV formatted lists across kexec. (Consider a modern
TLV firmware kernel wanting to boot an older kernel that only
understands template formats. How simple it would be for the first
kernel to export its list to a file, and the second kernel keeps
its list in template.)

I have been testing this patch on all of these scenarios, and it
provides a simple, powerful approach for all of them.

> The kernel already exports the IMA measurement list to userspace via a
> securityfs file.  From a userspace perspective, missing is the ability
> of removing N number of records.  In this scenario, userspace would be
> responsible for safely storing the measurements (e.g. blockchain).
>  The kernel would only be responsible for limiting permission, perhaps
> based on a capability, before removing records from the measurement
> list. 

I don't think we want to export 'N' records, as this would
be really hard to understand and coordinate with userspace.
Exporting all or none seems simpler.

> In the kernel usecase, somehow the kernel would need to safely export
> the measurement list, or some portion of the measurement list, to a
> file and then delete that portion.  What protects the exported records
> stored in a file from modification?

Tampering is prevented with the TPM_QUOTE. Accidental deletion is
protected with CAP_SYS_ADMIN. If CAP_SYS_ADMIN is untrusted, you 
have bigger problems, and even then it will be detected.

> Instead of exporting the measurement records, one option as suggested
> by Amir Goldstein, would be to use a vfs_tmpfile() to get an anonymous
> file for backing store.  The existing securityfs measurement lists
> would then read from this private copy of the anonymous file.

This doesn't help in use cases where we really do want to
export to a persistent file, without userspace help.

> I've Cc'ed fsdevel for additional comments/suggestions.
> 
> thanks,
> 
> Mimi
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] ima: export the measurement list when needed
  2020-02-10 18:18     ` david.safford
@ 2020-02-10 20:24       ` Mimi Zohar
  2020-02-11  8:06         ` Janne Karhunen
  2020-02-11 16:10         ` david.safford
  0 siblings, 2 replies; 12+ messages in thread
From: Mimi Zohar @ 2020-02-10 20:24 UTC (permalink / raw)
  To: david.safford, Janne Karhunen, linux-integrity, linux-security-module
  Cc: Ken Goldman, monty.wiseman, Amir Goldstein, linux-fsdevel

On Mon, 2020-02-10 at 13:18 -0500, david.safford@gmail.com wrote:
> On Thu, 2020-02-06 at 09:13 -0500, Mimi Zohar wrote:
> > Hi Janne,
> > 
> > On Fri, 2020-01-10 at 10:48 +0200, Janne Karhunen wrote:
> > > On Wed, Jan 8, 2020 at 1:18 PM Janne Karhunen <janne.karhunen@gmail.com> wrote:
> > > > Some systems can end up carrying lots of entries in the ima
> > > > measurement list. Since every entry is using a bit of kernel
> > > > memory, allow the sysadmin to export the measurement list to
> > > > the filesystem to free up some memory.
> > > 
> > > Hopefully this addressed comments from everyone. The flush event can
> > > now be triggered by the admin anytime and unique file names can be
> > > used for each flush (log.1, log.2, ...) etc, so getting to the correct
> > > item should be easy.
> > > 
> > > While it can now be argued that since this is an admin-driven event,
> > > kernel does not need to write the file. However, the intention is to
> > > bring out a second patch a bit later that adds a variable to define
> > > the max number of entries to be kept in the kernel memory and
> > > workqueue based automatic flushing. In those cases the kernel has to
> > > be able to write the file without any help from the admin..
> > 
> > The implications of exporting and removing records from the IMA-
> > measurement list needs to be considered carefully.  Verifying a TPM
> > quote will become dependent on knowing where the measurements are
> > stored.  The existing measurement list is stored in kernel memory and,
> > barring a kernel memory attack, is protected from modification.
> >  Before upstreaming this or a similar patch, there needs to be a
> > discussion as to how the measurement list will be protected once is it
> > exported to userspace.
> 
> "Protected" here can mean two different aspects: cryptographically
> protected from tampering, which is covered with the TPM_QUOTE, and
> availability protected from even accidental deletion, which is what
> I suspect you are concerned about. Certainly my original TLV patches
> were too flippant about this, as userspace had to be trusted not to
> drop any records. In this patch, the kernel writes the data in an
> atomic fashion. Either all records are successfully written, or none
> are, and an error is returned.

A third aspect, which I'm concerned about, is removing records from
the measurement list.  This changes the existing userspace
expectations of returning the entire measurement list.  Now userspace
will need some out of band method of knowing where to look for the
measurements.

> 
> > This patch now attempts to address two very different scenarios.  The
> > first scenario is where userspace is requesting exporting and removing
> > of the measurement list records.  The other scenario is the kernel
> > exporting and removing of the measurement list records.  Conflating
> > these two different use cases might not be the right solution, as we
> > originally thought.
> 
> Actually there are at least four significant use cases: userspace
> requested, and kernel initiated, both for running out of memory or
> for saving the list prior to a kexec. Exporting everything to a file
> prior to kexec can really simplify all the vaious use cases of 
> template vs TLV formatted lists across kexec. (Consider a modern
> TLV firmware kernel wanting to boot an older kernel that only
> understands template formats. How simple it would be for the first
> kernel to export its list to a file, and the second kernel keeps
> its list in template.)

When Thiago and I added support for carrying the measurement list
across kexec, there were a number of additional measurements after the
kexec load.  These additional measurements will need to be safely
written out to file in order to validate the TPM quote.

> I have been testing this patch on all of these scenarios, and it
> provides a simple, powerful approach for all of them.
 
Were you able to walk the measurement list and validate the TPM quote
after a kexec?

> 
> > The kernel already exports the IMA measurement list to userspace via a
> > securityfs file.  From a userspace perspective, missing is the ability
> > of removing N number of records.  In this scenario, userspace would be
> > responsible for safely storing the measurements (e.g. blockchain).
> >  The kernel would only be responsible for limiting permission, perhaps
> > based on a capability, before removing records from the measurement
> > list. 
> 
> I don't think we want to export 'N' records, as this would
> be really hard to understand and coordinate with userspace.
> Exporting all or none seems simpler.

Userspace already has the ability of exporting the measurement list.
 However, beetween saving the measurement list to a file and telling
the kernel to delete the records from the kernel, additional
measurement could have been added.

> 
> > In the kernel usecase, somehow the kernel would need to safely export
> > the measurement list, or some portion of the measurement list, to a
> > file and then delete that portion.  What protects the exported records
> > stored in a file from modification?
> 
> Tampering is prevented with the TPM_QUOTE. Accidental deletion is
> protected with CAP_SYS_ADMIN. If CAP_SYS_ADMIN is untrusted, you 
> have bigger problems, and even then it will be detected.

Agreed, attestation will detect any tampering, but up to now we didn't
have to rely on DAC/MAC to prevent tampering of the measurement list.

> > Instead of exporting the measurement records, one option as suggested
> > by Amir Goldstein, would be to use a vfs_tmpfile() to get an anonymous
> > file for backing store.  The existing securityfs measurement lists
> > would then read from this private copy of the anonymous file.
> 
> This doesn't help in use cases where we really do want to
> export to a persistent file, without userspace help.

Is to prevent needing to carry the measurement list across kexec the
only reason for the kernel needing to write to a persistent file?

Mimi


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] ima: export the measurement list when needed
  2020-02-10 20:24       ` Mimi Zohar
@ 2020-02-11  8:06         ` Janne Karhunen
  2020-02-11 16:10         ` david.safford
  1 sibling, 0 replies; 12+ messages in thread
From: Janne Karhunen @ 2020-02-11  8:06 UTC (permalink / raw)
  To: Mimi Zohar
  Cc: david.safford, linux-integrity, linux-security-module,
	Ken Goldman, Wiseman, Monty (GE Global Research, US),
	Amir Goldstein, linux-fsdevel

On Mon, Feb 10, 2020 at 10:25 PM Mimi Zohar <zohar@linux.ibm.com> wrote:

> A third aspect, which I'm concerned about, is removing records from
> the measurement list.  This changes the existing userspace
> expectations of returning the entire measurement list.  Now userspace
> will need some out of band method of knowing where to look for the
> measurements.

Well, the original patch has a mechanism with one bit flip. You can
read the list name given that you are in the right namespace and/or
mount.


> > > The kernel already exports the IMA measurement list to userspace via a
> > > securityfs file.  From a userspace perspective, missing is the ability
> > > of removing N number of records.  In this scenario, userspace would be
> > > responsible for safely storing the measurements (e.g. blockchain).
> > >  The kernel would only be responsible for limiting permission, perhaps
> > > based on a capability, before removing records from the measurement
> > > list.
> >
> > I don't think we want to export 'N' records, as this would
> > be really hard to understand and coordinate with userspace.
> > Exporting all or none seems simpler.
>
> Userspace already has the ability of exporting the measurement list.
>  However, beetween saving the measurement list to a file and telling
> the kernel to delete the records from the kernel, additional
> measurement could have been added.

This is not an issue as long as there is no 'ALL' alias. We can't
agree on what 'ALL' is, but we can agree on 'N'.


> > Tampering is prevented with the TPM_QUOTE. Accidental deletion is
> > protected with CAP_SYS_ADMIN. If CAP_SYS_ADMIN is untrusted, you
> > have bigger problems, and even then it will be detected.
>
> Agreed, attestation will detect any tampering, but up to now we didn't
> have to rely on DAC/MAC to prevent tampering of the measurement list.

True. How about storing a hmac of the file in a securityfs entry?


--
Janne

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] ima: export the measurement list when needed
  2020-02-10 20:24       ` Mimi Zohar
  2020-02-11  8:06         ` Janne Karhunen
@ 2020-02-11 16:10         ` david.safford
  2020-02-11 23:10           ` Mimi Zohar
  1 sibling, 1 reply; 12+ messages in thread
From: david.safford @ 2020-02-11 16:10 UTC (permalink / raw)
  To: Mimi Zohar, Janne Karhunen, linux-integrity, linux-security-module
  Cc: Ken Goldman, monty.wiseman, Amir Goldstein, linux-fsdevel

On Mon, 2020-02-10 at 15:24 -0500, Mimi Zohar wrote:
> On Mon, 2020-02-10 at 13:18 -0500, david.safford@gmail.com wrote:
> > On Thu, 2020-02-06 at 09:13 -0500, Mimi Zohar wrote:
> > > Hi Janne,
> > > 
> > > On Fri, 2020-01-10 at 10:48 +0200, Janne Karhunen wrote:
> > > > On Wed, Jan 8, 2020 at 1:18 PM Janne Karhunen <janne.karhunen@gmail.com> wrote:
> > > > > Some systems can end up carrying lots of entries in the ima
> > > > > measurement list. Since every entry is using a bit of kernel
> > > > > memory, allow the sysadmin to export the measurement list to
> > > > > the filesystem to free up some memory.
> > > > 
> > > > Hopefully this addressed comments from everyone. The flush event can
> > > > now be triggered by the admin anytime and unique file names can be
> > > > used for each flush (log.1, log.2, ...) etc, so getting to the correct
> > > > item should be easy.
> > > > 
> > > > While it can now be argued that since this is an admin-driven event,
> > > > kernel does not need to write the file. However, the intention is to
> > > > bring out a second patch a bit later that adds a variable to define
> > > > the max number of entries to be kept in the kernel memory and
> > > > workqueue based automatic flushing. In those cases the kernel has to
> > > > be able to write the file without any help from the admin..
> > > 
> > > The implications of exporting and removing records from the IMA-
> > > measurement list needs to be considered carefully.  Verifying a TPM
> > > quote will become dependent on knowing where the measurements are
> > > stored.  The existing measurement list is stored in kernel memory and,
> > > barring a kernel memory attack, is protected from modification.
> > >  Before upstreaming this or a similar patch, there needs to be a
> > > discussion as to how the measurement list will be protected once is it
> > > exported to userspace.
> > 
> > "Protected" here can mean two different aspects: cryptographically
> > protected from tampering, which is covered with the TPM_QUOTE, and
> > availability protected from even accidental deletion, which is what
> > I suspect you are concerned about. Certainly my original TLV patches
> > were too flippant about this, as userspace had to be trusted not to
> > drop any records. In this patch, the kernel writes the data in an
> > atomic fashion. Either all records are successfully written, or none
> > are, and an error is returned.
> 
> A third aspect, which I'm concerned about, is removing records from
> the measurement list.  This changes the existing userspace
> expectations of returning the entire measurement list.  Now userspace
> will need some out of band method of knowing where to look for the
> measurements.

This is a feature, not a bug. :-)
There is no reason to resend the same data for every attestation,
nor is there any reason to store already attested measurements anywhere
on the client. By versioning the log file names, userspace gets a
simple way to know what has and has not been attested, and for small
embedded devices we don't need to waste memory or filesystem space
on the data already attested.

> When Thiago and I added support for carrying the measurement list
> across kexec, there were a number of additional measurements after the
> kexec load.  These additional measurements will need to be safely
> written out to file in order to validate the TPM quote.
> 
> > I have been testing this patch on all of these scenarios, and it
> > provides a simple, powerful approach for all of them.
>  
> Were you able to walk the measurement list and validate the TPM quote
> after a kexec?

I'm still working on this. (I've mainly been making sure this works
for normal template and TLV lists.) I should be able to write out the
remaining kexec measurements, but haven't actually validated that
yet...

> > > The kernel already exports the IMA measurement list to userspace via a
> > > securityfs file.  From a userspace perspective, missing is the ability
> > > of removing N number of records.  In this scenario, userspace would be
> > > responsible for safely storing the measurements (e.g. blockchain).
> > >  The kernel would only be responsible for limiting permission, perhaps
> > > based on a capability, before removing records from the measurement
> > > list. 
> > 
> > I don't think we want to export 'N' records, as this would
> > be really hard to understand and coordinate with userspace.
> > Exporting all or none seems simpler.
> 
> Userspace already has the ability of exporting the measurement list.
>  However, beetween saving the measurement list to a file and telling
> the kernel to delete the records from the kernel, additional
> measurement could have been added.

This method of exporting is atomic, so only those items exported
get deleted.

> > > In the kernel usecase, somehow the kernel would need to safely export
> > > the measurement list, or some portion of the measurement list, to a
> > > file and then delete that portion.  What protects the exported records
> > > stored in a file from modification?
> > 
> > Tampering is prevented with the TPM_QUOTE. Accidental deletion is
> > protected with CAP_SYS_ADMIN. If CAP_SYS_ADMIN is untrusted, you 
> > have bigger problems, and even then it will be detected.
> 
> Agreed, attestation will detect any tampering, but up to now we didn't
> have to rely on DAC/MAC to prevent tampering of the measurement list.

The userspace attestation process has always been able to tamper or
delete the list data during its attestation, but we can detect this
remotely.

> > > Instead of exporting the measurement records, one option as suggested
> > > by Amir Goldstein, would be to use a vfs_tmpfile() to get an anonymous
> > > file for backing store.  The existing securityfs measurement lists
> > > would then read from this private copy of the anonymous file.
> > 
> > This doesn't help in use cases where we really do want to
> > export to a persistent file, without userspace help.
> 
> Is to prevent needing to carry the measurement list across kexec the
> only reason for the kernel needing to write to a persistent file?

Well, that and the other reasons mentioned, such as completely freeing
the data from the client after attestation, and simplicity of the
mechanism.

dave

> Mimi
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] ima: export the measurement list when needed
  2020-02-11 16:10         ` david.safford
@ 2020-02-11 23:10           ` Mimi Zohar
  2020-02-12 21:08             ` david.safford
  0 siblings, 1 reply; 12+ messages in thread
From: Mimi Zohar @ 2020-02-11 23:10 UTC (permalink / raw)
  To: david.safford, Janne Karhunen, linux-integrity, linux-security-module
  Cc: Ken Goldman, monty.wiseman, Amir Goldstein, linux-fsdevel

On Tue, 2020-02-11 at 11:10 -0500, david.safford@gmail.com wrote:
> On Mon, 2020-02-10 at 15:24 -0500, Mimi Zohar wrote:
> > On Mon, 2020-02-10 at 13:18 -0500, david.safford@gmail.com wrote:
> > > On Thu, 2020-02-06 at 09:13 -0500, Mimi Zohar wrote:
> > > > Hi Janne,
> > > > 
> > > > On Fri, 2020-01-10 at 10:48 +0200, Janne Karhunen wrote:
> > > > > On Wed, Jan 8, 2020 at 1:18 PM Janne Karhunen <janne.karhunen@gmail.com> wrote:
> > > > > > Some systems can end up carrying lots of entries in the ima
> > > > > > measurement list. Since every entry is using a bit of kernel
> > > > > > memory, allow the sysadmin to export the measurement list to
> > > > > > the filesystem to free up some memory.
> > > > > 
> > > > > Hopefully this addressed comments from everyone. The flush event can
> > > > > now be triggered by the admin anytime and unique file names can be
> > > > > used for each flush (log.1, log.2, ...) etc, so getting to the correct
> > > > > item should be easy.
> > > > > 
> > > > > While it can now be argued that since this is an admin-driven event,
> > > > > kernel does not need to write the file. However, the intention is to
> > > > > bring out a second patch a bit later that adds a variable to define
> > > > > the max number of entries to be kept in the kernel memory and
> > > > > workqueue based automatic flushing. In those cases the kernel has to
> > > > > be able to write the file without any help from the admin..
> > > > 
> > > > The implications of exporting and removing records from the IMA-
> > > > measurement list needs to be considered carefully.  Verifying a TPM
> > > > quote will become dependent on knowing where the measurements are
> > > > stored.  The existing measurement list is stored in kernel memory and,
> > > > barring a kernel memory attack, is protected from modification.
> > > >  Before upstreaming this or a similar patch, there needs to be a
> > > > discussion as to how the measurement list will be protected once is it
> > > > exported to userspace.
> > > 
> > > "Protected" here can mean two different aspects: cryptographically
> > > protected from tampering, which is covered with the TPM_QUOTE, and
> > > availability protected from even accidental deletion, which is what
> > > I suspect you are concerned about. Certainly my original TLV patches
> > > were too flippant about this, as userspace had to be trusted not to
> > > drop any records. In this patch, the kernel writes the data in an
> > > atomic fashion. Either all records are successfully written, or none
> > > are, and an error is returned.
> > 
> > A third aspect, which I'm concerned about, is removing records from
> > the measurement list.  This changes the existing userspace
> > expectations of returning the entire measurement list.  Now userspace
> > will need some out of band method of knowing where to look for the
> > measurements.
> 
> This is a feature, not a bug. :-)
> There is no reason to resend the same data for every attestation,
> nor is there any reason to store already attested measurements anywhere
> on the client. By versioning the log file names, userspace gets a
> simple way to know what has and has not been attested, and for small
> embedded devices we don't need to waste memory or filesystem space
> on the data already attested.

This new feature will require setting up some infrastructure for
storing the partial measurement list(s) in order to validate a TPM
quote.  Userspace already can save partial measurement list(s) without
any kernel changes.  The entire measurement list does not need to be
read each time.  lseek can read past the last record previously read.
 The only new aspect is truncating the in kernel measurement list in
order to free kernel memory.

< snip> 

> > > > Instead of exporting the measurement records, one option as suggested
> > > > by Amir Goldstein, would be to use a vfs_tmpfile() to get an anonymous
> > > > file for backing store.  The existing securityfs measurement lists
> > > > would then read from this private copy of the anonymous file.
> > > 
> > > This doesn't help in use cases where we really do want to
> > > export to a persistent file, without userspace help.
> > 
> > Is to prevent needing to carry the measurement list across kexec the
> > only reason for the kernel needing to write to a persistent file?
> 
> Well, that and the other reasons mentioned, such as completely freeing
> the data from the client after attestation, and simplicity of the
> mechanism.

Until there is proof that the measurement list can be exported to a
file before kexec, instead of carrying the measurement list across
kexec, and a TPM quote can be validated after the kexec, there isn't a
compelling reason for the kernel needing to truncate the measurement
list.

Mimi


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] ima: export the measurement list when needed
  2020-02-11 23:10           ` Mimi Zohar
@ 2020-02-12 21:08             ` david.safford
  2020-02-13  1:03               ` Mimi Zohar
  0 siblings, 1 reply; 12+ messages in thread
From: david.safford @ 2020-02-12 21:08 UTC (permalink / raw)
  To: Mimi Zohar, Janne Karhunen, linux-integrity, linux-security-module
  Cc: Ken Goldman, monty.wiseman, Amir Goldstein, linux-fsdevel

On Tue, 2020-02-11 at 18:10 -0500, Mimi Zohar wrote:
> On Tue, 2020-02-11 at 11:10 -0500, david.safford@gmail.com wrote:

> > <snip>
> > 
> This new feature will require setting up some infrastructure for
> storing the partial measurement list(s) in order to validate a TPM
> quote.  Userspace already can save partial measurement list(s) without
> any kernel changes.  The entire measurement list does not need to be
> read each time.  lseek can read past the last record previously read.
>  The only new aspect is truncating the in kernel measurement list in
> order to free kernel memory.

This is a pretty important new feature.
A lot of people can't use IMA because of the memory issue.
Also, I really think we need to let administrators choose the tradeoffs
of keeping the list in memory, on a local file, or only on the 
attestation server, as best fits their use cases.
> 
> < snip> 
> 
> Until there is proof that the measurement list can be exported to a
> file before kexec, instead of carrying the measurement list across
> kexec, and a TPM quote can be validated after the kexec, there isn't a
> compelling reason for the kernel needing to truncate the measurement
> list.

If this approach doesn't work with all the kexec use cases, then it is 
useless, and the ball is in my court to prove that it does. Fortunately
I have to test that anyway for the coming TLV support.

Working on it...

dave

> Mimi
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] ima: export the measurement list when needed
  2020-02-12 21:08             ` david.safford
@ 2020-02-13  1:03               ` Mimi Zohar
  2020-02-13  6:41                 ` Janne Karhunen
  0 siblings, 1 reply; 12+ messages in thread
From: Mimi Zohar @ 2020-02-13  1:03 UTC (permalink / raw)
  To: david.safford, Janne Karhunen, linux-integrity, linux-security-module
  Cc: Ken Goldman, monty.wiseman, Amir Goldstein, linux-fsdevel

On Wed, 2020-02-12 at 16:08 -0500, david.safford@gmail.com wrote:
> On Tue, 2020-02-11 at 18:10 -0500, Mimi Zohar wrote:
> > On Tue, 2020-02-11 at 11:10 -0500, david.safford@gmail.com wrote:
> 
> > > <snip>
> > > 
> > This new feature will require setting up some infrastructure for
> > storing the partial measurement list(s) in order to validate a TPM
> > quote.  Userspace already can save partial measurement list(s) without
> > any kernel changes.  The entire measurement list does not need to be
> > read each time.  lseek can read past the last record previously read.
> >  The only new aspect is truncating the in kernel measurement list in
> > order to free kernel memory.
> 
> This is a pretty important new feature.
> A lot of people can't use IMA because of the memory issue.
> Also, I really think we need to let administrators choose the tradeoffs
> of keeping the list in memory, on a local file, or only on the 
> attestation server, as best fits their use cases.

Dave, I understand that some use cases require the ability of
truncating the measurement list.  We're discussing how to truncate the
measurement list.  For example, in addition to the existing securityfs
binary_runtime_measurements file, we could define a new securityfs
file indicating the number of records to delete.

> > 
> > < snip> 
> > 
> > Until there is proof that the measurement list can be exported to a
> > file before kexec, instead of carrying the measurement list across
> > kexec, and a TPM quote can be validated after the kexec, there isn't a
> > compelling reason for the kernel needing to truncate the measurement
> > list.
> 
> If this approach doesn't work with all the kexec use cases, then it is 
> useless, and the ball is in my court to prove that it does. Fortunately
> I have to test that anyway for the coming TLV support.
> 
> Working on it...

Testing could be done independently of the TLV support.  To verify
that you aren't loosing any measurements, boot with a measurement
policy like "ima_policy=tcb" on the boot command line.

thanks,

Mimi


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] ima: export the measurement list when needed
  2020-02-13  1:03               ` Mimi Zohar
@ 2020-02-13  6:41                 ` Janne Karhunen
  2020-02-18 15:36                   ` Mimi Zohar
  0 siblings, 1 reply; 12+ messages in thread
From: Janne Karhunen @ 2020-02-13  6:41 UTC (permalink / raw)
  To: Mimi Zohar
  Cc: david.safford, linux-integrity, linux-security-module,
	Ken Goldman, Wiseman, Monty (GE Global Research, US),
	Amir Goldstein, linux-fsdevel

On Thu, Feb 13, 2020 at 3:03 AM Mimi Zohar <zohar@linux.ibm.com> wrote:

> > This is a pretty important new feature.
> > A lot of people can't use IMA because of the memory issue.
> > Also, I really think we need to let administrators choose the tradeoffs
> > of keeping the list in memory, on a local file, or only on the
> > attestation server, as best fits their use cases.
>
> Dave, I understand that some use cases require the ability of
> truncating the measurement list.  We're discussing how to truncate the
> measurement list.  For example, in addition to the existing securityfs
> binary_runtime_measurements file, we could define a new securityfs
> file indicating the number of records to delete.

I don't have strong opinions either way, just let me know how to adapt
the patch and we will get it done asap. I'd prefer a solution where
the kernel can initiate the flush, but if not then not.

Thanks everyone for all the help.


--
Janne

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] ima: export the measurement list when needed
  2020-02-13  6:41                 ` Janne Karhunen
@ 2020-02-18 15:36                   ` Mimi Zohar
  0 siblings, 0 replies; 12+ messages in thread
From: Mimi Zohar @ 2020-02-18 15:36 UTC (permalink / raw)
  To: Janne Karhunen
  Cc: david.safford, linux-integrity, linux-security-module,
	Ken Goldman, Wiseman, Monty (GE Global Research, US),
	Amir Goldstein, linux-fsdevel

On Thu, 2020-02-13 at 08:41 +0200, Janne Karhunen wrote:
> On Thu, Feb 13, 2020 at 3:03 AM Mimi Zohar <zohar@linux.ibm.com> wrote:
> 
> > > This is a pretty important new feature.
> > > A lot of people can't use IMA because of the memory issue.
> > > Also, I really think we need to let administrators choose the tradeoffs
> > > of keeping the list in memory, on a local file, or only on the
> > > attestation server, as best fits their use cases.
> >
> > Dave, I understand that some use cases require the ability of
> > truncating the measurement list.  We're discussing how to truncate the
> > measurement list.  For example, in addition to the existing securityfs
> > binary_runtime_measurements file, we could define a new securityfs
> > file indicating the number of records to delete.
> 
> I don't have strong opinions either way, just let me know how to adapt
> the patch and we will get it done asap. I'd prefer a solution where
> the kernel can initiate the flush, but if not then not.

If the measurement list isn't stored in kernel memory, then we would
have the best of both worlds.  The measurement list staying intact for
attestation, with userspace's ability to truncate the measurement list
as desired.  Barring any implementation details, I see this as a win-
win solution.

Mimi


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-02-18 15:37 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200108111743.23393-1-janne.karhunen@gmail.com>
     [not found] ` <CAE=NcrZrbRinOAbB+k1rjhcae3nqfJ8snC_EnY8njMDioM7=vg@mail.gmail.com>
2020-02-06 14:13   ` [PATCH v2] ima: export the measurement list when needed Mimi Zohar
2020-02-10  8:04     ` Janne Karhunen
2020-02-10 15:26       ` Mimi Zohar
2020-02-10 18:18     ` david.safford
2020-02-10 20:24       ` Mimi Zohar
2020-02-11  8:06         ` Janne Karhunen
2020-02-11 16:10         ` david.safford
2020-02-11 23:10           ` Mimi Zohar
2020-02-12 21:08             ` david.safford
2020-02-13  1:03               ` Mimi Zohar
2020-02-13  6:41                 ` Janne Karhunen
2020-02-18 15:36                   ` Mimi Zohar

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).