mbox series

[v6,0/8] IMA: support for measuring kernel integrity critical data

Message ID 20201119232611.30114-1-tusharsu@linux.microsoft.com (mailing list archive)
Headers show
Series IMA: support for measuring kernel integrity critical data | expand

Message

Tushar Sugandhi Nov. 19, 2020, 11:26 p.m. UTC
Kernel integrity critical data can be defined as the in-memory kernel
data which if accidentally or maliciously altered, can compromise the
integrity of the system.

There are several kernel subsystems that contain integrity critical
data - e.g. LSMs like SELinux, or AppArmor; or device-mapper targets
like dm-crypt, dm-verity etc. Examples of critical data could be kernel
in-memory r/o structures, hash of the memory structures, or data that
represents a linux kernel subsystem state.

This patch set defines a new IMA hook namely ima_measure_critical_data()
to measure the critical data. Kernel subsystems can use this
functionality, to take advantage of IMA's measuring and quoting 
abilities - thus ultimately enabling remote attestation for the
subsystem specific information stored in the kernel memory.

The functionality is generic enough to measure the data, from the kernel
subsystems, that is required to protect the integrity of the kernel at
runtime.

System administrators may want to limit the critical data being
measured, quoted, and attested. To enable that, a new IMA policy
condition is defined.

This patch set also addresses the need for measuring kernel critical
data early, before a custom IMA policy is loaded - by providing a
builtin IMA policy.

And lastly, the series provides the first consumer of the new IMA hook -
namely SeLinux.

This series is based on the following repo/branch:

 repo: https://github.com/torvalds/linux
 branch: master
 commit 09162bc32c88 ("Linux 5.10-rc4")

This series also has a dependency on the following patch
https://patchwork.kernel.org/patch/11901423/

Change Log v6:
Incorporated feedback from Mimi on v5 of this series.
 - Got rid of patch 5 from the v5 of the series.(the allow list for data
   sources)
 - Updated function descriptions, changed variable names etc.
 - Moved the input param event_data_source in ima_measure_critical_data()
   to a new patch. (patch 6/8 of this series)
 - Split patch 4 from v5 of the series into two patches (patch 4/8 and 
   patch 5/8)
 - Updated cover letter and patch descriptions as per feedback.

Change Log v5:
(1) Incorporated feedback from Stephen on the last SeLinux patch.
 SeLinux Patch: https://patchwork.kernel.org/patch/11801585/
 - Freed memory in the reverse order of allocation in 
   selinux_measure_state().
 - Used scnprintf() instead of snprintf() to create the string for
   selinux state.
 - Allocated event name passed to ima_measure_critical_data() before
   gathering selinux state and policy information for measuring.

(2) Incorporated feedback from Mimi on v4 of this series.
 V4 of this Series: https://patchwork.kernel.org/project/linux-integrity/list/?series=354437

 - Removed patch "[v4,2/6] IMA: conditionally allow empty rule data"
 - Reversed the order of following patches.
      [v4,4/6] IMA: add policy to measure critical data from kernel components
      [v4,5/6] IMA: add hook to measure critical data from kernel components
   and renamed them to remove "from kernel components"
 - Added a new patch to this series - 
       IMA: add critical_data to built-in policy rules

 - Added the next version of SeLinux patch (mentioned above) to this
   series 
       selinux: measure state and hash of the policy using IMA

 - Updated cover-letter description to give broader perspective of the
   feature, rearranging paragraphs, removing unnecessary info, clarifying
   terms etc.
 - Got rid of opt_list param from ima_match_rule_data().
 - Updated the documentation to remove sources that don't yet exist.
 - detailed IMA hook description added to ima_measure_critical_data(),
   as well as elaborating terms event_name, event_data_source. 
 - "data_sources:=" is not a mandatory policy option for 
   func=CRITICAL_DATA anymore. If not present, all the data sources
   specified in __ima_supported_kernel_data_sources will be measured.

Lakshmi Ramasubramanian (2):
  IMA: add a built-in policy rule for critical data measurement
  selinux: measure state and hash of the policy using IMA

Tushar Sugandhi (6):
  IMA: generalize keyring specific measurement constructs
  IMA: add support to measure buffer data hash
  IMA: define a hook to measure kernel integrity critical data
  IMA: add policy rule to measure critical data
  IMA: extend policy to add data sources as a critical data measurement
    constraint
  IMA: add support to critical data hook to limit data sources for
    measurement

 Documentation/ABI/testing/ima_policy         |  10 +-
 include/linux/ima.h                          |   8 +
 security/integrity/ima/ima.h                 |   8 +-
 security/integrity/ima/ima_api.c             |   8 +-
 security/integrity/ima/ima_appraise.c        |   2 +-
 security/integrity/ima/ima_asymmetric_keys.c |   2 +-
 security/integrity/ima/ima_main.c            |  81 +++++++++-
 security/integrity/ima/ima_policy.c          | 123 ++++++++++++---
 security/integrity/ima/ima_queue_keys.c      |   3 +-
 security/selinux/Makefile                    |   2 +
 security/selinux/hooks.c                     |   3 +
 security/selinux/include/security.h          |  11 +-
 security/selinux/measure.c                   | 157 +++++++++++++++++++
 security/selinux/selinuxfs.c                 |   8 +
 security/selinux/ss/services.c               |  71 +++++++--
 15 files changed, 448 insertions(+), 49 deletions(-)
 create mode 100644 security/selinux/measure.c

Comments

Pavel Machek Nov. 20, 2020, 12:46 p.m. UTC | #1
On Thu 2020-11-19 15:26:03, Tushar Sugandhi wrote:
> Kernel integrity critical data can be defined as the in-memory kernel
> data which if accidentally or maliciously altered, can compromise the
> integrity of the system.

Is that an useful definition?

> There are several kernel subsystems that contain integrity critical
> data - e.g. LSMs like SELinux, or AppArmor; or device-mapper targets
> like dm-crypt, dm-verity etc. Examples of critical data could be kernel
> in-memory r/o structures, hash of the memory structures, or data that
> represents a linux kernel subsystem state.
> 
> This patch set defines a new IMA hook namely ima_measure_critical_data()
> to measure the critical data. Kernel subsystems can use this
> functionality, to take advantage of IMA's measuring and quoting 
> abilities - thus ultimately enabling remote attestation for the
> subsystem specific information stored in the kernel memory.

How is it supposed to be useful?

I'm pretty sure there are critical data that are not measured by
proposed module... and that are written under normal circumstances.

Best regards,

									Pavel
Tushar Sugandhi Nov. 22, 2020, 8:53 p.m. UTC | #2
Thanks Pavel for looking at this series.

On 2020-11-20 4:46 a.m., Pavel Machek wrote:
> On Thu 2020-11-19 15:26:03, Tushar Sugandhi wrote:
>> Kernel integrity critical data can be defined as the in-memory kernel
>> data which if accidentally or maliciously altered, can compromise the
>> integrity of the system.
> 
> Is that an useful definition?
I will rework on the definition in the next iteration.
Meanwhile, if you have any feedback on what can we add to the
definition, that would help is.

> 
>> There are several kernel subsystems that contain integrity critical
>> data - e.g. LSMs like SELinux, or AppArmor; or device-mapper targets
>> like dm-crypt, dm-verity etc. Examples of critical data could be kernel
>> in-memory r/o structures, hash of the memory structures, or data that
>> represents a linux kernel subsystem state.
>>
>> This patch set defines a new IMA hook namely ima_measure_critical_data()
>> to measure the critical data. Kernel subsystems can use this
>> functionality, to take advantage of IMA's measuring and quoting
>> abilities - thus ultimately enabling remote attestation for the
>> subsystem specific information stored in the kernel memory.
> 
> How is it supposed to be useful?
> 
> I'm pretty sure there are critical data that are not measured by
> proposed module... and that are written under normal circumstances.
> 
The goal of this series is to introduce the IMA hook
measure_critical_data() and the necessary policies to use it; and
illustrate that use with one example (SELinux). It is not scalable to 
identify and update all the critical data sources to use the proposed
module at once.

A piecemeal approach to add more critical data measurement in subsequent
patches would be easy to implement and review.

Please let me know if you have more thoughts on this. (what critical
data you think would be useful to measure etc.)

~Tushar

> Best regards,
> 
> 									Pavel
>
Pavel Machek Nov. 22, 2020, 9 p.m. UTC | #3
Hi!

> >How is it supposed to be useful?
> >
> >I'm pretty sure there are critical data that are not measured by
> >proposed module... and that are written under normal circumstances.
> >
> The goal of this series is to introduce the IMA hook
> measure_critical_data() and the necessary policies to use it; and
> illustrate that use with one example (SELinux). It is not scalable to
> identify and update all the critical data sources to use the proposed
> module at once.
> 
> A piecemeal approach to add more critical data measurement in subsequent
> patches would be easy to implement and review.

Basically every other data structure in kernel is "critical" by your
definition, and you can't really measure them all; some of them change
rather often. Going piecemeal does not really help here.

Example of critical data structure: page table entries for process I
own.

Best regards,
								Pavel
Mimi Zohar Nov. 23, 2020, 1:41 p.m. UTC | #4
Hi Pavel,

On Sun, 2020-11-22 at 22:00 +0100, Pavel Machek wrote:
> Hi!
> 
> > >How is it supposed to be useful?
> > >
> > >I'm pretty sure there are critical data that are not measured by
> > >proposed module... and that are written under normal circumstances.
> > >
> > The goal of this series is to introduce the IMA hook
> > measure_critical_data() and the necessary policies to use it; and
> > illustrate that use with one example (SELinux). It is not scalable to
> > identify and update all the critical data sources to use the proposed
> > module at once.
> > 
> > A piecemeal approach to add more critical data measurement in subsequent
> > patches would be easy to implement and review.
> 
> Basically every other data structure in kernel is "critical" by your
> definition, and you can't really measure them all; some of them change
> rather often. Going piecemeal does not really help here.

Agreed, measuring data structures that change is not really applicable.
However, measuring data structures that once initialized don't change,
does make sense (similar concept to __ro_after_init).  The attestation
server doesn't need to know anything about the measurement, other than
more than a single measurement is indicative of a problem.

Mimi

> Example of critical data structure: page table entries for process I
> own.
Pavel Machek Nov. 23, 2020, 5:18 p.m. UTC | #5
Hi!

> > > >How is it supposed to be useful?
> > > >
> > > >I'm pretty sure there are critical data that are not measured by
> > > >proposed module... and that are written under normal circumstances.
> > > >
> > > The goal of this series is to introduce the IMA hook
> > > measure_critical_data() and the necessary policies to use it; and
> > > illustrate that use with one example (SELinux). It is not scalable to
> > > identify and update all the critical data sources to use the proposed
> > > module at once.
> > > 
> > > A piecemeal approach to add more critical data measurement in subsequent
> > > patches would be easy to implement and review.
> > 
> > Basically every other data structure in kernel is "critical" by your
> > definition, and you can't really measure them all; some of them change
> > rather often. Going piecemeal does not really help here.
> 
> Agreed, measuring data structures that change is not really applicable.
> However, measuring data structures that once initialized don't change,
> does make sense (similar concept to __ro_after_init).  The attestation
> server doesn't need to know anything about the measurement, other than
> more than a single measurement is indicative of a problem.

So, why not simply measure everything that is ro_after_init?

But... I really fail to see how this is useful. It is trivial to
"backdoor" kernel w/o modifying anything that is
ro_after_init. (Example: page tables).

								Pavel
Mimi Zohar Nov. 23, 2020, 7:49 p.m. UTC | #6
On Mon, 2020-11-23 at 18:18 +0100, Pavel Machek wrote:
> > > Basically every other data structure in kernel is "critical" by your
> > > definition, and you can't really measure them all; some of them change
> > > rather often. Going piecemeal does not really help here.
> > 
> > Agreed, measuring data structures that change is not really applicable.
> > However, measuring data structures that once initialized don't change,
> > does make sense (similar concept to __ro_after_init).  The attestation
> > server doesn't need to know anything about the measurement, other than
> > more than a single measurement is indicative of a problem.
> 
> So, why not simply measure everything that is ro_after_init?

I guess we could, but the original discussion, a long time ago prior to
LSM stacking, was limited to measuring the LSM hooks.

Mimi