Skip to contentSkip to conversation

initramfs with digital signature protection

RFC In review Dmitry Kasatkin 8 participants 41 messages Feb 5, 2013 – Apr 12, 2013 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover initramfs with digital signature protection

This an RFC for the signed initramfs images, which can be used to provide verified initial user-space. Please read patch description for the detailed explanation.

BR,
Dmitry

Dmitry Kasatkin (2):
export unpack_to_rootfs
initramfs with digital signature protection

 init/Kconfig         |    7 +++
 init/Makefile        |    1 +
 init/do_mounts.h     |   12 ++++
 init/initramfs.c     |    2 +-
 init/initramfs_sig.c |  171 ++++++++++++++++++++++++++++++++++++++++++++++++++
 init/main.c          |    4 ++
 6 files changed, 196 insertions(+), 1 deletion(-)
 create mode 100644 init/initramfs_sig.c
Signature · 1 line
1.7.10.4
#1 lore raw

RFC 1/2 export unpack_to_rootfs

---
 init/do_mounts.h |    2 ++
 init/initramfs.c |    2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
init/do_mounts.h +2 -0
index f5b978a..11829eb 100644
@@ -74,3 +74,5 @@ void md_run_setup(void);
 static inline void md_run_setup(void) {}
 
 #endif
+
+char * __init unpack_to_rootfs(char *buf, unsigned len);
init/initramfs.c +1 -1
index 84c6bf1..e32bc06 100644
@@ -421,7 +421,7 @@ static unsigned my_inptr;   /* index of next byte to be processed in inbuf */
 
 #include <linux/decompress/generic.h>
 
-static char * __init unpack_to_rootfs(char *buf, unsigned len)
+char * __init unpack_to_rootfs(char *buf, unsigned len)
 {
 	int written, res;
 	decompress_fn decompress;
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [RFC 1/2] export unpack_to_rootfs

Quoted 21 lines · Dmitry Kasatkin
---
 init/do_mounts.h |    2 ++
 init/initramfs.c |    2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
init/do_mounts.h +2 -0
index f5b978a..11829eb 100644
@@ -74,3 +74,5 @@ void md_run_setup(void);
 static inline void md_run_setup(void) {}
 
 #endif
+
+char * __init unpack_to_rootfs(char *buf, unsigned len);
init/initramfs.c +0 -0
index 84c6bf1..e32bc06 100644

init/initramfs.c static unsigned my_inptr; /* index of next byte to be processed in inbuf */ · line 427

Quoted 8 lines
init/initramfs.c +1 -1
@@ -421,7 +421,7 @@ static unsigned my_inptr;   /* index of next byte to be processed in inbuf */
 
 #include <linux/decompress/generic.h>
 
-static char * __init unpack_to_rootfs(char *buf, unsigned len)
+char * __init unpack_to_rootfs(char *buf, unsigned len)
 {
 	int written, res;
 	decompress_fn decompress;

Doing this unconditionally seems to be inviting rootkit authors to use a new and shiny tool. I also don't think it's the best way to do this, but I'll comment on the other patch to explain why.

Signature · 1 line
        Peter
#3 lore raw

Re: [RFC 1/2] export unpack_to_rootfs

Quoted 25 lines · Peter Jones
Quoted 24 lines · Dmitry Kasatkin
---
 init/do_mounts.h |    2 ++
 init/initramfs.c |    2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
init/do_mounts.h +2 -0
index f5b978a..11829eb 100644
@@ -74,3 +74,5 @@ void md_run_setup(void);
 static inline void md_run_setup(void) {}
 
 #endif
+
+char * __init unpack_to_rootfs(char *buf, unsigned len);
init/initramfs.c +0 -0
index 84c6bf1..e32bc06 100644
@@ -421,7 +421,7 @@ static unsigned my_inptr;   /* index of next byte to be processed in inbuf */
 
 #include <linux/decompress/generic.h>
 
Quoted 10 lines

init/initramfs.c static unsigned my_inptr; /* index of next byte to be processed in inbuf */ · line 427

Quoted 5 lines
init/initramfs.c +1 -1
-static char * __init unpack_to_rootfs(char *buf, unsigned len)
+char * __init unpack_to_rootfs(char *buf, unsigned len)
 {
      int written, res;
      decompress_fn decompress;

Doing this unconditionally seems to be inviting rootkit authors to use a new and shiny tool. I also don't think it's the best way to do this, but I'll comment on the other patch to explain why.

Sorry for re-post, but answering from mobile was in HTML and it was blocked. Modifying an initramfs gives the same opportunity during boot only. But agreed, it might be the part of the primary source code. It was very to do it in this way to implement and test a solution.

Thanks.

Quoted 2 lines

--
Peter

#4 lore raw

Re: [RFC 1/2] export unpack_to_rootfs

Quoted 26 lines · Dmitry
Quoted 25 lines · Peter Jones
Quoted 24 lines · Dmitry Kasatkin
---
 init/do_mounts.h |    2 ++
 init/initramfs.c |    2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
init/do_mounts.h +2 -0
index f5b978a..11829eb 100644
@@ -74,3 +74,5 @@ void md_run_setup(void);
 static inline void md_run_setup(void) {}
 
 #endif
+
+char * __init unpack_to_rootfs(char *buf, unsigned len);
init/initramfs.c +0 -0
index 84c6bf1..e32bc06 100644
@@ -421,7 +421,7 @@ static unsigned my_inptr;   /* index of next byte to be processed in inbuf */
 
 #include <linux/decompress/generic.h>
 
Quoted 11 lines
Quoted 10 lines

init/initramfs.c static unsigned my_inptr; /* index of next byte to be processed in inbuf */ · line 427

Quoted 5 lines
init/initramfs.c +1 -1
-static char * __init unpack_to_rootfs(char *buf, unsigned len)
+char * __init unpack_to_rootfs(char *buf, unsigned len)
 {
      int written, res;
      decompress_fn decompress;

Doing this unconditionally seems to be inviting rootkit authors to use a new and shiny tool. I also don't think it's the best way to do this, but I'll comment on the other patch to explain why.

Just wanted to point out, that there is no chance for rootkits in anyway because of this:

1) "rootkits" can have unpacking functionality inside, but if they are so lazy
2) unpack_to_rootfs() is not EXPORT_SYMBOLed.
3) and more over, unpack_to_rootfs() is "__init" and is freed before main initramfs or rootfs init is executed.

- Dmitry

Quoted 9 lines

Sorry for re-post, but answering from mobile was in HTML and it was blocked. Modifying an initramfs gives the same opportunity during boot only. But agreed, it might be the part of the primary source code. It was very to do it in this way to implement and test a solution.

Thanks.

Quoted 2 lines

--
Peter

#5 lore raw

RFC 2/2 initramfs with digital signature protection

In reply to Dmitry Kasatkin

Often initramfs is (re)fabricated on the machine on which it runs. In such cases it is impossible to sign initramfs image, because private key is not supposed to be available.

This patch adds support for additional digitaly signed initramfs images. Digitaly signed initramfs image can be loaded from conventional initramfs image or from rootfs and '/pre-init' is executed prior 'init' from initramfs or root file system. If 'pre-init' fails, kernel panics. Signed initramfs image must be located in '/initramfs-sig.img'.

Digitally signed initramfs can be used to provide protected user-space environment for initialization purpose. For example, LSM, IMA/EVM can be securely initialized using such approach.

Signing is done using scripts/sign-file from kernel source code and uses module signature format and module verification API. Important to note again that signing of such images should be done on the build machine.

Bellow is an example, how to sign compressed initrd (cpio) image:

scripts/sign-file -v signing_key.priv signing_key.x509 initrd.gz initramfs-sig.img

When using initramfs-tools, initramfs-sig.img can be easily included into the conventional initramfs using initramfs-tools hooks, for example, by creating /etc/initramfs-tools/hooks/initramfs_sig.sh, and adding following lines there:

#!/bin/sh
. /usr/share/initramfs-tools/hook-functions
copy_exec /initramfs-sig.img

---
 init/Kconfig         |    7 +++
 init/Makefile        |    1 +
 init/do_mounts.h     |   10 +++
 init/initramfs_sig.c |  171 ++++++++++++++++++++++++++++++++++++++++++++++++++
 init/main.c          |    4 ++
 5 files changed, 193 insertions(+)
 create mode 100644 init/initramfs_sig.c
init/Kconfig +7 -0
index 7d30240..fca6f47 100644
@@ -1738,4 +1738,11 @@ config ASN1
 	  inform it as to what tags are to be expected in a stream and what
 	  functions to call on what tags.
 
+config INITRAMFS_SIG
+	bool "initramfs with digital signature protection"
+	depends on INTEGRITY_ASYMMETRIC_KEYS
+	default n
+	help
+	  This option enables initramfs with digital signature protection.
+
 source "kernel/Kconfig.locks"
init/Makefile +1 -0
index 7bc47ee..0099169 100644
@@ -7,6 +7,7 @@ ifneq ($(CONFIG_BLK_DEV_INITRD),y)
 obj-y                          += noinitramfs.o
 else
 obj-$(CONFIG_BLK_DEV_INITRD)   += initramfs.o
+obj-$(CONFIG_INITRAMFS_SIG)   += initramfs_sig.o
 endif
 obj-$(CONFIG_GENERIC_CALIBRATE_DELAY) += calibrate.o
 
init/do_mounts.h +10 -0
index 11829eb..113207f 100644
@@ -76,3 +76,13 @@ static inline void md_run_setup(void) {}
 #endif
 
 char * __init unpack_to_rootfs(char *buf, unsigned len);
+
+#ifdef CONFIG_INITRAMFS_SIG
+
+int __init initramfs_sig_load(void);
+
+#else
+
+static inline int initramfs_sig_load(void) { return 0; }
+
+#endif
init/initramfs_sig.c new file +171 -0

171 lines not on this page · raw message

init/main.c +4 -0
index 85d69df..43ef145 100644
@@ -81,6 +81,8 @@
 #include <asm/smp.h>
 #endif
 
+#include "do_mounts.h"
+
 static int kernel_init(void *);
 
 extern void init_IRQ(void);
@@ -895,6 +897,8 @@ static void __init kernel_init_freeable(void)
 		prepare_namespace();
 	}
 
+	initramfs_sig_load();
+
 	/*
 	 * Ok, we have completed the initial bootup, and
 	 * we're essentially up and running. Get rid of the
Signature · 1 line
1.7.10.4
#6 lore raw
Quoted 3 lines · Dmitry Kasatkin

Often initramfs is (re)fabricated on the machine on which it runs. In such cases it is impossible to sign initramfs image, because private key is not supposed to be available.

This doesn't address that problem at all.

Quoted 5 lines

This patch adds support for additional digitaly signed initramfs images. Digitaly signed initramfs image can be loaded from conventional initramfs image or from rootfs and '/pre-init' is executed prior 'init' from initramfs or root file system. If 'pre-init' fails, kernel panics. Signed initramfs image must be located in '/initramfs-sig.img'.

So with this patch, you've effectively combined an unchecked initramfs with a checked one that loads before it, and called the answer "secure". This is like S&P traunching a AAA mortgage with a DDD mortgage and calling it a AAA CDO - the result isn't as good as what's claimed.

Quoted 11 lines

Digitally signed initramfs can be used to provide protected user-space environment for initialization purpose. For example, LSM, IMA/EVM can be securely initialized using such approach.

Signing is done using scripts/sign-file from kernel source code and uses module signature format and module verification API. Important to note again that signing of such images should be done on the build machine.

Bellow is an example, how to sign compressed initrd (cpio) image:

scripts/sign-file -v signing_key.priv signing_key.x509 initrd.gz initramfs-sig.img

This means that if you've got multiple initramfs images, there's a signature interleaved between them in the in-memory representation. We've used separate images to separate invariant bits from e.g. plymouth from the initramfs that's generated for each new kernel installed. In general, it'd be nice to keep multiple initramfs images working.

It's not clear to me why we need this encapsulation - wouldn't it be better to add another [pointer,size] pair to the bootloader protocol with a structure like:

struct {
	void *initramfs_area;
	size_t initramfs_area_len;
	void *signature;
	size_t signature_len;
};

And make that a list (all fields zero signifying the end). That way we can a) continue to easily support multiple initramfs images, b) allow for /the whole initramfs to be checked/, which would be useful for e.g. distro media? If we really need a "parts of this are checked and parts aren't" system, you could still allow policy to support that, but it's not clear to me why that's a useful thing to have.

init/main.c static void __init kernel_init_freeable(void) · line 904

Quoted 9 lines
init/main.c +2 -0
@@ -895,6 +897,8 @@ static void __init kernel_init_freeable(void)
 		prepare_namespace();
 	}
 
+	initramfs_sig_load();
+
 	/*
 	 * Ok, we have completed the initial bootup, and
 	 * we're essentially up and running. Get rid of the

At the very least, this call should go in kernel_init() so that it's logically after the comment you trimmed here about how we're about to start userland running.

Signature · 1 line
        Peter
#7 lore raw
Quoted 3 lines · Peter Jones

It's not clear to me why we need this encapsulation - wouldn't it be better to add another [pointer,size] pair to the bootloader protocol with a structure like:

https://lkml.org/lkml/2013/1/30/68 was in response to the assumption that the initramfs is measured/appraised. These patches attempt to address those concerns.

Mimi

#8 lore raw
In reply to Peter Jones
Quoted 7 lines · Peter Jones
Quoted 3 lines · Dmitry Kasatkin

Often initramfs is (re)fabricated on the machine on which it runs. In such cases it is impossible to sign initramfs image, because private key is not supposed to be available.

This doesn't address that problem at all.

Does not address what?

Quoted 11 lines
Quoted 5 lines

This patch adds support for additional digitaly signed initramfs images. Digitaly signed initramfs image can be loaded from conventional initramfs image or from rootfs and '/pre-init' is executed prior 'init' from initramfs or root file system. If 'pre-init' fails, kernel panics. Signed initramfs image must be located in '/initramfs-sig.img'.

So with this patch, you've effectively combined an unchecked initramfs with a checked one that loads before it, and called the answer "secure". This is like S&P traunching a AAA mortgage with a DDD mortgage and calling it a AAA CDO - the result isn't as good as what's claimed.

This is absolutely wrong example. I do not understand your point at all. Signed image is loaded, verified and executed before any content from unsigned. What is the problem here?

Quoted 10 lines
Quoted 10 lines

Digitally signed initramfs can be used to provide protected user-space environment for initialization purpose. For example, LSM, IMA/EVM can be securely initialized using such approach.

Signing is done using scripts/sign-file from kernel source code and uses module signature format and module verification API. Important to note again that signing of such images should be done on the build machine.

Bellow is an example, how to sign compressed initrd (cpio) image:

Quoted 7 lines
Quoted 1 line

scripts/sign-file -v signing_key.priv signing_key.x509 initrd.gz initramfs-sig.img

This means that if you've got multiple initramfs images, there's a signature interleaved between them in the in-memory representation. We've used separate images to separate invariant bits from e.g. plymouth from the initramfs that's generated for each new kernel installed. In general, it'd be nice to keep multiple initramfs images working.

I cannot get you.
There are multiple inittamfs images. But in addition, there is a signed image, which contains
special stuff to initialize secure bits of the platform. After that, LSM or IMA/EVM could do its job.

Quoted 5 lines

It's not clear to me why we need this encapsulation - wouldn't it be better to add another [pointer,size] pair to the bootloader protocol with a structure like:

Quoted 7 lines
struct {
        void *initramfs_area;
        size_t initramfs_area_len;
        void *signature;
        size_t signature_len;
};

Yes, it can be done in this way as well. I wanted to get fast working solution to have a discussion
and ideas.

Quoted 11 lines

And make that a list (all fields zero signifying the end). That way we can a) continue to easily support multiple initramfs images, b) allow for /the whole initramfs to be checked/, which would be useful for e.g. distro media? If we really need a "parts of this are checked and parts aren't" system, you could still allow policy to support that, but it's not clear to me why that's a useful thing to have.

Quoted 4 lines
init/main.c +0 -0
@@ -895,6 +897,8 @@ static void __init kernel_init_freeable(void)
              prepare_namespace();
      }
 
Quoted 9 lines

init/main.c static void __init kernel_init_freeable(void) · line 904

Quoted 5 lines
init/main.c +2 -0
+     initramfs_sig_load();
+
      /*
       * Ok, we have completed the initial bootup, and
       * we're essentially up and running. Get rid of the

At the very least, this call should go in kernel_init() so that it's logically after the comment you trimmed here about how we're about to start userland running.

Yes. it is possible to call it before free_initmem()...

Thanks,
Dmitry

Quoted 7 lines

--
Peter
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw
In reply to Dmitry Kasatkin
Quoted 3 lines · Dmitry Kasatkin

Digitally signed initramfs can be used to provide protected user-space environment for initialization purpose. For example, LSM, IMA/EVM can be securely initialized using such approach.

What stops an attacker from simply removing the signed image from the initramfs and running modified versions of the same tools from the unsigned image?

Signature · 1 line
Matthew Garrett | [email protected]
#10 lore raw
Quoted 9 lines · Matthew Garrett
Quoted 3 lines · Dmitry Kasatkin

Digitally signed initramfs can be used to provide protected user-space environment for initialization purpose. For example, LSM, IMA/EVM can be securely initialized using such approach.

What stops an attacker from simply removing the signed image from the initramfs and running modified versions of the same tools from the unsigned image?

I'm sorry, ignore that - if the kernel's configured to do this, it'll panic if it can't find the signed image. Ok.

Signature · 1 line
Matthew Garrett | [email protected]
#11 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 3 lines · Dmitry Kasatkin

Digitally signed initramfs can be used to provide protected user-space environment for initialization purpose. For example, LSM, IMA/EVM can be securely initialized using such approach.

What stops an attacker from simply removing the signed image from the initramfs and running modified versions of the same tools from the unsigned image?

Looks like having signed initramfs image is mandatory otherwise system panics.

+ if (sys_access(initramfs_img, 0))
+ panic("signed initramfs image not found (INITRAMFS_SIG is
+anabled)\n");

Also I am assuming that from signed initramfs, keys will be loaded in appropriate keyrings and then keyring will be locked so that any tools from unsigned initramfs can not load additional keys.

Thanks
Vivek

#12 lore raw
Quoted 18 lines · Vivek Goyal
Quoted 9 lines · Matthew Garrett
Quoted 3 lines · Dmitry Kasatkin

Digitally signed initramfs can be used to provide protected user-space environment for initialization purpose. For example, LSM, IMA/EVM can be securely initialized using such approach.

What stops an attacker from simply removing the signed image from the initramfs and running modified versions of the same tools from the unsigned image?

Looks like having signed initramfs image is mandatory otherwise system panics.

(quoted diff) +3 -0
+       if (sys_access(initramfs_img, 0))
+               panic("signed initramfs image not found (INITRAMFS_SIG is
+anabled)\n");
Quoted 4 lines

Also I am assuming that from signed initramfs, keys will be loaded in appropriate keyrings and then keyring will be locked so that any tools from unsigned initramfs can not load additional keys.

Exactly like that.

Quoted 6 lines

Thanks
Vivek
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

On Tue, Feb 05, 2013 at 11:55:09PM +0200, Kasatkin, Dmitry wrote:

[..]

Quoted 6 lines
Quoted 4 lines

Also I am assuming that from signed initramfs, keys will be loaded in appropriate keyrings and then keyring will be locked so that any tools from unsigned initramfs can not load additional keys.

Exactly like that.

Dmitry,

[ Following up on this thread after a very long time ]

I was thinking about this point that keys can be loaded from signed initramfs. But how is it better than embedding the keys in kernel the way we do for module signing and lock down ima keyring before control is passed to initramfs.

Reason being, that anyway a user can not put its own keys in signed initramfs. Signed initramfs will be shipped by distribution. So then it does not matter whether distribution's keys are embedded in the kernel or are loaded from signed initramfs.

Thanks
Vivek

#14 lore raw
Quoted 19 lines · Vivek Goyal

On Tue, Feb 05, 2013 at 11:55:09PM +0200, Kasatkin, Dmitry wrote:

[..]

Quoted 6 lines
Quoted 4 lines

Also I am assuming that from signed initramfs, keys will be loaded in appropriate keyrings and then keyring will be locked so that any tools from unsigned initramfs can not load additional keys.

Exactly like that.

Dmitry,

[ Following up on this thread after a very long time ]

I was thinking about this point that keys can be loaded from signed initramfs. But how is it better than embedding the keys in kernel the way we do for module signing and lock down ima keyring before control is passed to initramfs.

Quoted 4 lines

Reason being, that anyway a user can not put its own keys in signed initramfs. Signed initramfs will be shipped by distribution. So then it does not matter whether distribution's keys are embedded in the kernel or are loaded from signed initramfs.

Although both the early initramfs and the kernel are signed, building the keys into the kernel implies a static set of predefined public keys, while the initramfs could load, in addition to the distro keys, keys from the UEFI databases. (Refer to James Bottomley's post on efivarfs.) If distro's would sign such an early initramfs, it would allow users to add their own keys in a safe and secure manner, without requiring them to rebuild the kernel.

Mimi

#15 lore raw
Quoted 25 lines · Mimi Zohar
Quoted 19 lines · Vivek Goyal

On Tue, Feb 05, 2013 at 11:55:09PM +0200, Kasatkin, Dmitry wrote:

[..]

Quoted 6 lines
Quoted 4 lines

Also I am assuming that from signed initramfs, keys will be loaded in appropriate keyrings and then keyring will be locked so that any tools from unsigned initramfs can not load additional keys.

Exactly like that.

Dmitry,

[ Following up on this thread after a very long time ]

I was thinking about this point that keys can be loaded from signed initramfs. But how is it better than embedding the keys in kernel the way we do for module signing and lock down ima keyring before control is passed to initramfs.

Quoted 4 lines

Reason being, that anyway a user can not put its own keys in signed initramfs. Signed initramfs will be shipped by distribution. So then it does not matter whether distribution's keys are embedded in the kernel or are loaded from signed initramfs.

Quoted 4 lines

Although both the early initramfs and the kernel are signed, building the keys into the kernel implies a static set of predefined public keys, while the initramfs could load, in addition to the distro keys, keys from the UEFI databases.

Kernel already loads all the keys from UEFI database and MOK into module keyring.

So that can be true for IMA too. A user can add its keys to UEFI database or MOK and reboot the system and those keys should show up in kernel keyring.

In addition any keys embedded in kernel at build time will be loaded too.

Quoted 1 line

(Refer to James Bottomley's post on efivarfs.)

Are you referring to following link.

http://blog.hansenpartnership.com/efitools-1-4-with-linux-key-manipulation-utilities-released/

This one seems to be talking about tools for adding your own keys to UEFI database if one has PK and KEK.

Quoted 4 lines

If distro's would sign such an early initramfs, it would allow users to add their own keys in a safe and secure manner, without requiring them to rebuild the kernel.

Sorry, I did not understand this part. Even if user adds its own keys in UEFI database (using efivarfs filesystem), it does not require rebuiling kernel. Over next reboot these keys should show up in kernel keyring. So does not look like we will gain anything by creating a signed initramfs.

Thanks
Vivek

#16 lore raw
Quoted 26 lines · Vivek Goyal
Quoted 25 lines · Mimi Zohar
Quoted 23 lines · Vivek Goyal

On Tue, Feb 05, 2013 at 11:55:09PM +0200, Kasatkin, Dmitry wrote:

[..]

Quoted 6 lines
Quoted 4 lines

Also I am assuming that from signed initramfs, keys will be loaded in appropriate keyrings and then keyring will be locked so that any tools from unsigned initramfs can not load additional keys.

Exactly like that.

Dmitry,

[ Following up on this thread after a very long time ]

I was thinking about this point that keys can be loaded from signed initramfs. But how is it better than embedding the keys in kernel the way we do for module signing and lock down ima keyring before control is passed to initramfs.

Reason being, that anyway a user can not put its own keys in signed initramfs. Signed initramfs will be shipped by distribution. So then it does not matter whether distribution's keys are embedded in the kernel or are loaded from signed initramfs.

Quoted 7 lines
Quoted 4 lines

Although both the early initramfs and the kernel are signed, building the keys into the kernel implies a static set of predefined public keys, while the initramfs could load, in addition to the distro keys, keys from the UEFI databases.

Kernel already loads all the keys from UEFI database and MOK into module keyring.

Small point of order: there are patches to allow the kernel to do this. None of those patches are upstream.

josh

#17 lore raw

On Mon, Apr 08, 2013 at 04:17:56PM -0400, Josh Boyer wrote:

[..]

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 9 lines

I was thinking about this point that keys can be loaded from signed initramfs. But how is it better than embedding the keys in kernel the way we do for module signing and lock down ima keyring before control is passed to initramfs.

Reason being, that anyway a user can not put its own keys in signed initramfs. Signed initramfs will be shipped by distribution. So then it does not matter whether distribution's keys are embedded in the kernel or are loaded from signed initramfs.

Although both the early initramfs and the kernel are signed, building the keys into the kernel implies a static set of predefined public keys, while the initramfs could load, in addition to the distro keys, keys from the UEFI databases.

Quoted 5 lines
Quoted 2 lines

Kernel already loads all the keys from UEFI database and MOK into module keyring.

Small point of order: there are patches to allow the kernel to do this. None of those patches are upstream.

Ok, thanks Josh. We had been talking about copying all the UEFI keys (including dbx) and MOK keys, so I assumed that patches already went in.

So assuming all that will go in kernel (as it is required for module signature too), does not look like we will benefit from signed initramfs.

Thanks
Vivek

#18 lore raw
Quoted 21 lines · Vivek Goyal

On Mon, Apr 08, 2013 at 04:17:56PM -0400, Josh Boyer wrote:

[..]

Quoted 18 lines
Quoted 17 lines
Quoted 10 lines
Quoted 9 lines

I was thinking about this point that keys can be loaded from signed initramfs. But how is it better than embedding the keys in kernel the way we do for module signing and lock down ima keyring before control is passed to initramfs.

Reason being, that anyway a user can not put its own keys in signed initramfs. Signed initramfs will be shipped by distribution. So then it does not matter whether distribution's keys are embedded in the kernel or are loaded from signed initramfs.

Quoted 4 lines

Although both the early initramfs and the kernel are signed, building the keys into the kernel implies a static set of predefined public keys, while the initramfs could load, in addition to the distro keys, keys from the UEFI databases.

Kernel already loads all the keys from UEFI database and MOK into module keyring.

Quoted 8 lines
Quoted 2 lines

Small point of order: there are patches to allow the kernel to do this. None of those patches are upstream.

Ok, thanks Josh. We had been talking about copying all the UEFI keys (including dbx) and MOK keys, so I assumed that patches already went in.

So assuming all that will go in kernel (as it is required for module signature too), does not look like we will benefit from signed initramfs.

The module keyring is a special case. Loading these keys from the kernel and, presumably, locking the keyring is probably fine. In the case of IMA, however, files will be signed by any number of package owners. If the _ima keyring is locked by the kernel, how would you add these other keys?

thanks,

Mimi

#19 lore raw

On Tue, Apr 09, 2013 at 11:07:10PM -0400, Mimi Zohar wrote:

[..]

Quoted 5 lines

The module keyring is a special case. Loading these keys from the kernel and, presumably, locking the keyring is probably fine. In the case of IMA, however, files will be signed by any number of package owners. If the _ima keyring is locked by the kernel, how would you add these other keys?

Who are package owners here. IOW, in typical IMA setup, where are the keys and when are these keys loaded in ima keyring?

If we trust root and keys can be loaded any time later, then signed initramfs will not solve the problem either.

So this boils down to again not trusting root. So secureboot will not trust root and IMA does.

May be we need an additional IMA keyring which gets locked by kernel (like module keyring). And during signing, we need to encode keyring info in file signatuer. IMA will parse keyring info and try to verify signature against that specified keyring.

/sbin/kexec signing can happen in such a way that we tell IMA to verify against this locked keyring say, ima_kernel.

And in regular ima keyring, root can continue to load its own keys in usual way even in secureboot mode.

Just that sys_kexec() will have to call into IMA to make sure that /sbin/kexec's integrity was verified using keys in ima_kernel keyring and not using keys in _ima keyring.

IOW, apart from integrity results, we will have to store the keyring info too in results which should be queryable by the client. And then client can decide how to interpret integrity results.

Or we can just export the APIs from IMA (which don't do any caching) and client can specify keyring to verify against as a parameter.

Thoughts?

Thanks
Vivek

#20 lore raw
Quoted 11 lines · Vivek Goyal

On Tue, Apr 09, 2013 at 11:07:10PM -0400, Mimi Zohar wrote:

[..]

Quoted 5 lines

The module keyring is a special case. Loading these keys from the kernel and, presumably, locking the keyring is probably fine. In the case of IMA, however, files will be signed by any number of package owners. If the _ima keyring is locked by the kernel, how would you add these other keys?

Who are package owners here. IOW, in typical IMA setup, where are the keys and when are these keys loaded in ima keyring?

Suppose I install third party packages not signed by the distro, but by the package owner (eg. google, rpmfusion, ...). Not only does the package signature need to be verified on installation, but the files need to be installed with signatures. For IMA to enforce file integrity, the package owner's public key needs to be added to the _ima keyring.

Quoted 2 lines

If we trust root and keys can be loaded any time later, then signed initramfs will not solve the problem either.

Locking the keyring in the kernel will limit the set of permitted keys to only those specified in UEFI db or builtin. Locking the keyring in the "early" initramfs, will allow the system owner, whose key is in the UEFI db, to specify additional keys, such as those for third party packages. Not all public keys belong in the UEFI db.

Mimi

#21 lore raw

Hello,

(in plain text)

I respond to the original question of this thread. signed initramfs allows not only to add keys to the keyrings but perform other initialization,
which requires user-space.
Keys can be embedded into the kernel. This is fine.

Regards

- Dmitry

Quoted 35 lines · Mimi Zohar
Quoted 11 lines · Vivek Goyal

On Tue, Apr 09, 2013 at 11:07:10PM -0400, Mimi Zohar wrote:

[..]

Quoted 5 lines

The module keyring is a special case. Loading these keys from the kernel and, presumably, locking the keyring is probably fine. In the case of IMA, however, files will be signed by any number of package owners. If the _ima keyring is locked by the kernel, how would you add these other keys?

Who are package owners here. IOW, in typical IMA setup, where are the keys and when are these keys loaded in ima keyring?

Suppose I install third party packages not signed by the distro, but by the package owner (eg. google, rpmfusion, ...). Not only does the package signature need to be verified on installation, but the files need to be installed with signatures. For IMA to enforce file integrity, the package owner's public key needs to be added to the _ima keyring.

Quoted 2 lines

If we trust root and keys can be loaded any time later, then signed initramfs will not solve the problem either.

Locking the keyring in the kernel will limit the set of permitted keys to only those specified in UEFI db or builtin. Locking the keyring in the "early" initramfs, will allow the system owner, whose key is in the UEFI db, to specify additional keys, such as those for third party packages. Not all public keys belong in the UEFI db.

Mimi

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#22 lore raw
In reply to Mimi Zohar
Quoted 13 lines · Mimi Zohar
Quoted 11 lines · Vivek Goyal

On Tue, Apr 09, 2013 at 11:07:10PM -0400, Mimi Zohar wrote:

[..]

Quoted 5 lines

The module keyring is a special case. Loading these keys from the kernel and, presumably, locking the keyring is probably fine. In the case of IMA, however, files will be signed by any number of package owners. If the _ima keyring is locked by the kernel, how would you add these other keys?

Who are package owners here. IOW, in typical IMA setup, where are the keys and when are these keys loaded in ima keyring?

Quoted 6 lines

Suppose I install third party packages not signed by the distro, but by the package owner (eg. google, rpmfusion, ...). Not only does the package signature need to be verified on installation, but the files need to be installed with signatures. For IMA to enforce file integrity, the package owner's public key needs to be added to the _ima keyring.

Ok, got it.

Quoted 9 lines
Quoted 3 lines

If we trust root and keys can be loaded any time later, then signed initramfs will not solve the problem either.

Locking the keyring in the kernel will limit the set of permitted keys to only those specified in UEFI db or builtin. Locking the keyring in the "early" initramfs, will allow the system owner, whose key is in the UEFI db, to specify additional keys, such as those for third party packages. Not all public keys belong in the UEFI db.

Ok, so third party public key you don't want to add in UEFI db. Instead platform owner (whose key is in UEFI db) will regenerate initrafs and sign it.

So above use case is primarily for user space files and verifying its integrity and IMA keyring is used for that. secureboot does not require IMA keyring to be locked as none of that code runs at ring0.

This locking requirement of IMA keyring is coming in only because we are trying to also verify the integrity of a process who will load code which runs at ring0.

So how do you like the idea of using another keyring (say system keyring) for this purpose and what keyring to use integrity of a file can be encoded in file signature.

This is something similar to INTEGRITY_KEYRING_MODULE keyring for modules. (Though I don't see this code fully hooked up yet).

Or, given the fact that module signature and here /sbin/kexec verification will make use of similar keys, we can create a system keyring, make module code make use of that keyring. And IMA code can make use of that keyring too if a file's digital signature indicates so.

Thanks
Vivek

#23 lore raw
Quoted 49 lines · Vivek Goyal
Quoted 13 lines · Mimi Zohar
Quoted 11 lines · Vivek Goyal

On Tue, Apr 09, 2013 at 11:07:10PM -0400, Mimi Zohar wrote:

[..]

Quoted 5 lines

The module keyring is a special case. Loading these keys from the kernel and, presumably, locking the keyring is probably fine. In the case of IMA, however, files will be signed by any number of package owners. If the _ima keyring is locked by the kernel, how would you add these other keys?

Who are package owners here. IOW, in typical IMA setup, where are the keys and when are these keys loaded in ima keyring?

Quoted 6 lines

Suppose I install third party packages not signed by the distro, but by the package owner (eg. google, rpmfusion, ...). Not only does the package signature need to be verified on installation, but the files need to be installed with signatures. For IMA to enforce file integrity, the package owner's public key needs to be added to the _ima keyring.

Ok, got it.

Quoted 9 lines
Quoted 3 lines

If we trust root and keys can be loaded any time later, then signed initramfs will not solve the problem either.

Locking the keyring in the kernel will limit the set of permitted keys to only those specified in UEFI db or builtin. Locking the keyring in the "early" initramfs, will allow the system owner, whose key is in the UEFI db, to specify additional keys, such as those for third party packages. Not all public keys belong in the UEFI db.

Ok, so third party public key you don't want to add in UEFI db. Instead platform owner (whose key is in UEFI db) will regenerate initrafs and sign it.

So above use case is primarily for user space files and verifying its integrity and IMA keyring is used for that. secureboot does not require IMA keyring to be locked as none of that code runs at ring0.

This locking requirement of IMA keyring is coming in only because we are trying to also verify the integrity of a process who will load code which runs at ring0.

So how do you like the idea of using another keyring (say system keyring) for this purpose and what keyring to use integrity of a file can be encoded in file signature.

Quoted 7 lines

This is something similar to INTEGRITY_KEYRING_MODULE keyring for modules. (Though I don't see this code fully hooked up yet).

Or, given the fact that module signature and here /sbin/kexec verification will make use of similar keys, we can create a system keyring, make module code make use of that keyring. And IMA code can make use of that keyring too if a file's digital signature indicates so.

Sounds good to me!

thanks,

Mimi

A message that is not in the archive (sent off-list or not yet received): CACE9dm-GZpjco8u6jNxLQpYA8LYSeoVjsyyRXVwxXHzjO-LvGw@mail.gmail.com

#25 lore raw
Quoted 7 lines · Dmitry Kasatkin

Hello,

I respond to the original question of this thread.
signed initramfs allows not only to add keys to the keyrings but perform other initialization,
which requires user-space.
Keys can be embedded into the kernel. This is fine.

What other initialization user space need to do where we can't trust root (even in secureboot mode).

IOW, if keys can be embedded in kernel (or read from UEFI db and MOK db), what other operation requires initramfs to be signed. It could very well be unsigned initramfs like today.

Thanks
Vivek

#26 lore raw
Quoted 9 lines · Vivek Goyal
Quoted 7 lines · Dmitry Kasatkin

Hello,

I respond to the original question of this thread.
signed initramfs allows not only to add keys to the keyrings but perform other initialization,
which requires user-space.
Keys can be embedded into the kernel. This is fine.

Quoted 7 lines

What other initialization user space need to do where we can't trust root (even in secureboot mode).

IOW, if keys can be embedded in kernel (or read from UEFI db and MOK db), what other operation requires initramfs to be signed. It could very well be unsigned initramfs like today.

It looks like you do not hear me.
I said that any user space initialization can be done from signed user space. For example IMA policy can be initialized.

I see that you see your particular case and in that case you do not require that.
That is fine. That is your case....

- Dmitry

Quoted 2 lines

Thanks
Vivek

#27 lore raw

On Thu, Apr 11, 2013 at 09:42:54PM +0300, Dmitry Kasatkin wrote:

[..]

Quoted 12 lines
Quoted 7 lines

What other initialization user space need to do where we can't trust root (even in secureboot mode).

IOW, if keys can be embedded in kernel (or read from UEFI db and MOK db), what other operation requires initramfs to be signed. It could very well be unsigned initramfs like today.

It looks like you do not hear me.
I said that any user space initialization can be done from signed user space. For example IMA policy can be initialized.

I am hearing you. Yes I heard you saying "but perform other initialization, which requires user-space". I am just trying to figure out more details. You are assuming that a single line statement gives all the context and it often might not be the case.

What makes it important that IMA policy is loaded from an signed initramfs and not from unsigned one.

Also how would you make use of it without secureboot. Only secureboot will allow to keep keys in firmware so that one can have a key in there and be able to sign initramfs.

In regular system, distributions do not ship pre-loaded keys so one can not sign initramfs. So only thing possible is that distributions enforce some policy in signed initramfs and if distributions have to enforce a policy they can do that in kernel itself and no need for signed initramfs.

Thanks
Vivek

#28 lore raw
Quoted 21 lines · Vivek Goyal

On Thu, Apr 11, 2013 at 09:42:54PM +0300, Dmitry Kasatkin wrote:

[..]

Quoted 12 lines
Quoted 7 lines

What other initialization user space need to do where we can't trust root (even in secureboot mode).

IOW, if keys can be embedded in kernel (or read from UEFI db and MOK db), what other operation requires initramfs to be signed. It could very well be unsigned initramfs like today.

It looks like you do not hear me.
I said that any user space initialization can be done from signed user space. For example IMA policy can be initialized.

I am hearing you. Yes I heard you saying "but perform other initialization, which requires user-space". I am just trying to figure out more details. You are assuming that a single line statement gives all the context and it often might not be the case.

Quoted 6 lines

What makes it important that IMA policy is loaded from an signed initramfs and not from unsigned one.

Also how would you make use of it without secureboot. Only secureboot will allow to keep keys in firmware so that one can have a key in there and be able to sign initramfs.

You don't have a monopoly on secure boot. We're all assuming a secure boot environment. The only question is what happens afterwards. You're interested in appraising a few particular files: kernel modules, kexec, and the files kexec loads. I'm interested in having all files in the TCB measured and appraised. Dmitry is interested in having all files appraised. The kernel needs to be able to support these and other scenarios.

Quoted 4 lines

In regular system, distributions do not ship pre-loaded keys so one can not sign initramfs. So only thing possible is that distributions enforce some policy in signed initramfs and if distributions have to enforce a policy they can do that in kernel itself and no need for signed initramfs.

The difference is that one hard codes policy in the kernel, while the other doesn't. Having the policy in a signed initramfs, permits the platform owner, for example, to change the policy.

Having said this, both Dmitry and I agreed with you that the UEFI keys can be loaded from the kernel. We disagree with you, that there is no other purpose for a signed early initramfs. Dmitry's example was loading the IMA policy. Another example is locking the _ima keyring. Each scenario has its own requirements.

thanks,

Mimi

#29 lore raw
In reply to Dmitry Kasatkin
Quoted 5 lines · Dmitry Kasatkin
init/initramfs_sig.c new file +5 -0
+static const char *secmnt = "/root";
+static const char *initramfs_img = "/initramfs-sig.img";
+
+static int __init load_image(const char *from)
+{

...

Quoted 13 lines
init/initramfs_sig.c new file +13 -0
+	err = sys_mount("tpmfs", (char *)secmnt, "tmpfs", MS_SILENT, NULL);
+	if (err) {
+		pr_err("sys_mount() = %d\n", err);
+		goto out;
+	}
+
+	sys_unshare(CLONE_FS | CLONE_FILES);
+	sys_chdir(secmnt);
+	sys_chroot(".");
+	sys_setsid();
+
+	pr_info("unpack start\n");
+	msg = unpack_to_rootfs(buf, offset);

...

Quoted 30 lines
init/initramfs_sig.c new file +30 -0
+}
+
+static int __init init_init(struct subprocess_info *info, struct cred *new)
+{
+	return load_image(initramfs_img);
+}
+
+static void init_cleanup(struct subprocess_info *info)
+{
+	int err;
+
+	pr_info("cleanup\n");
+
+	err = sys_umount((char *)secmnt, MNT_DETACH);
+	if (err)
+		pr_err("unable to umount secmnt: %d\n", err);
+}
+
+static int __init load_initramfs(void)
+{
+	static char *argv[] = { "pre-init", NULL, };
+	extern char *envp_init[];
+	int err;
+
+	/*
+	 * In case that a resume from disk is carried out by linuxrc or one of
+	 * its children, we need to tell the freezer not to wait for us.
+	 */
+	current->flags |= PF_FREEZER_SKIP;
+

init/initramfs_sig.c line 158

Quoted 10 lines
init/initramfs_sig.c new file +10 -0
+	err = call_usermodehelper_fns("/pre-init", argv, envp_init,
+				      UMH_WAIT_PROC, init_init, init_cleanup,
+				      NULL);
+
+	current->flags &= ~PF_FREEZER_SKIP;
+
+	pr_info("initramfs_sig /pre-init completed: %d\n", err);
+
+	return err;
+}

So, there's another issue here - if you do want to run a fully-signed initramfs, and so there's nothing else in the container, you go through this code and it mounts it. In this case the wrapper initramfs which includes the signed image is still in memory, and there's nothing e.g. dracut can do about it. Which means you've got two whole copies of the initramfs in memory, and even if code later cleans up the one it sees, you can't get rid of the other one.

(this would not be an issue without the wrapper.)

Signature · 1 line
        Peter
#30 lore raw
Quoted 71 lines · Peter Jones
Quoted 5 lines · Dmitry Kasatkin
init/initramfs_sig.c new file +5 -0
+static const char *secmnt = "/root";
+static const char *initramfs_img = "/initramfs-sig.img";
+
+static int __init load_image(const char *from)
+{

...

Quoted 13 lines
init/initramfs_sig.c new file +13 -0
+     err = sys_mount("tpmfs", (char *)secmnt, "tmpfs", MS_SILENT, NULL);
+     if (err) {
+             pr_err("sys_mount() = %d\n", err);
+             goto out;
+     }
+
+     sys_unshare(CLONE_FS | CLONE_FILES);
+     sys_chdir(secmnt);
+     sys_chroot(".");
+     sys_setsid();
+
+     pr_info("unpack start\n");
+     msg = unpack_to_rootfs(buf, offset);

...

Quoted 30 lines
init/initramfs_sig.c new file +30 -0
+}
+
+static int __init init_init(struct subprocess_info *info, struct cred *new)
+{
+     return load_image(initramfs_img);
+}
+
+static void init_cleanup(struct subprocess_info *info)
+{
+     int err;
+
+     pr_info("cleanup\n");
+
+     err = sys_umount((char *)secmnt, MNT_DETACH);
+     if (err)
+             pr_err("unable to umount secmnt: %d\n", err);
+}
+
+static int __init load_initramfs(void)
+{
+     static char *argv[] = { "pre-init", NULL, };
+     extern char *envp_init[];
+     int err;
+
+     /*
+      * In case that a resume from disk is carried out by linuxrc or one of
+      * its children, we need to tell the freezer not to wait for us.
+      */
+     current->flags |= PF_FREEZER_SKIP;
+

init/initramfs_sig.c line 158

Quoted 10 lines
init/initramfs_sig.c new file +10 -0
+     err = call_usermodehelper_fns("/pre-init", argv, envp_init,
+                                   UMH_WAIT_PROC, init_init, init_cleanup,
+                                   NULL);
+
+     current->flags &= ~PF_FREEZER_SKIP;
+
+     pr_info("initramfs_sig /pre-init completed: %d\n", err);
+
+     return err;
+}

So, there's another issue here - if you do want to run a fully-signed initramfs, and so there's nothing else in the container, you go through this code and it mounts it. In this case the wrapper initramfs which includes the signed image is still in memory, and there's nothing e.g. dracut can do about it. Which means you've got two whole copies of the initramfs in memory, and even if code later cleans up the one it sees, you can't get rid of the other one.

Quoted 2 lines

(this would not be an issue without the wrapper.)

It should not be like that. Actually when pre-init exits, cleanup code umount tmpfs,
which in turn cleanups the RAM.

Also ffter unpacking of signed image, it can be just removed. In fact, IIRC, switch root cleans up ramfs.

I think everything is fine here...

Thanks,

Dmitry

Quoted 2 lines

--
Peter

#31 lore raw
Quoted 4 lines · Dmitry

It should not be like that. Actually when pre-init exits, cleanup code umount tmpfs, which in turn cleanups the RAM.

It doesn't quite... the rootfs is permanent. This is also only one usage mode: there are quite a few Linux systems running directly out of initramfs.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#32 lore raw
Quoted 10 lines · H. Peter Anvin
Quoted 5 lines · Dmitry

It should not be like that. Actually when pre-init exits, cleanup code umount tmpfs, which in turn cleanups the RAM.

It doesn't quite... the rootfs is permanent. This is also only one usage
mode: there are quite a few Linux systems running directly out of initramfs.

rootfs is not permanent when it is ramfs. It is cleaned up on switch root. It is easy to find out that it is empty by mounting : mount -t ramfs rootfs /mnt/

In the case of running from normal storage, of course, there is ridicules remove the content.

- Dmitry

Quoted 7 lines

-hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.

#33 lore raw

The cleanup is not a umount, it is actually a tree walk unlinking the contents.

Quoted 33 lines · Dmitry
Quoted 4 lines · H. Peter Anvin
Quoted 3 lines · Dmitry

It should not be like that. Actually when pre-init exits, cleanup

code

Quoted 4 lines
Quoted 2 lines

umount tmpfs, which in turn cleanups the RAM.

It doesn't quite... the rootfs is permanent. This is also only one

usage

Quoted 1 line

mode: there are quite a few Linux systems running directly out of

initramfs.

Quoted 1 line

rootfs is not permanent when it is ramfs. It is cleaned up on switch root.
It is easy to find out that it is empty by mounting : mount -t ramfs rootfs /mnt/

In the case of running from normal storage, of course, there is ridicules remove the content.

- Dmitry

Quoted 7 lines

-hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.

Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
#34 lore raw
Quoted 2 lines · H. Peter Anvin

The cleanup is not a umount, it is actually a tree walk unlinking the contents.

Please see that umounting ramfs releases the memory. There was no forced cleanup.
"cp" copied about 2GB of content.
After umounting we got 2GB back to free RAM...

kds@kds:~$ sudo mount -t ramfs testramfs /test
kds@kds:~$ sudo cp -r /usr/ /test
kds@kds:~$ du -sm /test
2154    /test
kds@kds:~$ free
                       total       used            free     shared
buffers     cached
Mem:       8058600    7855780     202820          0      24768    4819136
-/+ buffers/cache:    3011876    5046724
Swap:            0          0          0
kds@kds:~$ sudo umount /test
kds@kds:~$ free
                      total       used            free     shared
buffers     cached
Mem:       8058600    5644864    2413736          0      25268    2623956
-/+ buffers/cache:    2995640    5062960
Swap:            0          0          0

The same happens also with tmpfs.

- Dmitry

Quoted 38 lines
Quoted 20 lines · Dmitry
Quoted 4 lines · H. Peter Anvin
Quoted 3 lines · Dmitry

It should not be like that. Actually when pre-init exits, cleanup

code

Quoted 4 lines
Quoted 2 lines

umount tmpfs, which in turn cleanups the RAM.

It doesn't quite... the rootfs is permanent. This is also only one

usage

Quoted 1 line

mode: there are quite a few Linux systems running directly out of

initramfs.

Quoted 1 line

rootfs is not permanent when it is ramfs. It is cleaned up on switch root.
It is easy to find out that it is empty by mounting : mount -t ramfs rootfs /mnt/

Quoted 13 lines

In the case of running from normal storage, of course, there is ridicules remove the content.

- Dmitry

Quoted 7 lines

-hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.

--
Sent from my mobile phone. Please excuse brevity and lack of formatting.

#35 lore raw

Yes, but you can't umount rootfs.

Quoted 73 lines · Dmitry
Quoted 1 line · H. Peter Anvin

The cleanup is not a umount, it is actually a tree walk unlinking the

contents.

Quoted 1 line

Please see that umounting ramfs releases the memory. There was no forced cleanup.
"cp" copied about 2GB of content.
After umounting we got 2GB back to free RAM...

kds@kds:~$ sudo mount -t ramfs testramfs /test
kds@kds:~$ sudo cp -r /usr/ /test
kds@kds:~$ du -sm /test
2154    /test
kds@kds:~$ free
                      total       used            free     shared
buffers     cached
Mem:       8058600    7855780     202820          0      24768   
4819136
-/+ buffers/cache:    3011876    5046724
Swap:            0          0          0
kds@kds:~$ sudo umount /test
kds@kds:~$ free
                     total       used            free     shared
buffers     cached
Mem:       8058600    5644864    2413736          0      25268   
2623956
-/+ buffers/cache:    2995640    5062960
Swap:            0          0          0

The same happens also with tmpfs.

- Dmitry

Quoted 31 lines
Quoted 29 lines · Dmitry
Quoted 4 lines · H. Peter Anvin
Quoted 3 lines · Dmitry

It should not be like that. Actually when pre-init exits, cleanup

code

Quoted 4 lines
Quoted 2 lines

umount tmpfs, which in turn cleanups the RAM.

It doesn't quite... the rootfs is permanent. This is also only one

usage

Quoted 1 line

mode: there are quite a few Linux systems running directly out of

initramfs.

Quoted 1 line

rootfs is not permanent when it is ramfs. It is cleaned up on switch root.
It is easy to find out that it is empty by mounting : mount -t ramfs rootfs /mnt/

In the case of running from normal storage, of course, there is ridicules remove the content.

- Dmitry

Quoted 3 lines

-hpa

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.

--
Sent from my mobile phone. Please excuse brevity and lack of

formatting.

Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
#36 lore raw
Quoted 1 line · H. Peter Anvin

Yes, but you can't umount rootfs.

But that was not a rootfs, but tmpfs/ramfs mounted to /root folder.

Quoted 79 lines
Quoted 65 lines · Dmitry
Quoted 1 line · H. Peter Anvin

The cleanup is not a umount, it is actually a tree walk unlinking the

contents.

Quoted 1 line

Please see that umounting ramfs releases the memory. There was no forced cleanup.
"cp" copied about 2GB of content.
After umounting we got 2GB back to free RAM...

kds@kds:~$ sudo mount -t ramfs testramfs /test
kds@kds:~$ sudo cp -r /usr/ /test
kds@kds:~$ du -sm /test
2154    /test
kds@kds:~$ free
                      total       used            free     shared
buffers     cached
Mem:       8058600    7855780     202820          0      24768
4819136
-/+ buffers/cache:    3011876    5046724
Swap:            0          0          0
kds@kds:~$ sudo umount /test
kds@kds:~$ free
                     total       used            free     shared
buffers     cached
Mem:       8058600    5644864    2413736          0      25268
2623956
-/+ buffers/cache:    2995640    5062960
Swap:            0          0          0

The same happens also with tmpfs.

- Dmitry

Quoted 31 lines
Quoted 29 lines · Dmitry
Quoted 4 lines · H. Peter Anvin
Quoted 3 lines · Dmitry

It should not be like that. Actually when pre-init exits, cleanup

code

Quoted 4 lines
Quoted 2 lines

umount tmpfs, which in turn cleanups the RAM.

It doesn't quite... the rootfs is permanent. This is also only one

usage

Quoted 1 line

mode: there are quite a few Linux systems running directly out of

initramfs.

Quoted 1 line

rootfs is not permanent when it is ramfs. It is cleaned up on switch root.
It is easy to find out that it is empty by mounting : mount -t ramfs rootfs /mnt/

In the case of running from normal storage, of course, there is ridicules remove the content.

- Dmitry

Quoted 3 lines

-hpa

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.

--
Sent from my mobile phone. Please excuse brevity and lack of

formatting.

--
Sent from my mobile phone. Please excuse brevity and lack of formatting.

#37 lore raw

Yes, but I am talking about initramfs.

Quoted 91 lines · Dmitry
Quoted 1 line · H. Peter Anvin

Yes, but you can't umount rootfs.

But that was not a rootfs, but tmpfs/ramfs mounted to /root folder.

Quoted 5 lines
Quoted 2 lines · Dmitry
Quoted 1 line · H. Peter Anvin

The cleanup is not a umount, it is actually a tree walk unlinking

the

Quoted 35 lines
Quoted 35 lines

contents.

Quoted 1 line

Please see that umounting ramfs releases the memory. There was no forced cleanup.
"cp" copied about 2GB of content.
After umounting we got 2GB back to free RAM...

kds@kds:~$ sudo mount -t ramfs testramfs /test
kds@kds:~$ sudo cp -r /usr/ /test
kds@kds:~$ du -sm /test
2154    /test
kds@kds:~$ free
                      total       used            free     shared
buffers     cached
Mem:       8058600    7855780     202820          0      24768
4819136
-/+ buffers/cache:    3011876    5046724
Swap:            0          0          0
kds@kds:~$ sudo umount /test
kds@kds:~$ free
                     total       used            free     shared
buffers     cached
Mem:       8058600    5644864    2413736          0      25268
2623956
-/+ buffers/cache:    2995640    5062960
Swap:            0          0          0

The same happens also with tmpfs.

- Dmitry

Quoted 3 lines
Quoted 1 line · Dmitry

On Wed, Feb 6, 2013 at 7:04 AM, H. Peter Anvin <[email protected]>

Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines · Dmitry
Quoted 3 lines

It should not be like that. Actually when pre-init exits,

cleanup

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

code

Quoted 4 lines
Quoted 2 lines

umount tmpfs, which in turn cleanups the RAM.

It doesn't quite... the rootfs is permanent. This is also only

one

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

usage

Quoted 1 line

mode: there are quite a few Linux systems running directly out of

initramfs.

Quoted 1 line

rootfs is not permanent when it is ramfs. It is cleaned up on

switch

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

root.
It is easy to find out that it is empty by mounting : mount -t

ramfs

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

rootfs /mnt/

In the case of running from normal storage, of course, there is ridicules remove the content.

- Dmitry

Quoted 7 lines

-hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

--
Sent from my mobile phone. Please excuse brevity and lack of

formatting.

--
Sent from my mobile phone. Please excuse brevity and lack of

formatting.

Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
#38 lore raw
In reply to Dmitry Kasatkin

On Tue, Feb 05, 2013 at 02:34:50PM +0200, Dmitry Kasatkin wrote:

[..]

Quoted 10 lines
init/initramfs_sig.c new file +10 -0
+static int __init load_initramfs(void)
+{
+	static char *argv[] = { "pre-init", NULL, };
+	extern char *envp_init[];
+	int err;
+
+	/*
+	 * In case that a resume from disk is carried out by linuxrc or one of
+	 * its children, we need to tell the freezer not to wait for us.
+	 */

init/initramfs_sig.c line 156

Quoted 10 lines
init/initramfs_sig.c new file +10 -0
+	current->flags |= PF_FREEZER_SKIP;
+
+	err = call_usermodehelper_fns("/pre-init", argv, envp_init,
+				      UMH_WAIT_PROC, init_init, init_cleanup,
+				      NULL);
+
+	current->flags &= ~PF_FREEZER_SKIP;
+
+	pr_info("initramfs_sig /pre-init completed: %d\n", err);
+

Dmitry,

How do we make sure that this is the first call to user mode helpers. I see that we first unpacked unsigned initramfs. Then after a while we unpacked signed initramfs on /root and did a chroot. But now there is a window before chroot, where kernel might call into /sbin/hotplug or /sbin/modprobe from unsigned initramfs?

Specifically, I put some printk and I am seeing calls to /sbin/hotplug before we even unpacked signed initramfs.

Thanks
Vivek

#39 lore raw
Quoted 26 lines · Vivek Goyal

On Tue, Feb 05, 2013 at 02:34:50PM +0200, Dmitry Kasatkin wrote:

[..]

Quoted 10 lines
init/initramfs_sig.c new file +10 -0
+static int __init load_initramfs(void)
+{
+     static char *argv[] = { "pre-init", NULL, };
+     extern char *envp_init[];
+     int err;
+
+     /*
+      * In case that a resume from disk is carried out by linuxrc or one of
+      * its children, we need to tell the freezer not to wait for us.
+      */

init/initramfs_sig.c line 156

Quoted 10 lines
init/initramfs_sig.c new file +10 -0
+     current->flags |= PF_FREEZER_SKIP;
+
+     err = call_usermodehelper_fns("/pre-init", argv, envp_init,
+                                   UMH_WAIT_PROC, init_init, init_cleanup,
+                                   NULL);
+
+     current->flags &= ~PF_FREEZER_SKIP;
+
+     pr_info("initramfs_sig /pre-init completed: %d\n", err);
+

Dmitry,

Quoted 8 lines

How do we make sure that this is the first call to user mode helpers. I see that we first unpacked unsigned initramfs. Then after a while we unpacked signed initramfs on /root and did a chroot. But now there is a window before chroot, where kernel might call into /sbin/hotplug or /sbin/modprobe from unsigned initramfs?

Specifically, I put some printk and I am seeing calls to /sbin/hotplug before we even unpacked signed initramfs.

If it really happens, then there something should be done to prevent it. Can you please send me your patch with printks.
It would be interesting to analyze more what might happen.

Thanks,

Dmitry

Quoted 3 lines

Thanks
Vivek

#40 lore raw
Quoted 12 lines
Quoted 11 lines

Dmitry,

How do we make sure that this is the first call to user mode helpers. I see that we first unpacked unsigned initramfs. Then after a while we unpacked signed initramfs on /root and did a chroot. But now there is a window before chroot, where kernel might call into /sbin/hotplug or /sbin/modprobe from unsigned initramfs?

Specifically, I put some printk and I am seeing calls to /sbin/hotplug before we even unpacked signed initramfs.

I did some experiments and made this patch which prevents launching of user mode helpers before pre-init from signed image is executed.

I do not know if this is the right way to do it, but at least it works for me. The whole idea of these patches is to allow simple usage of signed image, without the need to modify kernel parameters (0 block) and boot loaders....

--------------------------------------------------------------------------------------------------
commit a99eaa06ab142906da67800423425b7c5def0a3e

Author: Dmitry Kasatkin <[email protected]>
Date:   Fri Feb 8 15:05:22 2013 +0200

initramfs_sig: prevent usermode helpers before signed image is executed

This patch prevents execution of user mode helper before /pre-init is executed.

include/linux/kmod.h +3 -0
index 5398d58..8b6d2d5 100644
@@ -53,6 +53,8 @@ struct file;
 #define UMH_WAIT_PROC	2	/* wait for the process to complete */
 #define UMH_KILLABLE	4	/* wait for EXEC/PROC killable */
 
+#define UMH_FLAGS_SIG	0x01
+
 struct subprocess_info {
 	struct work_struct work;
 	struct completion *complete;
@@ -64,6 +66,7 @@ struct subprocess_info {
 	int (*init)(struct subprocess_info *info, struct cred *new);
 	void (*cleanup)(struct subprocess_info *info);
 	void *data;
+	unsigned flags;
 };
 
 extern int
@@ -71,6 +74,12 @@ call_usermodehelper_fns(char *path, char **argv,

char **envp, int wait,
int (*init)(struct subprocess_info *info, struct cred *new), void (*cleanup)(struct subprocess_info *), void *data);

+extern int
+__call_usermodehelper_fns(char *path, char **argv, char **envp, int wait,

+			  int (*init)(struct subprocess_info *info, struct cred *new),
+			  void (*cleanup)(struct subprocess_info *),
+			  void *data, unsigned flags);

+
static inline int
call_usermodehelper(char *path, char **argv, char **envp, int wait) {

init/initramfs_sig.c +5 -3
index 3385414..7ab0604 100644
@@ -146,9 +146,9 @@ static int __init load_initramfs(void)
 	 */
 	current->flags |= PF_FREEZER_SKIP;
 
-	err = call_usermodehelper_fns("/pre-init", argv, envp_init,
-				      UMH_WAIT_PROC, init_init, init_cleanup,
-				      NULL);
+	err = __call_usermodehelper_fns("/pre-init", argv, envp_init,
+				        UMH_WAIT_PROC, init_init, init_cleanup,
+				        NULL, UMH_FLAGS_SIG);
 
 	current->flags &= ~PF_FREEZER_SKIP;
 
@@ -167,5 +167,7 @@ int __init initramfs_sig_load(void)
 
 	pr_info("initramfs_sig finished\n");
 
+	usermodehelper_enable();
+
 	return 0;
 }
init/main.c +2 -0
index 43ef145..bbfa130 100644
@@ -784,7 +784,9 @@ static void __init do_basic_setup(void)
 	driver_init();
 	init_irq_proc();
 	do_ctors();
+#ifndef CONFIG_INITRAMFS_SIG
 	usermodehelper_enable();
+#endif
 	do_initcalls();
 }
 
kernel/kmod.c +0 -0
index 0023a87..e4b9117 100644
@@ -564,10 +564,12 @@ int call_usermodehelper_exec(struct

subprocess_info *sub_info, int wait)
if (sub_info->path[0] == '\0')
goto out;

-	if (!khelper_wq || usermodehelper_disabled) {
+	if (!khelper_wq || (usermodehelper_disabled &&

+ !(sub_info->flags & UMH_FLAGS_SIG))) {
retval = -EBUSY;
goto out;
}
+ pr_info("initr: %s: %s\n", __func__, sub_info->path);
/*
* Worker thread must not wait for khelper thread at below
* wait_for_completion() if the thread was created with CLONE_VFORK
@@ -613,10 +615,10 @@ unlock:
* check the call_usermodehelper_fns() return value: if it is -ENOMEM, perform
* the necessaary cleanup within the caller.
*/
-int call_usermodehelper_fns(
+int __call_usermodehelper_fns(
char *path, char **argv, char **envp, int wait,
int (*init)(struct subprocess_info *info, struct cred *new),
- void (*cleanup)(struct subprocess_info *), void *data)
+ void (*cleanup)(struct subprocess_info *), void *data, unsigned flags)
{
struct subprocess_info *info;
gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
@@ -628,8 +630,18 @@ int call_usermodehelper_fns(

call_usermodehelper_setfns(info, init, cleanup, data);

+ info->flags = flags;
+
return call_usermodehelper_exec(info, wait);
}
+
+int call_usermodehelper_fns(
+ char *path, char **argv, char **envp, int wait,
+ int (*init)(struct subprocess_info *info, struct cred *new),
+ void (*cleanup)(struct subprocess_info *), void *data)
+{
+ return __call_usermodehelper_fns(path, argv, envp, wait, init,
cleanup, data, 0);
+}
EXPORT_SYMBOL(call_usermodehelper_fns);

static int proc_cap_handler(struct ctl_table *table, int write,

#41 lore raw
Quoted 25 lines · Dmitry
Quoted 12 lines
Quoted 11 lines

Dmitry,

How do we make sure that this is the first call to user mode helpers. I see that we first unpacked unsigned initramfs. Then after a while we unpacked signed initramfs on /root and did a chroot. But now there is a window before chroot, where kernel might call into /sbin/hotplug or /sbin/modprobe from unsigned initramfs?

Specifically, I put some printk and I am seeing calls to /sbin/hotplug before we even unpacked signed initramfs.

I did some experiments and made this patch which prevents launching of user mode helpers before pre-init from signed image is executed.

I do not know if this is the right way to do it, but at least it works for me. The whole idea of these patches is to allow simple usage of signed image, without the need to modify kernel parameters (0 block) and boot loaders....

--------------------------------------------------------------------------------------------------
commit a99eaa06ab142906da67800423425b7c5def0a3e

Author: Dmitry Kasatkin <[email protected]>
Date:   Fri Feb 8 15:05:22 2013 +0200
Quoted 6 lines

initramfs_sig: prevent usermode helpers before signed image is executed

This patch prevents execution of user mode helper before /pre-init is executed.

Yep. This seems to have blocked the calls going out to user space and returns with -EBUSY

Thanks
Vivek