Skip to contentSkip to conversation

ima: export the measurement list when needed

RFC Raphael Gianotti 2 participants 8 messages Aug 17, 2020 – Sep 2, 2020 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

Hi Janne,

Subject: Re: [RFC] ima: export the measurement list when needed

Quoted 22 lines

Date: Wed, 18 Dec 2019 17:11:22 +0200
From: Janne Karhunen <[email protected]>
To: [email protected], Mimi Zohar <[email protected]>
CC: Ken Goldman <[email protected]>, [email protected], [email protected]

Hi,

Have in mind that below is the first trial draft that booted and seemingly accomplished the task once, it was not really tested at all yet. I will make a polished and tested version if people like the concept.

Note that the code (almost) supports pushing and pulling of the entries. This variant is a simple pull given that the list size is above the defined limits. Pushing can be put in place if the recursion with the list extend_list_mutex is cleared, maybe this could be done via another patch later on when we have a workqueue for the export task? The workqueue might be the best context for the export job since clearing the list is a heavy operation (and it's not entirely correct here AFAIK, there is no rcu sync before the template free).

Quoted 21 lines

-- Janne

Quoted 18 lines · Janne Karhunen

Some systems can end up carrying lots of entries in the ima measurement list. Since every entry is using a bit of kernel memory, add a new Kconfig variable to allow the sysadmin to define the maximum measurement list size and the location of the exported list.

The list is written out in append mode, so the system will keep writing new entries as long as it stays running or runs out of space. File is also automatically truncated on startup.

---
 security/integrity/ima/Kconfig     |  10 ++ security/integrity/ima/ima.h       |   7 +- security/integrity/ima/ima_fs.c    | 178 +++++++++++++++++++++++++++++ security/integrity/ima/ima_queue.c |   2 +-

 4 files changed, 192 insertions(+), 5 deletions(-)

I've been looking into a solution to this same issue you started some work on. I was wondering if you are still working on it. I was considering taking your initial prototyping on this and extending it into a final solution, but I wanted to reply here first and check if you are currently working on this.

#2 lore raw

Hi Raphael,

Sorry I missed the reply. I'm not working on this right now, feel free to grab. Please copy me with the results, thank you.

--
Janne

Quoted 57 lines · Raphael Gianotti

Hi Janne,

Subject: Re: [RFC] ima: export the measurement list when needed

Quoted 23 lines

Date: Wed, 18 Dec 2019 17:11:22 +0200
From: Janne Karhunen <[email protected]>
To: [email protected], Mimi Zohar <[email protected]>
CC: Ken Goldman <[email protected]>, [email protected], [email protected]

Hi,

Have in mind that below is the first trial draft that booted and seemingly accomplished the task once, it was not really tested at all yet. I will make a polished and tested version if people like the concept.

Note that the code (almost) supports pushing and pulling of the entries. This variant is a simple pull given that the list size is above the defined limits. Pushing can be put in place if the recursion with the list extend_list_mutex is cleared, maybe this could be done via another patch later on when we have a workqueue for the export task? The workqueue might be the best context for the export job since clearing the list is a heavy operation (and it's not entirely correct here AFAIK, there is no rcu sync before the template free).

Quoted 22 lines

-- Janne

Quoted 18 lines · Janne Karhunen

Some systems can end up carrying lots of entries in the ima measurement list. Since every entry is using a bit of kernel memory, add a new Kconfig variable to allow the sysadmin to define the maximum measurement list size and the location of the exported list.

The list is written out in append mode, so the system will keep writing new entries as long as it stays running or runs out of space. File is also automatically truncated on startup.

---
 security/integrity/ima/Kconfig     |  10 ++
 security/integrity/ima/ima.h       |   7 +-
 security/integrity/ima/ima_fs.c    | 178 +++++++++++++++++++++++++++++
 security/integrity/ima/ima_queue.c |   2 +-
 4 files changed, 192 insertions(+), 5 deletions(-)

I've been looking into a solution to this same issue you started some work on. I was wondering if you are still working on it. I was considering taking your initial prototyping on this and extending it into a final solution, but I wanted to reply here first and check if you are currently working on this.

#3 lore raw

Hi,

Attached a variant of the patch from that time that only does the element free and relies on the userspace reading the data.

The reason why I stopped working on this at the time was that below was sufficient for my needs. However, after a discussion between Mimi and myself (based on a suggestion by Amir Goldstein) we realized that we could do something considerably more elegant through vfs_tmpfile. It's also much more work.

The way this could probably work the best is if we would implement a new allocator that would pull pages from a vmarea tied to a vfs_tmpfile and the file could be opened by the kernel itself during the ima init. Now if all the measurement list data blobs would be allocated through this allocator the pages would never be permanently resident in the kernel, they would only visit the memory for a while when someone reads the data. If done this way the allocator probably does not even need a 'free' and the mm code would do all the real work pushing the data out.

The benefits would be that no-one would ever have to poll from userspace (kernel does not depend on the userspace to work) and we would never OOM because of IMA as long as the filesystem is writable. Also we would never lose any data as long as the file system is functioning.

Thoughts?

--
Janne

Quoted 7 lines · Janne Karhunen

Hi Raphael,

Sorry I missed the reply. I'm not working on this right now, feel free to grab. Please copy me with the results, thank you.

Quoted 62 lines

--
Janne

Quoted 57 lines · Raphael Gianotti

Hi Janne,

Subject: Re: [RFC] ima: export the measurement list when needed

Quoted 23 lines

Date: Wed, 18 Dec 2019 17:11:22 +0200
From: Janne Karhunen <[email protected]>
To: [email protected], Mimi Zohar <[email protected]>
CC: Ken Goldman <[email protected]>, [email protected], [email protected]

Hi,

Have in mind that below is the first trial draft that booted and seemingly accomplished the task once, it was not really tested at all yet. I will make a polished and tested version if people like the concept.

Note that the code (almost) supports pushing and pulling of the entries. This variant is a simple pull given that the list size is above the defined limits. Pushing can be put in place if the recursion with the list extend_list_mutex is cleared, maybe this could be done via another patch later on when we have a workqueue for the export task? The workqueue might be the best context for the export job since clearing the list is a heavy operation (and it's not entirely correct here AFAIK, there is no rcu sync before the template free).

Quoted 22 lines

-- Janne

Quoted 18 lines · Janne Karhunen

Some systems can end up carrying lots of entries in the ima measurement list. Since every entry is using a bit of kernel memory, add a new Kconfig variable to allow the sysadmin to define the maximum measurement list size and the location of the exported list.

The list is written out in append mode, so the system will keep writing new entries as long as it stays running or runs out of space. File is also automatically truncated on startup.

---
 security/integrity/ima/Kconfig     |  10 ++
 security/integrity/ima/ima.h       |   7 +-
 security/integrity/ima/ima_fs.c    | 178 +++++++++++++++++++++++++++++
 security/integrity/ima/ima_queue.c |   2 +-
 4 files changed, 192 insertions(+), 5 deletions(-)

I've been looking into a solution to this same issue you started some work on. I was wondering if you are still working on it. I was considering taking your initial prototyping on this and extending it into a final solution, but I wanted to reply here first and check if you are currently working on this.

From be120a15c8d81655bf112334e3279b19415c2ca2 Mon Sep 17 00:00:00 2001
From: Janne Karhunen <[email protected]>
Date: Mon, 16 Dec 2019 12:59:30 +0200
Subject: [PATCH v3] ima: allow the measurement list flush

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 free any amount of entries and handle the list export manually.

Changelog:
v3:
- Depend on the userspace doing the file export, only allow the list flush.

---
 security/integrity/ima/ima.h       |  6 +--
 security/integrity/ima/ima_fs.c    | 65 ++++++++++++++++++++++++++++++
 security/integrity/ima/ima_queue.c |  2 +-
 3 files changed, 68 insertions(+), 5 deletions(-)
security/integrity/ima/ima.h +2 -4
index 64317d95363e..821a0f1d832f 100644
@@ -153,6 +153,7 @@ int template_desc_init_fields(const char *template_fmt,
 struct ima_template_desc *ima_template_desc_current(void);
 struct ima_template_desc *lookup_template_desc(const char *name);
 bool ima_template_has_modsig(const struct ima_template_desc *ima_template);
+void ima_free_template_entry(struct ima_template_entry *entry);
 int ima_restore_measurement_entry(struct ima_template_entry *entry);
 int ima_restore_measurement_list(loff_t bufsize, void *buf);
 int ima_measurements_show(struct seq_file *m, void *v);
@@ -163,10 +164,7 @@ int __init ima_init_digests(void);
 int ima_lsm_policy_change(struct notifier_block *nb, unsigned long event,
 			  void *lsm_data);
 
-/*
- * used to protect h_table and sha_table
- */
-extern spinlock_t ima_queue_lock;
+extern struct mutex ima_extend_list_mutex;
 
 struct ima_h_table {
 	atomic_long_t len;	/* number of stored measurements in the list */
security/integrity/ima/ima_fs.c +65 -0

88 lines not on this page · raw message

security/integrity/ima/ima_queue.c +1 -1
index 8753212ddb18..4eee0bbf2647 100644
@@ -42,7 +42,7 @@ struct ima_h_table ima_htable = {
  * and extending the TPM PCR aggregate. Since tpm_extend can take
  * long (and the tpm driver uses a mutex), we can't use the spinlock.
  */
-static DEFINE_MUTEX(ima_extend_list_mutex);
+DEFINE_MUTEX(ima_extend_list_mutex);
 
 /* lookup up the digest value in the hash table, and return the entry */
 static struct ima_queue_entry *ima_lookup_digest_entry(u8 *digest_value,
Signature · 1 line
2.17.1
#4 lore raw

Hi,

Come to think of it, there could be a MM trap though as I'm not sure this has been done before. This new file vmarea would sit in the kernel virtual memory area somewhere above the page_offset and the mm code might assume that there is no need to look for dirty pages there when running the PTE scan. But that shouldn't be more than one line patch if that is the only trap..

--
Janne

Quoted 105 lines · Janne Karhunen

Hi,

Attached a variant of the patch from that time that only does the element free and relies on the userspace reading the data.

The reason why I stopped working on this at the time was that below was sufficient for my needs. However, after a discussion between Mimi and myself (based on a suggestion by Amir Goldstein) we realized that we could do something considerably more elegant through vfs_tmpfile. It's also much more work.

The way this could probably work the best is if we would implement a new allocator that would pull pages from a vmarea tied to a vfs_tmpfile and the file could be opened by the kernel itself during the ima init. Now if all the measurement list data blobs would be allocated through this allocator the pages would never be permanently resident in the kernel, they would only visit the memory for a while when someone reads the data. If done this way the allocator probably does not even need a 'free' and the mm code would do all the real work pushing the data out.

The benefits would be that no-one would ever have to poll from userspace (kernel does not depend on the userspace to work) and we would never OOM because of IMA as long as the filesystem is writable. Also we would never lose any data as long as the file system is functioning.

Thoughts?

--
Janne

Quoted 69 lines · Janne Karhunen

Hi Raphael,

Sorry I missed the reply. I'm not working on this right now, feel free to grab. Please copy me with the results, thank you.

--
Janne

Quoted 57 lines · Raphael Gianotti

Hi Janne,

Subject: Re: [RFC] ima: export the measurement list when needed

Quoted 23 lines

Date: Wed, 18 Dec 2019 17:11:22 +0200
From: Janne Karhunen <[email protected]>
To: [email protected], Mimi Zohar <[email protected]>
CC: Ken Goldman <[email protected]>, [email protected], [email protected]

Hi,

Have in mind that below is the first trial draft that booted and seemingly accomplished the task once, it was not really tested at all yet. I will make a polished and tested version if people like the concept.

Note that the code (almost) supports pushing and pulling of the entries. This variant is a simple pull given that the list size is above the defined limits. Pushing can be put in place if the recursion with the list extend_list_mutex is cleared, maybe this could be done via another patch later on when we have a workqueue for the export task? The workqueue might be the best context for the export job since clearing the list is a heavy operation (and it's not entirely correct here AFAIK, there is no rcu sync before the template free).

Quoted 22 lines

-- Janne

Quoted 18 lines · Janne Karhunen

Some systems can end up carrying lots of entries in the ima measurement list. Since every entry is using a bit of kernel memory, add a new Kconfig variable to allow the sysadmin to define the maximum measurement list size and the location of the exported list.

The list is written out in append mode, so the system will keep writing new entries as long as it stays running or runs out of space. File is also automatically truncated on startup.

---
 security/integrity/ima/Kconfig     |  10 ++
 security/integrity/ima/ima.h       |   7 +-
 security/integrity/ima/ima_fs.c    | 178 +++++++++++++++++++++++++++++
 security/integrity/ima/ima_queue.c |   2 +-
 4 files changed, 192 insertions(+), 5 deletions(-)

I've been looking into a solution to this same issue you started some work on. I was wondering if you are still working on it. I was considering taking your initial prototyping on this and extending it into a final solution, but I wanted to reply here first and check if you are currently working on this.

#5 lore raw

Hi Janne,

Thanks for your response, I didn't reply right away as I hadn't used mm and vmarea via vfs_tmpfile before, so I wanted to read some code to familiarize myself with it. Correct me if I am misunderstanding the approach you mentioned, but in it, we would still lose the logs accross kexec/cold boots as we do today, is that correct? It feels like this approach would solely solve the issue where we can potentially run out of memory for ima logs.

For the original approach, I have a prototype version that I intend to send as an RFC soon (I will link you and it's based off of your original RFC from late last year).

- Raphael

Quoted 114 lines · Janne Karhunen

Hi,

Come to think of it, there could be a MM trap though as I'm not sure this has been done before. This new file vmarea would sit in the kernel virtual memory area somewhere above the page_offset and the mm code might assume that there is no need to look for dirty pages there when running the PTE scan. But that shouldn't be more than one line patch if that is the only trap..

--
Janne

Quoted 100 lines · Janne Karhunen

Hi,

Attached a variant of the patch from that time that only does the element free and relies on the userspace reading the data.

The reason why I stopped working on this at the time was that below was sufficient for my needs. However, after a discussion between Mimi and myself (based on a suggestion by Amir Goldstein) we realized that we could do something considerably more elegant through vfs_tmpfile. It's also much more work.

The way this could probably work the best is if we would implement a new allocator that would pull pages from a vmarea tied to a vfs_tmpfile and the file could be opened by the kernel itself during the ima init. Now if all the measurement list data blobs would be allocated through this allocator the pages would never be permanently resident in the kernel, they would only visit the memory for a while when someone reads the data. If done this way the allocator probably does not even need a 'free' and the mm code would do all the real work pushing the data out.

The benefits would be that no-one would ever have to poll from userspace (kernel does not depend on the userspace to work) and we would never OOM because of IMA as long as the filesystem is writable. Also we would never lose any data as long as the file system is functioning.

Thoughts?

--
Janne

Quoted 65 lines · Janne Karhunen

Hi Raphael,

Sorry I missed the reply. I'm not working on this right now, feel free to grab. Please copy me with the results, thank you.

--
Janne

Quoted 54 lines · Raphael Gianotti

Hi Janne,

Subject: Re: [RFC] ima: export the measurement list when needed

Quoted 23 lines

Date: Wed, 18 Dec 2019 17:11:22 +0200
From: Janne Karhunen <[email protected]>
To: [email protected], Mimi Zohar <[email protected]>
CC: Ken Goldman <[email protected]>, [email protected], [email protected]

Hi,

Have in mind that below is the first trial draft that booted and seemingly accomplished the task once, it was not really tested at all yet. I will make a polished and tested version if people like the concept.

Note that the code (almost) supports pushing and pulling of the entries. This variant is a simple pull given that the list size is above the defined limits. Pushing can be put in place if the recursion with the list extend_list_mutex is cleared, maybe this could be done via another patch later on when we have a workqueue for the export task? The workqueue might be the best context for the export job since clearing the list is a heavy operation (and it's not entirely correct here AFAIK, there is no rcu sync before the template free).

Quoted 21 lines

-- Janne

Quoted 17 lines · Janne Karhunen

Some systems can end up carrying lots of entries in the ima measurement list. Since every entry is using a bit of kernel memory, add a new Kconfig variable to allow the sysadmin to define the maximum measurement list size and the location of the exported list.

The list is written out in append mode, so the system will keep writing new entries as long as it stays running or runs out of space. File is also automatically truncated on startup.

---
  security/integrity/ima/Kconfig     |  10 ++
  security/integrity/ima/ima.h       |   7 +-
  security/integrity/ima/ima_fs.c    | 178 +++++++++++++++++++++++++++++
  security/integrity/ima/ima_queue.c |   2 +-
  4 files changed, 192 insertions(+), 5 deletions(-)

I've been looking into a solution to this same issue you started some work on. I was wondering if you are still working on it. I was considering taking your initial prototyping on this and extending it into a final solution, but I wanted to reply here first and check if you are currently working on this.

#6 lore raw

Hi Raphael,

It depends how well you make it, if you do it right you would not lose them. If the pagefile has a readable format it should all be safe, right?

--
Janne

Quoted 132 lines · Raphael Gianotti

Hi Janne,

Thanks for your response, I didn't reply right away as I hadn't used mm and vmarea via vfs_tmpfile before, so I wanted to read some code to familiarize myself with it. Correct me if I am misunderstanding the approach you mentioned, but in it, we would still lose the logs accross kexec/cold boots as we do today, is that correct? It feels like this approach would solely solve the issue where we can potentially run out of memory for ima logs.

For the original approach, I have a prototype version that I intend to send as an RFC soon (I will link you and it's based off of your original RFC from late last year).

- Raphael

Quoted 114 lines · Janne Karhunen

Hi,

Come to think of it, there could be a MM trap though as I'm not sure this has been done before. This new file vmarea would sit in the kernel virtual memory area somewhere above the page_offset and the mm code might assume that there is no need to look for dirty pages there when running the PTE scan. But that shouldn't be more than one line patch if that is the only trap..

--
Janne

Quoted 100 lines · Janne Karhunen

Hi,

Attached a variant of the patch from that time that only does the element free and relies on the userspace reading the data.

The reason why I stopped working on this at the time was that below was sufficient for my needs. However, after a discussion between Mimi and myself (based on a suggestion by Amir Goldstein) we realized that we could do something considerably more elegant through vfs_tmpfile. It's also much more work.

The way this could probably work the best is if we would implement a new allocator that would pull pages from a vmarea tied to a vfs_tmpfile and the file could be opened by the kernel itself during the ima init. Now if all the measurement list data blobs would be allocated through this allocator the pages would never be permanently resident in the kernel, they would only visit the memory for a while when someone reads the data. If done this way the allocator probably does not even need a 'free' and the mm code would do all the real work pushing the data out.

The benefits would be that no-one would ever have to poll from userspace (kernel does not depend on the userspace to work) and we would never OOM because of IMA as long as the filesystem is writable. Also we would never lose any data as long as the file system is functioning.

Thoughts?

--
Janne

Quoted 65 lines · Janne Karhunen

Hi Raphael,

Sorry I missed the reply. I'm not working on this right now, feel free to grab. Please copy me with the results, thank you.

--
Janne

Quoted 54 lines · Raphael Gianotti

Hi Janne,

Subject: Re: [RFC] ima: export the measurement list when needed

Quoted 23 lines

Date: Wed, 18 Dec 2019 17:11:22 +0200
From: Janne Karhunen <[email protected]>
To: [email protected], Mimi Zohar <[email protected]>
CC: Ken Goldman <[email protected]>, [email protected], [email protected]

Hi,

Have in mind that below is the first trial draft that booted and seemingly accomplished the task once, it was not really tested at all yet. I will make a polished and tested version if people like the concept.

Note that the code (almost) supports pushing and pulling of the entries. This variant is a simple pull given that the list size is above the defined limits. Pushing can be put in place if the recursion with the list extend_list_mutex is cleared, maybe this could be done via another patch later on when we have a workqueue for the export task? The workqueue might be the best context for the export job since clearing the list is a heavy operation (and it's not entirely correct here AFAIK, there is no rcu sync before the template free).

Quoted 21 lines

-- Janne

Quoted 17 lines · Janne Karhunen

Some systems can end up carrying lots of entries in the ima measurement list. Since every entry is using a bit of kernel memory, add a new Kconfig variable to allow the sysadmin to define the maximum measurement list size and the location of the exported list.

The list is written out in append mode, so the system will keep writing new entries as long as it stays running or runs out of space. File is also automatically truncated on startup.

---
  security/integrity/ima/Kconfig     |  10 ++
  security/integrity/ima/ima.h       |   7 +-
  security/integrity/ima/ima_fs.c    | 178 +++++++++++++++++++++++++++++
  security/integrity/ima/ima_queue.c |   2 +-
  4 files changed, 192 insertions(+), 5 deletions(-)

I've been looking into a solution to this same issue you started some work on. I was wondering if you are still working on it. I was considering taking your initial prototyping on this and extending it into a final solution, but I wanted to reply here first and check if you are currently working on this.

#7 lore raw

Hi Janne,

As I mentioned previously I know very little about the approach you had mentioned. I read a little more on it and I think now I understand it a little better and yes, it should actually work.

 I will spend some time familiarizing myself with how this would work so I can actually compare both approaches myself on a technical level and have a more well informed opinion on the matter before moving on with either sending an RFC for the first approach (based on your code from last year) or starting some work using the new approach you brought up.

Thanks,

-Raphael

Quoted 142 lines · Janne Karhunen

Hi Raphael,

It depends how well you make it, if you do it right you would not lose them. If the pagefile has a readable format it should all be safe, right?

--
Janne

Quoted 130 lines · Raphael Gianotti

Hi Janne,

Thanks for your response, I didn't reply right away as I hadn't used mm and vmarea via vfs_tmpfile before, so I wanted to read some code to familiarize myself with it. Correct me if I am misunderstanding the approach you mentioned, but in it, we would still lose the logs accross kexec/cold boots as we do today, is that correct? It feels like this approach would solely solve the issue where we can potentially run out of memory for ima logs.

For the original approach, I have a prototype version that I intend to send as an RFC soon (I will link you and it's based off of your original RFC from late last year).

- Raphael

Quoted 113 lines · Janne Karhunen

Hi,

Come to think of it, there could be a MM trap though as I'm not sure this has been done before. This new file vmarea would sit in the kernel virtual memory area somewhere above the page_offset and the mm code might assume that there is no need to look for dirty pages there when running the PTE scan. But that shouldn't be more than one line patch if that is the only trap..

--
Janne

Quoted 99 lines · Janne Karhunen

Hi,

Attached a variant of the patch from that time that only does the element free and relies on the userspace reading the data.

The reason why I stopped working on this at the time was that below was sufficient for my needs. However, after a discussion between Mimi and myself (based on a suggestion by Amir Goldstein) we realized that we could do something considerably more elegant through vfs_tmpfile. It's also much more work.

The way this could probably work the best is if we would implement a new allocator that would pull pages from a vmarea tied to a vfs_tmpfile and the file could be opened by the kernel itself during the ima init. Now if all the measurement list data blobs would be allocated through this allocator the pages would never be permanently resident in the kernel, they would only visit the memory for a while when someone reads the data. If done this way the allocator probably does not even need a 'free' and the mm code would do all the real work pushing the data out.

The benefits would be that no-one would ever have to poll from userspace (kernel does not depend on the userspace to work) and we would never OOM because of IMA as long as the filesystem is writable. Also we would never lose any data as long as the file system is functioning.

Thoughts?

--
Janne

Quoted 64 lines · Janne Karhunen

Hi Raphael,

Sorry I missed the reply. I'm not working on this right now, feel free to grab. Please copy me with the results, thank you.

--
Janne

Quoted 53 lines · Raphael Gianotti

Hi Janne,

Subject: Re: [RFC] ima: export the measurement list when needed

Quoted 23 lines

Date: Wed, 18 Dec 2019 17:11:22 +0200
From: Janne Karhunen <[email protected]>
To: [email protected], Mimi Zohar <[email protected]>
CC: Ken Goldman <[email protected]>, [email protected], [email protected]

Hi,

Have in mind that below is the first trial draft that booted and seemingly accomplished the task once, it was not really tested at all yet. I will make a polished and tested version if people like the concept.

Note that the code (almost) supports pushing and pulling of the entries. This variant is a simple pull given that the list size is above the defined limits. Pushing can be put in place if the recursion with the list extend_list_mutex is cleared, maybe this could be done via another patch later on when we have a workqueue for the export task? The workqueue might be the best context for the export job since clearing the list is a heavy operation (and it's not entirely correct here AFAIK, there is no rcu sync before the template free).

Quoted 21 lines

-- Janne

Quoted 17 lines · Janne Karhunen

Some systems can end up carrying lots of entries in the ima measurement list. Since every entry is using a bit of kernel memory, add a new Kconfig variable to allow the sysadmin to define the maximum measurement list size and the location of the exported list.

The list is written out in append mode, so the system will keep writing new entries as long as it stays running or runs out of space. File is also automatically truncated on startup.

---
   security/integrity/ima/Kconfig     |  10 ++
   security/integrity/ima/ima.h       |   7 +-
   security/integrity/ima/ima_fs.c    | 178 +++++++++++++++++++++++++++++
   security/integrity/ima/ima_queue.c |   2 +-
   4 files changed, 192 insertions(+), 5 deletions(-)

I've been looking into a solution to this same issue you started some work on. I was wondering if you are still working on it. I was considering taking your initial prototyping on this and extending it into a final solution, but I wanted to reply here first and check if you are currently working on this.

#8 lore raw

Hi Raphael,

Thanks a lot. I understand it very well that the mm tricks surprise many. Moreover, I certainly understand that it might be over-engineering in the case it hits a trap with the mm, but the approach does have clear benefits in case it works (most importantly we would never use any kernel memory). Let's see what you come up with. Thanks again,

--
Janne

Quoted 160 lines · Raphael Gianotti

Hi Janne,

As I mentioned previously I know very little about the approach you had mentioned. I read a little more on it and I think now I understand it a little better and yes, it should actually work.

I will spend some time familiarizing myself with how this would work
so I can actually compare both approaches myself on a technical level and have a more well informed opinion on the matter before moving on with either sending an RFC for the first approach (based on your code from last year) or starting some work using the new approach you brought up.

Thanks,

-Raphael

Quoted 142 lines · Janne Karhunen

Hi Raphael,

It depends how well you make it, if you do it right you would not lose them. If the pagefile has a readable format it should all be safe, right?

--
Janne

Quoted 130 lines · Raphael Gianotti

Hi Janne,

Thanks for your response, I didn't reply right away as I hadn't used mm and vmarea via vfs_tmpfile before, so I wanted to read some code to familiarize myself with it. Correct me if I am misunderstanding the approach you mentioned, but in it, we would still lose the logs accross kexec/cold boots as we do today, is that correct? It feels like this approach would solely solve the issue where we can potentially run out of memory for ima logs.

For the original approach, I have a prototype version that I intend to send as an RFC soon (I will link you and it's based off of your original RFC from late last year).

- Raphael

Quoted 113 lines · Janne Karhunen

Hi,

Come to think of it, there could be a MM trap though as I'm not sure this has been done before. This new file vmarea would sit in the kernel virtual memory area somewhere above the page_offset and the mm code might assume that there is no need to look for dirty pages there when running the PTE scan. But that shouldn't be more than one line patch if that is the only trap..

--
Janne

Quoted 99 lines · Janne Karhunen

Hi,

Attached a variant of the patch from that time that only does the element free and relies on the userspace reading the data.

The reason why I stopped working on this at the time was that below was sufficient for my needs. However, after a discussion between Mimi and myself (based on a suggestion by Amir Goldstein) we realized that we could do something considerably more elegant through vfs_tmpfile. It's also much more work.

The way this could probably work the best is if we would implement a new allocator that would pull pages from a vmarea tied to a vfs_tmpfile and the file could be opened by the kernel itself during the ima init. Now if all the measurement list data blobs would be allocated through this allocator the pages would never be permanently resident in the kernel, they would only visit the memory for a while when someone reads the data. If done this way the allocator probably does not even need a 'free' and the mm code would do all the real work pushing the data out.

The benefits would be that no-one would ever have to poll from userspace (kernel does not depend on the userspace to work) and we would never OOM because of IMA as long as the filesystem is writable. Also we would never lose any data as long as the file system is functioning.

Thoughts?

--
Janne

Quoted 64 lines · Janne Karhunen

Hi Raphael,

Sorry I missed the reply. I'm not working on this right now, feel free to grab. Please copy me with the results, thank you.

--
Janne

Quoted 53 lines · Raphael Gianotti

Hi Janne,

Subject: Re: [RFC] ima: export the measurement list when needed

Quoted 23 lines

Date: Wed, 18 Dec 2019 17:11:22 +0200
From: Janne Karhunen <[email protected]>
To: [email protected], Mimi Zohar <[email protected]>
CC: Ken Goldman <[email protected]>, [email protected], [email protected]

Hi,

Have in mind that below is the first trial draft that booted and seemingly accomplished the task once, it was not really tested at all yet. I will make a polished and tested version if people like the concept.

Note that the code (almost) supports pushing and pulling of the entries. This variant is a simple pull given that the list size is above the defined limits. Pushing can be put in place if the recursion with the list extend_list_mutex is cleared, maybe this could be done via another patch later on when we have a workqueue for the export task? The workqueue might be the best context for the export job since clearing the list is a heavy operation (and it's not entirely correct here AFAIK, there is no rcu sync before the template free).

Quoted 21 lines

-- Janne

Quoted 17 lines · Janne Karhunen

Some systems can end up carrying lots of entries in the ima measurement list. Since every entry is using a bit of kernel memory, add a new Kconfig variable to allow the sysadmin to define the maximum measurement list size and the location of the exported list.

The list is written out in append mode, so the system will keep writing new entries as long as it stays running or runs out of space. File is also automatically truncated on startup.

---
   security/integrity/ima/Kconfig     |  10 ++
   security/integrity/ima/ima.h       |   7 +-
   security/integrity/ima/ima_fs.c    | 178 +++++++++++++++++++++++++++++
   security/integrity/ima/ima_queue.c |   2 +-
   4 files changed, 192 insertions(+), 5 deletions(-)

I've been looking into a solution to this same issue you started some work on. I was wondering if you are still working on it. I was considering taking your initial prototyping on this and extending it into a final solution, but I wanted to reply here first and check if you are currently working on this.