Skip to contentSkip to conversation

Introduce the in-kernel hibernation encryption

RFC PATCH In review Chen Yu 5 participants 53 messages Jul 18, 2018 – Aug 9, 2018 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

Chen Yu

author
#0 lore raw

v2 cover Introduce the in-kernel hibernation encryption

As security becomes more and more important, we add the in-kernel encryption support for hibernation.

This prototype is a trial version to implement the hibernation encryption in the kernel. This patch set is divided into two parts:
1. The hibernation snapshot encryption in kernel space.
2. The key derivation implementation in user space.

The whole process is illustrated below:
1. install the kernel module:
modprobe crypto_hibernation
2. run the tool to generate the key from user provided passphrase (salt has been read from kernel).
3. launch the hibernation process, the kernel uses the key in step 2 to encrypt the hibernation snapshot.
4. resume the system and the initrd will launch cryto_hibernate to read previous salt from kernel and probe the user passphrase and generate the same key.
5. kernel uses this key to decrypt the hibernation snapshot and restore to previous system.

Chen Yu (4):
PM / Hibernate: Add helper functions for hibernation encryption PM / hibernate: Install crypto hooks for hibernation encryption PM / Hibernate: Encrypt the snapshot pages before submitted to the
block device
tools: create power/crypto utility

 include/linux/suspend.h               |  40 +++
 kernel/power/Kconfig                  |  14 ++
 kernel/power/Makefile                 |   1 +
 kernel/power/crypto_hibernation.c     | 421 +++++++++++++++++++++++++++++++
 kernel/power/hibernate.c              |  67 +++++
 kernel/power/power.h                  |  67 +++++
 kernel/power/swap.c                   | 182 +++++++++++++-
 tools/power/crypto/Makefile           |  24 ++
 tools/power/crypto/crypto_hibernate.c | 462 ++++++++++++++++++++++++++++++++++
 9 files changed, 1270 insertions(+), 8 deletions(-)
 create mode 100644 kernel/power/crypto_hibernation.c
 create mode 100644 tools/power/crypto/Makefile
 create mode 100644 tools/power/crypto/crypto_hibernate.c
Signature · 1 line
2.7.4
author
#1 lore raw

RFC PATCH v2 1/4 PM / Hibernate: Add helper functions for hibernation encryption

Basically, the in-kernel hibernation encryption solution is to encrypt the pages before they go to the block device.

Why we do this?
1. One advantage is: Users do not have to
encrypt the whole swap partition as other tools.
2. Ideally kernel memory should be encrypted by the kernel itself. We have uswsusp to support user space hibernation, however doing the encryption
in kernel space has more advantages:
2.1 Not having to transfer plain text kernel memory to
user space. Per Lee, Chun-Yi, uswsusp is disabled when the kernel is locked down:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/
linux-fs.git/commit/?h=lockdown-20180410& id=8732c1663d7c0305ae01ba5a1ee4d2299b7b4612 due to:
"There have some functions be locked-down because there have no appropriate mechanisms to check the integrity of writing data."
2.2 Not having to copy each page to user space
one by one not in parallel, which might introduce significant amount of copy_to_user() and it might not be efficient on servers having large amount of DRAM.
2.3 Distribution has requirement to do snapshot
signature for verification, which can be built by leveraging this patch set.
2.4 The encryption is in the kernel, so it doesn't
have to worry too much about bugs in user space utilities and similar, for example.

For the key derivation solution, there was a discussion on the mailing list on whether the key should be derived in kernel or in user space. And it turns out to be generating the key by user space is more applicable[1]. So the procedure is illustrated below:

1. The user space reads the salt from kernel and generates a symmetrical key(512bits for now) based on user passphrase. Then the kernel uses that key to encrypt the hibernation image.
2. The salt will be saved in image header and passed to the restore kernel.
3. During restore, the userspace reads the salt from the kernel first and then probe passphrase from the user to generate the same key and pass that key back to kernel.
4. The restore kernel uses that key to decrypt the image.

[1] https://www.spinics.net/lists/linux-crypto/msg33145.html

Cc Rafael J. Wysocki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
Cc "Lee, Chun-Yi" <[email protected]>
Cc Eric Biggers <[email protected]>
Cc "Theodore Ts'o" <[email protected]>
Cc Stephan Mueller <[email protected]>
Cc Denis Kenzior <[email protected]>
---
 kernel/power/Kconfig              |  14 ++
 kernel/power/Makefile             |   1 +
 kernel/power/crypto_hibernation.c | 411 ++++++++++++++++++++++++++++++++++++++
 kernel/power/power.h              |  42 ++++
 4 files changed, 468 insertions(+)
 create mode 100644 kernel/power/crypto_hibernation.c
kernel/power/Kconfig +14 -0
index e880ca2..fd39c30 100644
@@ -101,6 +101,20 @@ config PM_STD_PARTITION
 	  suspended image to. It will simply pick the first available swap 
 	  device.
 
+config CRYPTO_HIBERNATION
+	tristate "Encryption/signature of snapshot for hibernation"
+	depends on HIBERNATION && CRYPTO_AES && CRYPTO_HASH2 && KEYS
+	default n
+	help
+	  Allow the kernel to encrypt/signature the snapshot data
+	  based on user provided passphrase. The user should provide
+	  a valid symmetrical key to the kernel either by ioctl or
+	  by keyctl, so the kernel could use that key either to encrypt
+	  the hibernation snapshot pages, or get signature of these pages.
+	  The user facility could be found under tools/power/crypto/.
+
+	  If in doubt, say N.
+
 config PM_SLEEP
 	def_bool y
 	depends on SUSPEND || HIBERNATE_CALLBACKS
kernel/power/Makefile +1 -0
index a3f79f0e..52c68a4 100644
@@ -11,6 +11,7 @@ obj-$(CONFIG_FREEZER)		+= process.o
 obj-$(CONFIG_SUSPEND)		+= suspend.o
 obj-$(CONFIG_PM_TEST_SUSPEND)	+= suspend_test.o
 obj-$(CONFIG_HIBERNATION)	+= hibernate.o snapshot.o swap.o user.o
+obj-$(CONFIG_CRYPTO_HIBERNATION) += crypto_hibernation.o
 obj-$(CONFIG_PM_AUTOSLEEP)	+= autosleep.o
 obj-$(CONFIG_PM_WAKELOCKS)	+= wakelock.o
 
kernel/power/crypto_hibernation.c new file +411 -0

411 lines not on this page · raw message

kernel/power/power.h +42 -0

48 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#2 lore raw

RFC PATCH v2 2/4 PM / hibernate: Install crypto hooks for hibernation encryption

In reply to Chen Yu

The encryption helper functions are installed into hibernation framework for later use.

Cc Rafael J. Wysocki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
Cc "Lee, Chun-Yi" <[email protected]>
Cc Eric Biggers <[email protected]>
Cc "Theodore Ts'o" <[email protected]>
Cc Stephan Mueller <[email protected]>
Cc Denis Kenzior <[email protected]>
---
 include/linux/suspend.h           | 40 +++++++++++++++++++++++
 kernel/power/crypto_hibernation.c | 10 ++++++
 kernel/power/hibernate.c          | 67 +++++++++++++++++++++++++++++++++++++++
 kernel/power/power.h              |  2 ++
 4 files changed, 119 insertions(+)
include/linux/suspend.h +40 -0
index 440b62f..b45a857 100644
@@ -391,6 +391,46 @@ extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
 extern int hibernate(void);
 extern bool system_entering_hibernation(void);
 extern bool hibernation_available(void);
+#if IS_ENABLED(CONFIG_CRYPTO_HIBERNATION)
+struct hibernation_crypto_ops {
+	int (*crypto_data)(
+		const char *inbuf, int inlen,
+		char *outbuf, int outlen,
+		unsigned int cmd,
+		int page_idx);
+	void (*save)(void *buf);
+	void (*restore)(void *buf);
+	int (*init)(bool suspend);
+};
+
+extern void hibernation_set_crypto_ops(
+		const struct hibernation_crypto_ops *ops);
+extern int hibernation_crypto_data(
+		const char *inbuf,
+		int inlen,
+		char *outbuf,
+		int outlen,
+		unsigned int cmd,
+		int page_idx);
+extern void hibernation_crypto_save(void *outbuf);
+extern void hibernation_crypto_restore(void *inbuf);
+extern int hibernation_crypto_init(bool suspend);
+extern int hibernation_crypto_mode;
+#else
+static inline int hibernation_crypto_data(
+		const char *inbuf,
+		int inlen,
+		char *outbuf,
+		int outlen,
+		unsigned int cmd,
+		int page_idx) { return 0; }
+static inline void hibernation_crypto_save(void *outbuf) {}
+static inline void hibernation_crypto_restore(void *inbuf) {}
+static inline int hibernation_crypto_init(bool suspend)
+{
+	return 0;
+}
+#endif
 asmlinkage int swsusp_save(void);
 extern struct pbe *restore_pblist;
 #else /* CONFIG_HIBERNATION */
kernel/power/crypto_hibernation.c +10 -0
index 406bb0c..845eb54 100644
@@ -36,6 +36,7 @@
 #include <linux/moduleparam.h>
 #include <linux/cdev.h>
 #include <linux/major.h>
+#include <linux/suspend.h>
 #include <crypto/skcipher.h>
 #include <crypto/akcipher.h>
 #include <crypto/aes.h>
@@ -288,6 +289,13 @@ static int crypto_init(bool suspend)
 	return 0;
 }
 
+static const struct hibernation_crypto_ops crypto_ops = {
+	.crypto_data = crypto_data,
+	.save = crypto_save,
+	.restore = crypto_restore,
+	.init = crypto_init,
+};
+
 /* key/salt probing via ioctl. */
 dev_t crypto_dev;
 static struct class *crypto_dev_class;
@@ -384,6 +392,8 @@ static int crypto_hibernate_init(void)
 	/* generate the random salt */
 	get_random_bytes(get_salt_ptr(), HIBERNATE_MAX_SALT_BYTES);
 
+	hibernation_set_crypto_ops(&crypto_ops);
+
 	return 0;
 
  r_device:
kernel/power/hibernate.c +67 -0

79 lines not on this page · raw message

kernel/power/power.h +2 -0
index a539bdb..ba3b24c 100644
@@ -107,6 +107,8 @@ struct hibernation_crypto {
 	struct hibernation_crypto_keys keys;
 };
 
+extern void hibernation_set_crypto_ops(
+	const struct hibernation_crypto_ops *ops);
 #else
 #define HIBERNATE_MAX_SALT_BYTES	0
 #endif
Signature · 1 line
2.7.4
author
#3 lore raw

RFC PATCH v2 4/4 tools: create power/crypto utility

In reply to Chen Yu

crypto_hibernate is a user-space utility to generate 512bits key and pass it to the kernel via ioctl for hibernation encryption.(We can also add the key into kernel via keyctl if necessary.)

The key derivation is based on a simplified implementation of PBKDF2[1] in e2fsprogs - both the key length and the hash bytes are the same - 512bits. crypto_hibernate will firstly read the salt from kernel and probe the user for passphrase, then uses the salt of passphrase to generate a 512bits key based on PBKDF2.

Usage:
1. install the kernel module:
modprobe crypto_hibernation
2. run this tool to generate the key from
user provided passphrase (salt has been read from kernel).
3. launch the hibernation process, the kernel
uses the key in step 2 to encrypt the hibernation snapshot.
4. resume the system and the initrd will
launch cryto_hibernate to read previous salt from kernel and probe the user passphrase
and generate the same key.
5. kernel uses this key to decrypt the hibernation snapshot and restore to previous system.

[1] https://www.ietf.org/rfc/rfc2898.txt (5.2 PBKDF2)

Cc Rafael J. Wysocki <[email protected]>
Cc "Theodore Ts'o" <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
Cc Eric Biggers <[email protected]>
Cc Stephan Mueller <[email protected]>
Cc Denis Kenzior <[email protected]>
Cc "Lee, Chun-Yi" <[email protected]>
---
 tools/power/crypto/Makefile           |  24 ++
 tools/power/crypto/crypto_hibernate.c | 462 ++++++++++++++++++++++++++++++++++
 2 files changed, 486 insertions(+)
 create mode 100644 tools/power/crypto/Makefile
 create mode 100644 tools/power/crypto/crypto_hibernate.c
tools/power/crypto/Makefile new file +24 -0
new file mode 100644
index 0000000..3544e64
@@ -0,0 +1,24 @@
+# SPDX-License-Identifier: GPL-2.0
+CC		= $(CROSS_COMPILE)gcc
+BUILD_OUTPUT	:= $(CURDIR)
+PREFIX		?= /usr
+DESTDIR		?=
+
+ifeq ("$(origin O)", "command line")
+	BUILD_OUTPUT := $(O)
+endif
+
+crypto_hibernate : crypto_hibernate.c
+CFLAGS +=	-Wall
+
+%: %.c
+	@mkdir -p $(BUILD_OUTPUT)
+	$(CC) $(CFLAGS) $< -o $(BUILD_OUTPUT)/$@
+
+.PHONY : clean
+clean :
+	@rm -f $(BUILD_OUTPUT)/crypto_hibernate
+
+install : crypto_hibernate
+	install -d  $(DESTDIR)$(PREFIX)/bin
+	install $(BUILD_OUTPUT)/crypto_hibernate $(DESTDIR)$(PREFIX)/bin/crypto_hibernate
tools/power/crypto/crypto_hibernate.c new file +462 -0

462 lines not on this page · raw message

Signature · 1 line
2.7.4
#4 lore raw
In reply to Chen Yu
Quoted 2 lines · Chen Yu

As security becomes more and more important, we add the in-kernel encryption support for hibernation.

Sorry, this does not really explain what security benefit it is supposed have to against what attack scenarios.

Which unfortunately means it can not reviewed.

Note that uswsusp already provides encryption. If this is supposed to have advantages over it, please say so.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#5 lore raw

Hi,

Quoted 4 lines · Pavel Machek
Quoted 2 lines · Chen Yu

As security becomes more and more important, we add the in-kernel encryption support for hibernation.

Quoted 8 lines

Sorry, this does not really explain what security benefit it is supposed have to against what attack scenarios.

Which unfortunately means it can not reviewed.

Note that uswsusp already provides encryption. If this is supposed to have advantages over it, please say so.

The advantages are described in detail in
[PATCH 1/4]'s log, please refer to that.
Thanks,
Yu

Quoted 5 lines

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#6 lore raw
Quoted 9 lines · Yu Chen

Hi,

Quoted 7 lines · Pavel Machek
Quoted 2 lines · Chen Yu

As security becomes more and more important, we add the in-kernel encryption support for hibernation.

Sorry, this does not really explain what security benefit it is supposed have to against what attack scenarios.

Quoted 7 lines
Quoted 5 lines

Which unfortunately means it can not reviewed.

Note that uswsusp already provides encryption. If this is supposed to have advantages over it, please say so.

The advantages are described in detail in
[PATCH 1/4]'s log, please refer to that.

Are you refering to this?

# Generally the advantage is: Users do not have to

# encrypt the whole swap partition as other tools.
# After all, ideally kernel memory should be encrypted
# by the kernel itself.

Sorry, this does not really explain what security benefit it is supposed have to against what attack scenarios.

Note that uswsusp already provides encryption. If this is supposed to have advantages over it, please say so.

Also note that joeyli <[email protected]> has patch series which encrypts both in-kernel and uswsusp hibernation methods. His motivation is secure boot. How does this compare to his work?

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#7 lore raw
Quoted 12 lines · Pavel Machek
Quoted 11 lines · Yu Chen

Hi,

Quoted 9 lines · Pavel Machek
Quoted 2 lines · Chen Yu

As security becomes more and more important, we add the in-kernel encryption support for hibernation.

Sorry, this does not really explain what security benefit it is supposed have to against what attack scenarios.

Which unfortunately means it can not reviewed.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Note that uswsusp already provides encryption. If this is supposed to have advantages over it, please say so.

The advantages are described in detail in
[PATCH 1/4]'s log, please refer to that.

Are you refering to this?

Not this one. I've sent v2 of this patch set which explain more on this:
https://patchwork.kernel.org/patch/10532935/
Let me paste the log here:

1. (This is not to compare with uswsusp but other tools) One advantage is: Users do not have to encrypt the whole swap partition as other tools.

2. Ideally kernel memory should be encrypted by the kernel itself. We have uswsusp to support user space hibernation, however doing the encryption in kernel space has more advantages:
2.1 Not having to transfer plain text kernel memory to
user space. Per Lee, Chun-Yi, uswsusp is disabled when the kernel is locked down:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/
linux-fs.git/commit/?h=lockdown-20180410& id=8732c1663d7c0305ae01ba5a1ee4d2299b7b4612 due to:
"There have some functions be locked-down because there have no appropriate mechanisms to check the integrity of writing data."
https://patchwork.kernel.org/patch/10476751/

2.2 Not having to copy each page to user space
one by one not in parallel, which might introduce significant amount of copy_to_user() and it might not be efficient on servers having large amount of DRAM.
2.3 Distribution has requirement to do snapshot
signature for verification, which can be built by leveraging this patch set.
2.4 The encryption is in the kernel, so it doesn't
have to worry too much about bugs in user space utilities and similar, for example.

Quoted 8 lines

# Generally the advantage is: Users do not have to

# encrypt the whole swap partition as other tools.
# After all, ideally kernel memory should be encrypted
# by the kernel itself.

Sorry, this does not really explain what security benefit it is supposed have to against what attack scenarios.

Quoted 7 lines

Note that uswsusp already provides encryption. If this is supposed to have advantages over it, please say so.

Also note that joeyli <[email protected]> has patch series which encrypts both in-kernel and uswsusp hibernation methods. His motivation is secure boot. How does this compare to his work?

Joey Lee and I had a discussion on his previous work at
https://patchwork.kernel.org/patch/10476751
We collaborate on this task and his snapshot signature feature can be based on this patch set.

Thanks,
Yu

#8 lore raw

Hi!

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 2 lines

As security becomes more and more important, we add the in-kernel encryption support for hibernation.

Sorry, this does not really explain what security benefit it is supposed have to against what attack scenarios.

Which unfortunately means it can not reviewed.

Note that uswsusp already provides encryption. If this is supposed to have advantages over it, please say so.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

The advantages are described in detail in
[PATCH 1/4]'s log, please refer to that.

Are you refering to this?

Not this one. I've sent v2 of this patch set which explain more on this:
https://patchwork.kernel.org/patch/10532935/

Aha, sorry about that.

Quoted 5 lines

Let me paste the log here:

1. (This is not to compare with uswsusp but other tools) One advantage is: Users do not have to encrypt the whole swap partition as other tools.

Well.. encrypting the partition seems like good idea anyway.

Quoted 7 lines

2. Ideally kernel memory should be encrypted by the kernel itself. We have uswsusp to support user space hibernation, however doing the encryption in kernel space has more advantages:
2.1 Not having to transfer plain text kernel memory to
user space. Per Lee, Chun-Yi, uswsusp is disabled when the kernel is locked down:

Quoted 8 lines

https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/
linux-fs.git/commit/?h=lockdown-20180410& id=8732c1663d7c0305ae01ba5a1ee4d2299b7b4612 due to:
"There have some functions be locked-down because there have no appropriate mechanisms to check the integrity of writing data."
https://patchwork.kernel.org/patch/10476751/

So your goal is to make hibernation compatible with kernel lockdown? Do your patches provide sufficient security that hibernation can be enabled with kernel lockdown?

Quoted 4 lines

2.2 Not having to copy each page to user space
one by one not in parallel, which might introduce significant amount of copy_to_user() and it might not be efficient on servers having large amount of DRAM.

So how big speedup can be attributed by not doing copy_to_user?

Quoted 3 lines

2.3 Distribution has requirement to do snapshot
signature for verification, which can be built by leveraging this patch set.

Signatures can be done by uswsusp, too, right?

Quoted 3 lines

2.4 The encryption is in the kernel, so it doesn't
have to worry too much about bugs in user space utilities and similar, for example.

Answer to bugs in userspace is _not_ to move code from userspace to kernel.

Quoted 8 lines
Quoted 4 lines

Also note that joeyli <[email protected]> has patch series which encrypts both in-kernel and uswsusp hibernation methods. His motivation is secure boot. How does this compare to his work?

Joey Lee and I had a discussion on his previous work at
https://patchwork.kernel.org/patch/10476751
We collaborate on this task and his snapshot signature feature can be based on this patch set.

Well, his work can also work without your patchset, right?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#9 lore raw
Quoted 1 line · Pavel Machek

Hi!

Hello,

Quoted 7 lines
Quoted 5 lines

Let me paste the log here:

1. (This is not to compare with uswsusp but other tools) One advantage is: Users do not have to encrypt the whole swap partition as other tools.

Well.. encrypting the partition seems like good idea anyway.

Yes, but it is a policy decision the kernel should not force. STD needs to work anyway.

Quoted 16 lines
Quoted 7 lines

2. Ideally kernel memory should be encrypted by the kernel itself. We have uswsusp to support user space hibernation, however doing the encryption in kernel space has more advantages:
2.1 Not having to transfer plain text kernel memory to
user space. Per Lee, Chun-Yi, uswsusp is disabled when the kernel is locked down:

Quoted 8 lines

https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/
linux-fs.git/commit/?h=lockdown-20180410& id=8732c1663d7c0305ae01ba5a1ee4d2299b7b4612 due to:
"There have some functions be locked-down because there have no appropriate mechanisms to check the integrity of writing data."
https://patchwork.kernel.org/patch/10476751/

Quoted 3 lines

So your goal is to make hibernation compatible with kernel lockdown? Do your patches provide sufficient security that hibernation can be enabled with kernel lockdown?

OK, maybe I am dense, but if the key comes from user space, will that be enough?

Quoted 6 lines
Quoted 4 lines

2.2 Not having to copy each page to user space
one by one not in parallel, which might introduce significant amount of copy_to_user() and it might not be efficient on servers having large amount of DRAM.

So how big speedup can be attributed by not doing copy_to_user?

That would be an argument for compression in kernel space. Not encrpting would always be faster.

Quoted 5 lines
Quoted 3 lines

2.3 Distribution has requirement to do snapshot
signature for verification, which can be built by leveraging this patch set.

Signatures can be done by uswsusp, too, right?

Not if you want to keep the chain of trust intact. User space is not signed.

Quoted 5 lines
Quoted 3 lines

2.4 The encryption is in the kernel, so it doesn't
have to worry too much about bugs in user space utilities and similar, for example.

Answer to bugs in userspace is _not_ to move code from userspace to kernel.

Indeed.

Quoted 6 lines
Quoted 4 lines

Joey Lee and I had a discussion on his previous work at
https://patchwork.kernel.org/patch/10476751
We collaborate on this task and his snapshot signature feature can be based on this patch set.

Well, his work can also work without your patchset, right?

Yes. But you are objecting to encryption in kernel space at all, aren't you?

Regards
Oliver

#10 lore raw

Hi!

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

2. Ideally kernel memory should be encrypted by the kernel itself. We have uswsusp to support user space hibernation, however doing the encryption in kernel space has more advantages:
2.1 Not having to transfer plain text kernel memory to
user space. Per Lee, Chun-Yi, uswsusp is disabled when the kernel is locked down:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/
linux-fs.git/commit/?h=lockdown-20180410& id=8732c1663d7c0305ae01ba5a1ee4d2299b7b4612 due to:
"There have some functions be locked-down because there have no appropriate mechanisms to check the integrity of writing data."
https://patchwork.kernel.org/patch/10476751/

Quoted 6 lines
Quoted 3 lines

So your goal is to make hibernation compatible with kernel lockdown? Do your patches provide sufficient security that hibernation can be enabled with kernel lockdown?

OK, maybe I am dense, but if the key comes from user space, will that be enough?

Yes, that seems to be one of problems of Yu Chen's patchset.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

Joey Lee and I had a discussion on his previous work at
https://patchwork.kernel.org/patch/10476751
We collaborate on this task and his snapshot signature feature can be based on this patch set.

Well, his work can also work without your patchset, right?

Yes. But you are objecting to encryption in kernel space at all, aren't you?

I don't particulary love the idea of doing hibernation encryption in the kernel, correct.

But we have this weird thing called secure boot, some people seem to want. So we may need some crypto in the kernel -- but I'd like something that works with uswsusp, too. Plus, it is mandatory that patch explains what security guarantees they want to provide against what kinds of attacks...

Lee, Chun-Yi's patch seemed more promising. Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#11 lore raw

Hello,

Quoted 18 lines · Pavel Machek

Hi!

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

2. Ideally kernel memory should be encrypted by the kernel itself. We have uswsusp to support user space hibernation, however doing the encryption in kernel space has more advantages:
2.1 Not having to transfer plain text kernel memory to
user space. Per Lee, Chun-Yi, uswsusp is disabled when the kernel is locked down:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/
linux-fs.git/commit/?h=lockdown-20180410& id=8732c1663d7c0305ae01ba5a1ee4d2299b7b4612 due to:
"There have some functions be locked-down because there have no appropriate mechanisms to check the integrity of writing data."
https://patchwork.kernel.org/patch/10476751/

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

So your goal is to make hibernation compatible with kernel lockdown? Do your patches provide sufficient security that hibernation can be enabled with kernel lockdown?

OK, maybe I am dense, but if the key comes from user space, will that be enough?

Yes, that seems to be one of problems of Yu Chen's patchset.

It is a trade off to derive the key in user space, we once tried to derive the key in user space, and people suggested a better way is to do it in user space. And there is a similar user case of kernel using key from user space is derived from ecryptfs for ext4.

Quoted 13 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

Joey Lee and I had a discussion on his previous work at
https://patchwork.kernel.org/patch/10476751
We collaborate on this task and his snapshot signature feature can be based on this patch set.

Well, his work can also work without your patchset, right?

Yes. But you are objecting to encryption in kernel space at all, aren't you?

I don't particulary love the idea of doing hibernation encryption in the kernel, correct.

Quoted 8 lines

But we have this weird thing called secure boot, some people seem to want. So we may need some crypto in the kernel -- but I'd like something that works with uswsusp, too. Plus, it is mandatory that patch explains what security guarantees they want to provide against what kinds of attacks...

Lee, Chun-Yi's patch seemed more promising. Pavel

The only difference between Chun-Yi's hibernation encrytion solution and our solution is that his strategy encrypts the snapshot from sratch, and ours encryts each page before them going to block device. The benefit of his solution is that the snapshot can be encrypt in kernel first thus the uswsusp is allowed to read it to user space even kernel is lock down. And I had a discussion with Chun-Yi that we can use his snapshot solution to make uswsusp happy, and we share the crypto help code and he can also use our user provided key for his signature. From this point of view, our code are actually the same, except that we can help clean up the code and also enhance some encrytion process for his solution. I don't know why you don't like encryption in kernel, because from my point of view, without encryption hibernation in kernel, uswsusp could not be enabled if kernel is lock down : -) Or do I miss something? Best,
Yu

Quoted 3 lines
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#12 lore raw

Hi!

Quoted 22 lines
Quoted 6 lines
Quoted 2 lines

Yes. But you are objecting to encryption in kernel space at all, aren't you?

I don't particulary love the idea of doing hibernation encryption in the kernel, correct.

Quoted 8 lines

But we have this weird thing called secure boot, some people seem to want. So we may need some crypto in the kernel -- but I'd like something that works with uswsusp, too. Plus, it is mandatory that patch explains what security guarantees they want to provide against what kinds of attacks...

Lee, Chun-Yi's patch seemed more promising. Pavel

The only difference between Chun-Yi's hibernation encrytion solution and our solution is that his strategy encrypts the snapshot from sratch, and ours encryts each page before them going to block device. The benefit of his solution is that the snapshot can be encrypt in kernel first thus the uswsusp is allowed to read it to user space even kernel is lock down. And I had a discussion with Chun-Yi that we can use his snapshot solution to make uswsusp happy, and we share the crypto help code and he can also use our user provided key for his signature.

Quoted 5 lines
Quoted 1 line

From this point of view, our code are actually the same, except that

we can help clean up the code and also enhance some encrytion process for his solution. I don't know why you don't like encryption in kernel, because from my point of view, without encryption hibernation in kernel, uswsusp could not be enabled if kernel is lock down : -) Or do I miss something?

We can do encryption in kernel if really needed, but I don't have to like it, do I? :-).

I understand what Chun-Yi's code is trying to do. I can't say the same about yours.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#13 lore raw
In reply to Pavel Machek
Quoted 11 lines · Pavel Machek
Quoted 2 lines

Yes. But you are objecting to encryption in kernel space at all, aren't you?

I don't particulary love the idea of doing hibernation encryption in the kernel, correct.

But we have this weird thing called secure boot, some people seem to want. So we may need some crypto in the kernel -- but I'd like something that works with uswsusp, too. Plus, it is mandatory that patch explains what security guarantees they want to provide against what kinds of attacks...

Hi,

very well, maybe we should state clearly that the goal of these patch set is to make Secure Boot and STD coexist. Anything else is a nice side effect, but not the primary justification, right?

And we further agree that the model of Secure Boot requires the encryption to be done in kernel space, don't we? Furthermore IMHO the key must also be generated in trusted code, hence in kernel space. Yu Chen, I really cannot see how a symmetrical encryption with a known key can be secure.

Regards
Oliver

#14 lore raw
Quoted 20 lines · Oliver Neukum
Quoted 11 lines · Pavel Machek
Quoted 2 lines

Yes. But you are objecting to encryption in kernel space at all, aren't you?

I don't particulary love the idea of doing hibernation encryption in the kernel, correct.

But we have this weird thing called secure boot, some people seem to want. So we may need some crypto in the kernel -- but I'd like something that works with uswsusp, too. Plus, it is mandatory that patch explains what security guarantees they want to provide against what kinds of attacks...

Hi,

very well, maybe we should state clearly that the goal of these patch set is to make Secure Boot and STD coexist. Anything else is a nice side effect, but not the primary justification, right?

Quoted 5 lines

And we further agree that the model of Secure Boot requires the encryption to be done in kernel space, don't we? Furthermore IMHO the key must also be generated in trusted code, hence in kernel space. Yu Chen, I really cannot see how a symmetrical encryption with a known key can be secure.

Nicely said. Yes, this is the message I was trying to get across.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#15 lore raw
In reply to Oliver Neukum

Hi,

Quoted 7 lines · Oliver Neukum
Quoted 1 line · Pavel Machek

Hi!

Hello,

Quoted 2 lines
Quoted 2 lines

Let me paste the log here:

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

1. (This is not to compare with uswsusp but other tools) One advantage is: Users do not have to encrypt the whole swap partition as other tools.

Well.. encrypting the partition seems like good idea anyway.

Yes, but it is a policy decision the kernel should not force. STD needs to work anyway.

If the swap partition is too large, and there's low usage of memory, then it might a little time costly to encrypt the whole partition. You are right, people has choice to choose which mode they like.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

2. Ideally kernel memory should be encrypted by the kernel itself. We have uswsusp to support user space hibernation, however doing the encryption in kernel space has more advantages:
2.1 Not having to transfer plain text kernel memory to
user space. Per Lee, Chun-Yi, uswsusp is disabled when the kernel is locked down:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/
linux-fs.git/commit/?h=lockdown-20180410& id=8732c1663d7c0305ae01ba5a1ee4d2299b7b4612 due to:
"There have some functions be locked-down because there have no appropriate mechanisms to check the integrity of writing data."
https://patchwork.kernel.org/patch/10476751/

Quoted 7 lines
Quoted 3 lines

So your goal is to make hibernation compatible with kernel lockdown? Do your patches provide sufficient security that hibernation can be enabled with kernel lockdown?

OK, maybe I am dense, but if the key comes from user space, will that be enough?

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.
Best,
Yu

Quoted 40 lines
Quoted 6 lines
Quoted 4 lines

2.2 Not having to copy each page to user space
one by one not in parallel, which might introduce significant amount of copy_to_user() and it might not be efficient on servers having large amount of DRAM.

So how big speedup can be attributed by not doing copy_to_user?

That would be an argument for compression in kernel space. Not encrpting would always be faster.

Quoted 5 lines
Quoted 3 lines

2.3 Distribution has requirement to do snapshot
signature for verification, which can be built by leveraging this patch set.

Signatures can be done by uswsusp, too, right?

Not if you want to keep the chain of trust intact. User space is not signed.

Quoted 5 lines
Quoted 3 lines

2.4 The encryption is in the kernel, so it doesn't
have to worry too much about bugs in user space utilities and similar, for example.

Answer to bugs in userspace is _not_ to move code from userspace to kernel.

Indeed.

Quoted 6 lines
Quoted 4 lines

Joey Lee and I had a discussion on his previous work at
https://patchwork.kernel.org/patch/10476751
We collaborate on this task and his snapshot signature feature can be based on this patch set.

Well, his work can also work without your patchset, right?

Yes. But you are objecting to encryption in kernel space at all, aren't you?

Regards
Oliver

#16 lore raw
Quoted 12 lines · Yu Chen

Hi,

Quoted 9 lines · Oliver Neukum
Quoted 3 lines · Pavel Machek

So your goal is to make hibernation compatible with kernel lockdown? Do your patches provide sufficient security that hibernation can be enabled with kernel lockdown?

OK, maybe I am dense, but if the key comes from user space, will that be enough?

Quoted 7 lines

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

It seems to me that your initial reasoning was correct and the key should be generated in kernel space.

Regards
Oliver

#17 lore raw
In reply to Yu Chen

Hi!

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

"There have some functions be locked-down because there have no appropriate mechanisms to check the integrity of writing data."
https://patchwork.kernel.org/patch/10476751/

So your goal is to make hibernation compatible with kernel lockdown? Do your patches provide sufficient security that hibernation can be enabled with kernel lockdown?

Quoted 7 lines
Quoted 3 lines

OK, maybe I am dense, but if the key comes from user space, will that be enough?

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.

Safe against what kind of attack? Please describe what kind of security you are trying to provide.

I don't think generating key in userspace is good enough for providing guarantees for secure-boot.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#18 lore raw
Quoted 15 lines · Pavel Machek

Hi!

Quoted 13 lines
Quoted 12 lines
Quoted 8 lines
Quoted 4 lines

"There have some functions be locked-down because there have no appropriate mechanisms to check the integrity of writing data."
https://patchwork.kernel.org/patch/10476751/

So your goal is to make hibernation compatible with kernel lockdown? Do your patches provide sufficient security that hibernation can be enabled with kernel lockdown?

OK, maybe I am dense, but if the key comes from user space, will that be enough?

Quoted 7 lines
Quoted 4 lines

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.

Safe against what kind of attack? Please describe what kind of security you are trying to provide.

Unsigned code must not take over the priviledge level of signed code. Hence:

1. Unsigned code must not allowed to read sensitive parts of signed code's memory space

2. Unsigned code must not be able to alter the memory space of signed code -> snapshots that are changed must not be able to be resumed

Quoted 2 lines

I don't think generating key in userspace is good enough for providing guarantees for secure-boot.

Why?

Regards
Oliver

#19 lore raw
Quoted 27 lines · Oliver Neukum
Quoted 15 lines · Pavel Machek

Hi!

Quoted 13 lines
Quoted 12 lines
Quoted 8 lines
Quoted 4 lines

"There have some functions be locked-down because there have no appropriate mechanisms to check the integrity of writing data."
https://patchwork.kernel.org/patch/10476751/

So your goal is to make hibernation compatible with kernel lockdown? Do your patches provide sufficient security that hibernation can be enabled with kernel lockdown?

OK, maybe I am dense, but if the key comes from user space, will that be enough?

Quoted 7 lines
Quoted 4 lines

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.

Safe against what kind of attack? Please describe what kind of security you are trying to provide.

Unsigned code must not take over the priviledge level of signed code. Hence:

Quoted 6 lines

1. Unsigned code must not allowed to read sensitive parts of signed code's memory space

2. Unsigned code must not be able to alter the memory space of signed code -> snapshots that are changed must not be able to be resumed

Ok.

Quoted 4 lines
Quoted 2 lines

I don't think generating key in userspace is good enough for providing guarantees for secure-boot.

Why?

Because then, userpace has both key (now) and encrypted image (after reboot), so it can decrypt, modify, re-encrypt...?

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#20 lore raw
Quoted 2 lines · Pavel Machek
Quoted 1 line · Oliver Neukum

On Di, 2018-07-24 at 14:01 +0200, Pavel Machek wrote:

Hi,

Quoted 15 lines
Quoted 6 lines
Quoted 2 lines

Safe against what kind of attack? Please describe what kind of security you are trying to provide.

Unsigned code must not take over the priviledge level of signed code. Hence:

Quoted 6 lines

1. Unsigned code must not allowed to read sensitive parts of signed code's memory space

2. Unsigned code must not be able to alter the memory space of signed code -> snapshots that are changed must not be able to be resumed

Ok.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I don't think generating key in userspace is good enough for providing guarantees for secure-boot.

Why?

Because then, userpace has both key (now) and encrypted image (after reboot), so it can decrypt, modify, re-encrypt...?

Right. I was dense. But if the key is generated in kernel space, the method works, doesn't it?

Regards
Oliver

#21 lore raw
In reply to Yu Chen
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative. The whole point of Secure Boot is a cryptographic system of trust that does not include user space.

I seriously doubt we want to use trusted computing here. So the key needs to be generated in kernel space and stored in a safe manner. As we have a saolution doing that, can we come to ausable synthesis?

Regards
Oliver

#22 lore raw
Quoted 17 lines · Oliver Neukum
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative. The whole point of Secure Boot is a cryptographic system of trust that does not include user space.

Quoted 7 lines

I seriously doubt we want to use trusted computing here. So the key needs to be generated in kernel space and stored in a safe manner. As we have a saolution doing that, can we come to ausable synthesis?

Regards
Oliver

Crurently there have two solutions, they are trusted key and EFI key. Both of them are generated in kernel and are not visible in user space.

The trusted key is generated by kernel then sealed by the TPM's SRK. So the trusted key can be stored in anywhere then be enrolled to kernel when we need it. EVM already uses it.

The EFI key is Jiri Kosina's idea. It is stored in boot services variable, which means that it can only be access by signed EFI binary (e.g. signed EFI boot stub) when secure boot be enabled. SLE applied this solution a couple of years.

I am working on put the EFI key to key retention service. Then EFI key can be a master key of encrypted key. EVM can also use it:
https://github.com/joeyli/linux-s4sign/commit/bae39460393ada4c0226dd07cd5e3afcef86b71f
https://github.com/joeyli/linux-s4sign/commit/f552f97cc3cca5acd84f424b7f946ffb5fe8e9ec

That's why I want to use key retention service in hibernation encryption/authentication. Which means that we can use key API to access trusted key and EFI key.

Thanks
Joey Lee

#23 lore raw

Hi all,

Quoted 44 lines · joeyli
Quoted 17 lines · Oliver Neukum
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative. The whole point of Secure Boot is a cryptographic system of trust that does not include user space.

Quoted 7 lines

I seriously doubt we want to use trusted computing here. So the key needs to be generated in kernel space and stored in a safe manner. As we have a saolution doing that, can we come to ausable synthesis?

Regards
Oliver

Crurently there have two solutions, they are trusted key and EFI key. Both of them are generated in kernel and are not visible in user space.

The trusted key is generated by kernel then sealed by the TPM's SRK. So the trusted key can be stored in anywhere then be enrolled to kernel when we need it. EVM already uses it.

The EFI key is Jiri Kosina's idea. It is stored in boot services variable, which means that it can only be access by signed EFI binary (e.g. signed EFI boot stub) when secure boot be enabled. SLE applied this solution a couple of years.

I am working on put the EFI key to key retention service. Then EFI key can be a master key of encrypted key. EVM can also use it:
https://github.com/joeyli/linux-s4sign/commit/bae39460393ada4c0226dd07cd5e3afcef86b71f
https://github.com/joeyli/linux-s4sign/commit/f552f97cc3cca5acd84f424b7f946ffb5fe8e9ec

Quoted 4 lines

That's why I want to use key retention service in hibernation encryption/authentication. Which means that we can use key API to access trusted key and EFI key.

Here is a proof of concept for using the key retention service to encrypt/sign snapshot image. It's using EFI key now, I will add encrypted key support in the key handler later:

    https://github.com/joeyli/linux-s4sign/commit/6311e97038974bc5de8121769fb4d34470009566 

My next step is that cleaning up the my EFI key type patches and submit it to EFI/keys subsystem ASAP. Then I will clean up my hibernation encryption/authentication solution for reviewing.

Thanks
Joey Lee

author
#24 lore raw

Hi Joey,

Quoted 52 lines · joeyli

Hi all,

Quoted 44 lines · joeyli
Quoted 17 lines · Oliver Neukum
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative. The whole point of Secure Boot is a cryptographic system of trust that does not include user space.

Quoted 7 lines

I seriously doubt we want to use trusted computing here. So the key needs to be generated in kernel space and stored in a safe manner. As we have a saolution doing that, can we come to ausable synthesis?

Regards
Oliver

Crurently there have two solutions, they are trusted key and EFI key. Both of them are generated in kernel and are not visible in user space.

The trusted key is generated by kernel then sealed by the TPM's SRK. So the trusted key can be stored in anywhere then be enrolled to kernel when we need it. EVM already uses it.

The EFI key is Jiri Kosina's idea. It is stored in boot services variable, which means that it can only be access by signed EFI binary (e.g. signed EFI boot stub) when secure boot be enabled. SLE applied this solution a couple of years.

I am working on put the EFI key to key retention service. Then EFI key can be a master key of encrypted key. EVM can also use it:
https://github.com/joeyli/linux-s4sign/commit/bae39460393ada4c0226dd07cd5e3afcef86b71f
https://github.com/joeyli/linux-s4sign/commit/f552f97cc3cca5acd84f424b7f946ffb5fe8e9ec

Quoted 4 lines

That's why I want to use key retention service in hibernation encryption/authentication. Which means that we can use key API to access trusted key and EFI key.

Quoted 5 lines

Here is a proof of concept for using the key retention service to encrypt/sign snapshot image. It's using EFI key now, I will add encrypted key support in the key handler later:

    https://github.com/joeyli/linux-s4sign/commit/6311e97038974bc5de8121769fb4d34470009566 

Thanks for the work, I have two questions here:
1. Could you please describe a little more about the scenario on
how the user could use the secret key for hibernation encryption?
A requirement is that, the user should provide a passphrase(for key derivation, i.e.) during resume. I was thinking how user could interact with
the security key mechanism here.

2. The generation of secret key in EFI boot environment is using a non standard derivation method in generate_secret_key(), I'm not sure if this is safe enough. This is why we tried to put PBKDF2 into kernel at first and leave it to the user space then.

Best,
Yu

Quoted 6 lines

My next step is that cleaning up the my EFI key type patches and submit it to EFI/keys subsystem ASAP. Then I will clean up my hibernation encryption/authentication solution for reviewing.

Thanks
Joey Lee

#25 lore raw
Quoted 54 lines · Yu Chen

Hi Joey,

Quoted 52 lines · joeyli

Hi all,

Quoted 48 lines · joeyli
Quoted 17 lines · Oliver Neukum
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative. The whole point of Secure Boot is a cryptographic system of trust that does not include user space.

Quoted 7 lines

I seriously doubt we want to use trusted computing here. So the key needs to be generated in kernel space and stored in a safe manner. As we have a saolution doing that, can we come to ausable synthesis?

Regards
Oliver

Crurently there have two solutions, they are trusted key and EFI key. Both of them are generated in kernel and are not visible in user space.

The trusted key is generated by kernel then sealed by the TPM's SRK. So the trusted key can be stored in anywhere then be enrolled to kernel when we need it. EVM already uses it.

The EFI key is Jiri Kosina's idea. It is stored in boot services variable, which means that it can only be access by signed EFI binary (e.g. signed EFI boot stub) when secure boot be enabled. SLE applied this solution a couple of years.

I am working on put the EFI key to key retention service. Then EFI key can be a master key of encrypted key. EVM can also use it:
https://github.com/joeyli/linux-s4sign/commit/bae39460393ada4c0226dd07cd5e3afcef86b71f
https://github.com/joeyli/linux-s4sign/commit/f552f97cc3cca5acd84f424b7f946ffb5fe8e9ec

That's why I want to use key retention service in hibernation encryption/authentication. Which means that we can use key API to access trusted key and EFI key.

Quoted 6 lines
Quoted 5 lines

Here is a proof of concept for using the key retention service to encrypt/sign snapshot image. It's using EFI key now, I will add encrypted key support in the key handler later:

    https://github.com/joeyli/linux-s4sign/commit/6311e97038974bc5de8121769fb4d34470009566 

Thanks for the work, I have two questions here:

My EFI key patch set is almost done. I will send it soon.

Quoted 6 lines

1. Could you please describe a little more about the scenario on
how the user could use the secret key for hibernation encryption?
A requirement is that, the user should provide a passphrase(for key derivation, i.e.) during resume. I was thinking how user could interact with
the security key mechanism here.

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Quoted 5 lines

2. The generation of secret key in EFI boot environment is using a non standard derivation method in generate_secret_key(), I'm not sure if this is safe enough. This is why we tried to put PBKDF2 into kernel at first and leave it to the user space then.

Thank you for point out.

The generate_secret_key() reuse the logic in kaslr_get_random_long() that it produces random seed by RDRAND, RDTSC and i8254. It doesn't standard like PBKDF2, but we do not have too many choices in the early boot stage. At least KASLR is using the same logic.

We can relay on user space helper. But the helper must be authenticated by kernel. Currently we do not have kernel mechanism to verity user space process.

Regards
Joey Lee

#26 lore raw
Quoted 56 lines · joeyli
Quoted 54 lines · Yu Chen

Hi Joey,

Quoted 52 lines · joeyli

Hi all,

Quoted 48 lines · joeyli
Quoted 17 lines · Oliver Neukum
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative. The whole point of Secure Boot is a cryptographic system of trust that does not include user space.

Quoted 7 lines

I seriously doubt we want to use trusted computing here. So the key needs to be generated in kernel space and stored in a safe manner. As we have a saolution doing that, can we come to ausable synthesis?

Regards
Oliver

Crurently there have two solutions, they are trusted key and EFI key. Both of them are generated in kernel and are not visible in user space.

The trusted key is generated by kernel then sealed by the TPM's SRK. So the trusted key can be stored in anywhere then be enrolled to kernel when we need it. EVM already uses it.

The EFI key is Jiri Kosina's idea. It is stored in boot services variable, which means that it can only be access by signed EFI binary (e.g. signed EFI boot stub) when secure boot be enabled. SLE applied this solution a couple of years.

I am working on put the EFI key to key retention service. Then EFI key can be a master key of encrypted key. EVM can also use it:
https://github.com/joeyli/linux-s4sign/commit/bae39460393ada4c0226dd07cd5e3afcef86b71f
https://github.com/joeyli/linux-s4sign/commit/f552f97cc3cca5acd84f424b7f946ffb5fe8e9ec

That's why I want to use key retention service in hibernation encryption/authentication. Which means that we can use key API to access trusted key and EFI key.

Quoted 9 lines
Quoted 6 lines
Quoted 5 lines

Here is a proof of concept for using the key retention service to encrypt/sign snapshot image. It's using EFI key now, I will add encrypted key support in the key handler later:

    https://github.com/joeyli/linux-s4sign/commit/6311e97038974bc5de8121769fb4d34470009566

Thanks for the work, I have two questions here:

My EFI key patch set is almost done. I will send it soon.

Okay, please send them out then we can have further discussion on that.

Quoted 7 lines
Quoted 6 lines

1. Could you please describe a little more about the scenario on
how the user could use the secret key for hibernation encryption?
A requirement is that, the user should provide a passphrase(for key derivation, i.e.) during resume. I was thinking how user could interact with
the security key mechanism here.

Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the key and encrypted the hibernation snapshot and stores it on the disk . Then if user
B wants to do a hibernation resume to A's previous environment, B has to provide the same passphrase.
If I understand correctly, the secret key is saved in header and stored on the disk. Which means, any one can read the header from the disk to get the secret key in trampoline thus decrypt the image, which is not safe.
Best,
Yu

Quoted 19 lines
Quoted 5 lines

2. The generation of secret key in EFI boot environment is using a non standard derivation method in generate_secret_key(), I'm not sure if this is safe enough. This is why we tried to put PBKDF2 into kernel at first and leave it to the user space then.

Thank you for point out.

The generate_secret_key() reuse the logic in kaslr_get_random_long() that it produces random seed by RDRAND, RDTSC and i8254. It doesn't standard like PBKDF2, but we do not have too many choices in the early boot stage. At least KASLR is using the same logic.

We can relay on user space helper. But the helper must be authenticated by kernel. Currently we do not have kernel mechanism to verity user space process.

Regards
Joey Lee

Signature · 2 lines
Thanks,
Ryan
#27 lore raw
Quoted 80 lines · Ryan Chen
Quoted 56 lines · joeyli
Quoted 54 lines · Yu Chen

Hi Joey,

Quoted 52 lines · joeyli

Hi all,

Quoted 48 lines · joeyli
Quoted 17 lines · Oliver Neukum
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative. The whole point of Secure Boot is a cryptographic system of trust that does not include user space.

Quoted 7 lines

I seriously doubt we want to use trusted computing here. So the key needs to be generated in kernel space and stored in a safe manner. As we have a saolution doing that, can we come to ausable synthesis?

Regards
Oliver

Crurently there have two solutions, they are trusted key and EFI key. Both of them are generated in kernel and are not visible in user space.

The trusted key is generated by kernel then sealed by the TPM's SRK. So the trusted key can be stored in anywhere then be enrolled to kernel when we need it. EVM already uses it.

The EFI key is Jiri Kosina's idea. It is stored in boot services variable, which means that it can only be access by signed EFI binary (e.g. signed EFI boot stub) when secure boot be enabled. SLE applied this solution a couple of years.

I am working on put the EFI key to key retention service. Then EFI key can be a master key of encrypted key. EVM can also use it:
https://github.com/joeyli/linux-s4sign/commit/bae39460393ada4c0226dd07cd5e3afcef86b71f
https://github.com/joeyli/linux-s4sign/commit/f552f97cc3cca5acd84f424b7f946ffb5fe8e9ec

That's why I want to use key retention service in hibernation encryption/authentication. Which means that we can use key API to access trusted key and EFI key.

Quoted 9 lines
Quoted 6 lines
Quoted 5 lines

Here is a proof of concept for using the key retention service to encrypt/sign snapshot image. It's using EFI key now, I will add encrypted key support in the key handler later:

    https://github.com/joeyli/linux-s4sign/commit/6311e97038974bc5de8121769fb4d34470009566

Thanks for the work, I have two questions here:

My EFI key patch set is almost done. I will send it soon.

Okay, please send them out then we can have further discussion on that.

Quoted 7 lines
Quoted 6 lines

1. Could you please describe a little more about the scenario on
how the user could use the secret key for hibernation encryption?
A requirement is that, the user should provide a passphrase(for key derivation, i.e.) during resume. I was thinking how user could interact with
the security key mechanism here.

Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Quoted 13 lines

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the key and encrypted the hibernation snapshot and stores it on the disk . Then if user
B wants to do a hibernation resume to A's previous environment, B has to provide the same passphrase.
If I understand correctly, the secret key is saved in header and stored on the disk. Which means, any one can read the header from the disk to get the secret key in trampoline thus decrypt the image, which is not safe.

The secret key that it's saved in snapshot header is a session key which is encrypted by ERK (EFI root key). The ERK only lives in kernel space. So the session key is still secure.

When resume, the session key will be decrypted/verified by ERK. Then kernel uses the session key to decrypted/verified snapshot image.

Of course that we can direct use ERK to encrypt/authenticate snapshot image. Actually the first version of hibernation verification in SLE direct uses ERK. So the snapshot header only keeps signature but no encrypted session key.

I add session key in new version because I want to align with the use case of TPM trusted key + encrypted key. Then hibernation can use key retention service API to access EFI key or encrypted key.

Compare the trusted key with EFI secure key:

TPM SRK ----seal-----> Trusted key ---encrypt---> Encrypted key
ERK ---encrypt---> EFI secure key ---encrypt---> Encrypted key

Both of them can be the master key of encrypted key.

If EFI key can not be accepted by kernel community, then the TPM trusted key + encrypted key will be the only solution. We can very easy to switch to encrypted key by using key retention service API.

Thanks a lot!
Joey Lee

#28 lore raw
Quoted 96 lines · joeyli
Quoted 80 lines · Ryan Chen
Quoted 56 lines · joeyli
Quoted 54 lines · Yu Chen

Hi Joey,

Quoted 52 lines · joeyli

Hi all,

Quoted 48 lines · joeyli
Quoted 17 lines · Oliver Neukum
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative. The whole point of Secure Boot is a cryptographic system of trust that does not include user space.

Quoted 7 lines

I seriously doubt we want to use trusted computing here. So the key needs to be generated in kernel space and stored in a safe manner. As we have a saolution doing that, can we come to ausable synthesis?

Regards
Oliver

Crurently there have two solutions, they are trusted key and EFI key. Both of them are generated in kernel and are not visible in user space.

The trusted key is generated by kernel then sealed by the TPM's SRK. So the trusted key can be stored in anywhere then be enrolled to kernel when we need it. EVM already uses it.

The EFI key is Jiri Kosina's idea. It is stored in boot services variable, which means that it can only be access by signed EFI binary (e.g. signed EFI boot stub) when secure boot be enabled. SLE applied this solution a couple of years.

I am working on put the EFI key to key retention service. Then EFI key can be a master key of encrypted key. EVM can also use it:
https://github.com/joeyli/linux-s4sign/commit/bae39460393ada4c0226dd07cd5e3afcef86b71f
https://github.com/joeyli/linux-s4sign/commit/f552f97cc3cca5acd84f424b7f946ffb5fe8e9ec

That's why I want to use key retention service in hibernation encryption/authentication. Which means that we can use key API to access trusted key and EFI key.

Quoted 9 lines
Quoted 6 lines
Quoted 5 lines

Here is a proof of concept for using the key retention service to encrypt/sign snapshot image. It's using EFI key now, I will add encrypted key support in the key handler later:

    https://github.com/joeyli/linux-s4sign/commit/6311e97038974bc5de8121769fb4d34470009566

Thanks for the work, I have two questions here:

My EFI key patch set is almost done. I will send it soon.

Okay, please send them out then we can have further discussion on that.

Quoted 7 lines
Quoted 6 lines

1. Could you please describe a little more about the scenario on
how the user could use the secret key for hibernation encryption?
A requirement is that, the user should provide a passphrase(for key derivation, i.e.) during resume. I was thinking how user could interact with
the security key mechanism here.

Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Quoted 13 lines

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the key and encrypted the hibernation snapshot and stores it on the disk . Then if user
B wants to do a hibernation resume to A's previous environment, B has to provide the same passphrase.
If I understand correctly, the secret key is saved in header and stored on the disk. Which means, any one can read the header from the disk to get the secret key in trampoline thus decrypt the image, which is not safe.

Quoted 7 lines

The secret key that it's saved in snapshot header is a session key which is encrypted by ERK (EFI root key). The ERK only lives in kernel space. So the session key is still secure.

When resume, the session key will be decrypted/verified by ERK. Then kernel uses the session key to decrypted/verified snapshot image.

OK, I see.

Quoted 9 lines

Of course that we can direct use ERK to encrypt/authenticate snapshot image. Actually the first version of hibernation verification in SLE direct uses ERK. So the snapshot header only keeps signature but no encrypted session key.

I add session key in new version because I want to align with the use case of TPM trusted key + encrypted key. Then hibernation can use key retention service API to access EFI key or encrypted key.

Quoted 7 lines

Compare the trusted key with EFI secure key:

TPM SRK ----seal-----> Trusted key ---encrypt---> Encrypted key
ERK ---encrypt---> EFI secure key ---encrypt---> Encrypted key

Both of them can be the master key of encrypted key.

So either Trusted key or EFI secure key(session key) could be used for snapshot encryption, right?

Quoted 5 lines

If EFI key can not be accepted by kernel community, then the TPM trusted key + encrypted key will be the only solution. We can very easy to switch to encrypted key by using key retention service API.

Back to question raised previously, how could TPM or EFI key be used to prevent user B from resuming to the environment of A? It appears to me
that, although A is the user who launches the hibernation, B could
resume to the context of A because there's no certification during
resume. Is there any way to introduce the password based verification? Best,
Yu

Quoted 2 lines

Thanks a lot!
Joey Lee

#29 lore raw
Quoted 116 lines · Ryan Chen
Quoted 96 lines · joeyli
Quoted 80 lines · Ryan Chen
Quoted 56 lines · joeyli
Quoted 54 lines · Yu Chen

Hi Joey,

Quoted 52 lines · joeyli

Hi all,

Quoted 48 lines · joeyli
Quoted 17 lines · Oliver Neukum
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative. The whole point of Secure Boot is a cryptographic system of trust that does not include user space.

Quoted 7 lines

I seriously doubt we want to use trusted computing here. So the key needs to be generated in kernel space and stored in a safe manner. As we have a saolution doing that, can we come to ausable synthesis?

Regards
Oliver

Crurently there have two solutions, they are trusted key and EFI key. Both of them are generated in kernel and are not visible in user space.

The trusted key is generated by kernel then sealed by the TPM's SRK. So the trusted key can be stored in anywhere then be enrolled to kernel when we need it. EVM already uses it.

The EFI key is Jiri Kosina's idea. It is stored in boot services variable, which means that it can only be access by signed EFI binary (e.g. signed EFI boot stub) when secure boot be enabled. SLE applied this solution a couple of years.

I am working on put the EFI key to key retention service. Then EFI key can be a master key of encrypted key. EVM can also use it:
https://github.com/joeyli/linux-s4sign/commit/bae39460393ada4c0226dd07cd5e3afcef86b71f
https://github.com/joeyli/linux-s4sign/commit/f552f97cc3cca5acd84f424b7f946ffb5fe8e9ec

That's why I want to use key retention service in hibernation encryption/authentication. Which means that we can use key API to access trusted key and EFI key.

Quoted 9 lines
Quoted 6 lines
Quoted 5 lines

Here is a proof of concept for using the key retention service to encrypt/sign snapshot image. It's using EFI key now, I will add encrypted key support in the key handler later:

    https://github.com/joeyli/linux-s4sign/commit/6311e97038974bc5de8121769fb4d34470009566

Thanks for the work, I have two questions here:

My EFI key patch set is almost done. I will send it soon.

Okay, please send them out then we can have further discussion on that.

Quoted 7 lines
Quoted 6 lines

1. Could you please describe a little more about the scenario on
how the user could use the secret key for hibernation encryption?
A requirement is that, the user should provide a passphrase(for key derivation, i.e.) during resume. I was thinking how user could interact with
the security key mechanism here.

Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Quoted 13 lines

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the key and encrypted the hibernation snapshot and stores it on the disk . Then if user
B wants to do a hibernation resume to A's previous environment, B has to provide the same passphrase.
If I understand correctly, the secret key is saved in header and stored on the disk. Which means, any one can read the header from the disk to get the secret key in trampoline thus decrypt the image, which is not safe.

Quoted 7 lines

The secret key that it's saved in snapshot header is a session key which is encrypted by ERK (EFI root key). The ERK only lives in kernel space. So the session key is still secure.

When resume, the session key will be decrypted/verified by ERK. Then kernel uses the session key to decrypted/verified snapshot image.

OK, I see.

Quoted 11 lines

Of course that we can direct use ERK to encrypt/authenticate snapshot image. Actually the first version of hibernation verification in SLE direct uses ERK. So the snapshot header only keeps signature but no encrypted session key.

I add session key in new version because I want to align with the use case of TPM trusted key + encrypted key. Then hibernation can use key retention service API to access EFI key or encrypted key.

Compare the trusted key with EFI secure key:

Quoted 7 lines
Quoted 5 lines

TPM SRK ----seal-----> Trusted key ---encrypt---> Encrypted key
ERK ---encrypt---> EFI secure key ---encrypt---> Encrypted key

Both of them can be the master key of encrypted key.

So either Trusted key or EFI secure key(session key) could be used for snapshot encryption, right?

Yes. Or we can use encrypted key. It depends on different use case.

If the trusted key is sealed with PCRs, then we can not generate new trusted key after PCRs be capped. Then we can only use the encrypted key as the session key.

Quoted 10 lines
Quoted 5 lines

If EFI key can not be accepted by kernel community, then the TPM trusted key + encrypted key will be the only solution. We can very easy to switch to encrypted key by using key retention service API.

Back to question raised previously, how could TPM or EFI key be used to prevent user B from resuming to the environment of A? It appears to me
that, although A is the user who launches the hibernation, B could
resume to the context of A because there's no certification during
resume. Is there any way to introduce the password based verification?

I see you point. Yes, TPM or EFI key can only be used to prevent that the content in snapshot image be detected on other machine. It can not be used to prevent the snapshot image be resumed on _the same_ machine by different user. Sounds like B can physical accessing the machine. Could you please explain more detail for the case?

As you said, password is useful in this case. But I have no idea for how to introduce password without user space helper. And user space helper must be authenticate by kernel. Which means that we need to add mechanism to verify user space binary.

Thanks
Joey Lee

#30 lore raw
In reply to Ryan Chen

Hi!

Quoted 10 lines
Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the

No, I don't think that's purpose here.

Purpose here is to prevent user from reading/modifying kernel memory content on machine he owns.

Strange as it may sound, that is what "secure" boot requires (and what Disney wants).

I guess it may have some non-evil uses,
too... https://www.linux.com/news/matthew-garrett-explains-how-increase-security-boot-time

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#31 lore raw

Hi Pavel,

Quoted 13 lines · Pavel Machek

Hi!

Quoted 10 lines
Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the

Quoted 5 lines

No, I don't think that's purpose here.

Purpose here is to prevent user from reading/modifying kernel memory content on machine he owns.

Say, A puts his laptop into hibernation and walks away, and B walks by, and opens A's laptop and wakes up the system and he can do what he wants. Although EFI key/TPM trusted key is enabled, currently there's no certification during resume, which sounds unsafe to me. Afterall, the original requirement is to probe user for password during resume, which sounds more natural.

Quoted 3 lines

Strange as it may sound, that is what "secure" boot requires (and what Disney wants).

Ok, I understand this requirement, and I'm also concerning how to distinguish different users from seeing data of each other.

Joey,
I'm thinking of a possible direction which could take advantage of the password. It leverages either EFI key or TPM trusted key to get it done. Does it make sense?

1. The user space generates a symetric key key_user using the password, and passes the key_user to the kernel as the master key.
2. The kernel uses the EFI key or TPM trusted key to encrypt the key_user thus gets a encrypt_key.
3. Uses the encrypt_key to do snapshot encryption
4. During resume, the same encrypt_key is generated following the same steps(I assume the same EFI key or TPM key could be fetched during resumed, right?) and do the snapshot decryption.

And this is what fscrypt is doing:
Documentation/filesystems/fscrypt.rst

Best,
Yu

Quoted 8 lines

I guess it may have some non-evil uses,
too... https://www.linux.com/news/matthew-garrett-explains-how-increase-security-boot-time

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#32 lore raw
Quoted 20 lines · Yu Chen

Hi Pavel,

Quoted 13 lines · Pavel Machek

Hi!

Quoted 10 lines
Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the

Quoted 5 lines

No, I don't think that's purpose here.

Purpose here is to prevent user from reading/modifying kernel memory content on machine he owns.

Quoted 6 lines

Say, A puts his laptop into hibernation and walks away, and B walks by, and opens A's laptop and wakes up the system and he can do what he wants. Although EFI key/TPM trusted key is enabled, currently there's no certification during resume, which sounds unsafe to me. Afterall, the original requirement is to probe user for password during resume, which sounds more natural.

OK, I saw your case. This is a physical accessing.

I have a question: The suspend to memory also has the same behavior and more people are using suspend. Should we think a common solution to cover S3 and S4?

Quoted 11 lines
Quoted 3 lines

Strange as it may sound, that is what "secure" boot requires (and what Disney wants).

Ok, I understand this requirement, and I'm also concerning how to distinguish different users from seeing data of each other.

Joey,
I'm thinking of a possible direction which could take advantage of the password. It leverages either EFI key or TPM trusted key to get it done. Does it make sense?

Quoted 10 lines

1. The user space generates a symetric key key_user using the password, and passes the key_user to the kernel as the master key.
2. The kernel uses the EFI key or TPM trusted key to encrypt the key_user thus gets a encrypt_key.
3. Uses the encrypt_key to do snapshot encryption
4. During resume, the same encrypt_key is generated following the same steps(I assume the same EFI key or TPM key could be fetched during resumed, right?) and do the snapshot decryption.

Yes, we can use TPM key to protect the user key. But I suggest that we should give user a function to disable the user key because not everyone want to key-in a password for hibernate/resume and also snapshot image encryption.

Two policies:
- When user key-in user key, the snapshot image must be encryption.
- Without key-in user key, I still want the snapshot image can be encryption.

No matter that the user key be key-in or not, the snapshot image must be encrypted by a kernel key. So I suggest that we treat the user key as a salt for snapshot image encryption and authentication. If the user key be disabled, then kernel just generates a random number as a salt.

Actually, the kernel must compares the user key before snapshot decryption. If the user key doesn't match but user space still triggers furture resume process. Then kernel direct drops the snapshot image.

Quoted 3 lines

And this is what fscrypt is doing:
Documentation/filesystems/fscrypt.rst

The use case is different. We have two key for two purposes. And the two functions can be separated.

Thanks
Joey Lee

author
#33 lore raw
Quoted 28 lines · joeyli
Quoted 20 lines · Yu Chen

Hi Pavel,

Quoted 13 lines · Pavel Machek

Hi!

Quoted 10 lines
Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the

Quoted 5 lines

No, I don't think that's purpose here.

Purpose here is to prevent user from reading/modifying kernel memory content on machine he owns.

Quoted 6 lines

Say, A puts his laptop into hibernation and walks away, and B walks by, and opens A's laptop and wakes up the system and he can do what he wants. Although EFI key/TPM trusted key is enabled, currently there's no certification during resume, which sounds unsafe to me. Afterall, the original requirement is to probe user for password during resume, which sounds more natural.

Quoted 6 lines

OK, I saw your case. This is a physical accessing.

I have a question: The suspend to memory also has the same behavior and more people are using suspend. Should we think a common solution to cover S3 and S4?

Since STD behaves more likely a boot up, STR does not have solid requirement for certification.

Quoted 31 lines
Quoted 11 lines
Quoted 3 lines

Strange as it may sound, that is what "secure" boot requires (and what Disney wants).

Ok, I understand this requirement, and I'm also concerning how to distinguish different users from seeing data of each other.

Joey,
I'm thinking of a possible direction which could take advantage of the password. It leverages either EFI key or TPM trusted key to get it done. Does it make sense?

Quoted 10 lines

1. The user space generates a symetric key key_user using the password, and passes the key_user to the kernel as the master key.
2. The kernel uses the EFI key or TPM trusted key to encrypt the key_user thus gets a encrypt_key.
3. Uses the encrypt_key to do snapshot encryption
4. During resume, the same encrypt_key is generated following the same steps(I assume the same EFI key or TPM key could be fetched during resumed, right?) and do the snapshot decryption.

Yes, we can use TPM key to protect the user key. But I suggest that we should give user a function to disable the user key because not everyone want to key-in a password for hibernate/resume and also snapshot image encryption.

Two policies:
- When user key-in user key, the snapshot image must be encryption.
- Without key-in user key, I still want the snapshot image can be encryption.

Quoted 9 lines

No matter that the user key be key-in or not, the snapshot image must be encrypted by a kernel key. So I suggest that we treat the user key as a salt for snapshot image encryption and authentication. If the user key be disabled, then kernel just generates a random number as a salt.

Actually, the kernel must compares the user key before snapshot decryption. If the user key doesn't match but user space still triggers furture resume process. Then kernel direct drops the snapshot image.

Anyway I'm ok with using TPM for major 'security', please feel free to send a second version out, and for certification implementation we can have further discussion on that later.

Best,
Yu

Quoted 8 lines
Quoted 3 lines

And this is what fscrypt is doing:
Documentation/filesystems/fscrypt.rst

The use case is different. We have two key for two purposes. And the two functions can be separated.

Thanks
Joey Lee

#34 lore raw
Quoted 29 lines · Yu Chen
Quoted 28 lines · joeyli
Quoted 26 lines · Yu Chen

Hi Pavel,

Quoted 13 lines · Pavel Machek

Hi!

Quoted 10 lines
Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the

Quoted 5 lines

No, I don't think that's purpose here.

Purpose here is to prevent user from reading/modifying kernel memory content on machine he owns.

Say, A puts his laptop into hibernation and walks away, and B walks by, and opens A's laptop and wakes up the system and he can do what he wants. Although EFI key/TPM trusted key is enabled, currently there's no certification during resume, which sounds unsafe to me. Afterall, the original requirement is to probe user for password during resume, which sounds more natural.

Quoted 8 lines
Quoted 6 lines

OK, I saw your case. This is a physical accessing.

I have a question: The suspend to memory also has the same behavior and more people are using suspend. Should we think a common solution to cover S3 and S4?

Since STD behaves more likely a boot up, STR does not have solid requirement for certification.

In your A/B user case, when STR, B user can still open A's laptop and wakes up the system and do what he wants because he can get the console like resume from STD. I didn't see difference.

Quoted 36 lines
Quoted 36 lines
Quoted 11 lines
Quoted 3 lines

Strange as it may sound, that is what "secure" boot requires (and what Disney wants).

Ok, I understand this requirement, and I'm also concerning how to distinguish different users from seeing data of each other.

Joey,
I'm thinking of a possible direction which could take advantage of the password. It leverages either EFI key or TPM trusted key to get it done. Does it make sense?

Quoted 10 lines

1. The user space generates a symetric key key_user using the password, and passes the key_user to the kernel as the master key.
2. The kernel uses the EFI key or TPM trusted key to encrypt the key_user thus gets a encrypt_key.
3. Uses the encrypt_key to do snapshot encryption
4. During resume, the same encrypt_key is generated following the same steps(I assume the same EFI key or TPM key could be fetched during resumed, right?) and do the snapshot decryption.

Yes, we can use TPM key to protect the user key. But I suggest that we should give user a function to disable the user key because not everyone want to key-in a password for hibernate/resume and also snapshot image encryption.

Two policies:
- When user key-in user key, the snapshot image must be encryption.
- Without key-in user key, I still want the snapshot image can be encryption.

No matter that the user key be key-in or not, the snapshot image must be encrypted by a kernel key. So I suggest that we treat the user key as a salt for snapshot image encryption and authentication. If the user key be disabled, then kernel just generates a random number as a salt.

Quoted 8 lines
Quoted 4 lines

Actually, the kernel must compares the user key before snapshot decryption. If the user key doesn't match but user space still triggers furture resume process. Then kernel direct drops the snapshot image.

Anyway I'm ok with using TPM for major 'security', please feel free to send a second version out, and for certification implementation we can have further discussion on that later.

Regards
Joey Lee

#35 lore raw
In reply to joeyli
Quoted 28 lines · joeyli
Quoted 20 lines · Yu Chen

Hi Pavel,

Quoted 13 lines · Pavel Machek

Hi!

Quoted 10 lines
Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the

Quoted 5 lines

No, I don't think that's purpose here.

Purpose here is to prevent user from reading/modifying kernel memory content on machine he owns.

Quoted 6 lines

Say, A puts his laptop into hibernation and walks away, and B walks by, and opens A's laptop and wakes up the system and he can do what he wants. Although EFI key/TPM trusted key is enabled, currently there's no certification during resume, which sounds unsafe to me. Afterall, the original requirement is to probe user for password during resume, which sounds more natural.

Quoted 5 lines

OK, I saw your case. This is a physical accessing.

I have a question: The suspend to memory also has the same behavior and more people are using suspend. Should we think a common solution to cover S3 and S4?

Well, we have similar problem during runtime, too ;-).

Anyway, I don't think we should encrypt memory during S3 in kernel.

If you wanted to do that, you could use uswsusp to take snapshot, store it in ram, encrypt, erase originals (new API might be needed... hmm. does not exactly sound easy... kexec?), trigger S3, decrypt, resume from snapshot...

Sounds like a bit of work...

Best regards,

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#36 lore raw

Hi,

Quoted 31 lines · Pavel Machek
Quoted 30 lines · joeyli
Quoted 20 lines · Yu Chen

Hi Pavel,

Quoted 13 lines · Pavel Machek

Hi!

Quoted 10 lines
Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the

Quoted 5 lines

No, I don't think that's purpose here.

Purpose here is to prevent user from reading/modifying kernel memory content on machine he owns.

Quoted 6 lines

Say, A puts his laptop into hibernation and walks away, and B walks by, and opens A's laptop and wakes up the system and he can do what he wants. Although EFI key/TPM trusted key is enabled, currently there's no certification during resume, which sounds unsafe to me. Afterall, the original requirement is to probe user for password during resume, which sounds more natural.

OK, I saw your case. This is a physical accessing.

Quoted 8 lines
Quoted 3 lines

I have a question: The suspend to memory also has the same behavior and more people are using suspend. Should we think a common solution to cover S3 and S4?

Well, we have similar problem during runtime, too ;-).

Anyway, I don't think we should encrypt memory during S3 in kernel.

It seems that Joey was talking about certification(something like login) rather than encryption?

Best,
Yu

Quoted 13 lines

If you wanted to do that, you could use uswsusp to take snapshot, store it in ram, encrypt, erase originals (new API might be needed... hmm. does not exactly sound easy... kexec?), trigger S3, decrypt, resume from snapshot...

Sounds like a bit of work...

Best regards,

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#37 lore raw
Quoted 37 lines · Yu Chen

Hi,

Quoted 35 lines · Pavel Machek
Quoted 33 lines · joeyli
Quoted 20 lines · Yu Chen

Hi Pavel,

Quoted 13 lines · Pavel Machek

Hi!

Quoted 10 lines
Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the

Quoted 5 lines

No, I don't think that's purpose here.

Purpose here is to prevent user from reading/modifying kernel memory content on machine he owns.

Quoted 6 lines

Say, A puts his laptop into hibernation and walks away, and B walks by, and opens A's laptop and wakes up the system and he can do what he wants. Although EFI key/TPM trusted key is enabled, currently there's no certification during resume, which sounds unsafe to me. Afterall, the original requirement is to probe user for password during resume, which sounds more natural.

OK, I saw your case. This is a physical accessing.

I have a question: The suspend to memory also has the same behavior and more people are using suspend. Should we think a common solution to cover S3 and S4?

Quoted 7 lines
Quoted 4 lines

Well, we have similar problem during runtime, too ;-).

Anyway, I don't think we should encrypt memory during S3 in kernel.

It seems that Joey was talking about certification(something like login) rather than encryption?

Actually I do not have good idea.

Joey Lee

#38 lore raw
In reply to Yu Chen

Hi!

Quoted 13 lines
Quoted 13 lines
Quoted 10 lines
Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the

No, I don't think that's purpose here.

Quoted 8 lines
Quoted 3 lines

Purpose here is to prevent user from reading/modifying kernel memory content on machine he owns.

Say, A puts his laptop into hibernation and walks away, and B walks by, and opens A's laptop and wakes up the system and he can do what he wants. Although EFI key/TPM trusted key is enabled, currently there's no certification during resume, which sounds unsafe to me. Afterall, the original requirement is to probe

Define unsafe.

If you want security against bad people resuming your machines, please take a look at existing uswsusp solutions. It defends against that.

If you want security against bad people tampering with your machines physically, sorry, there's no way to defend against that.

But I thought you were trying to do something for secure boot, and "bad person resumes your machine" is out of scope there.

So please always explain security against _what kind of attack_ you are trying to improve; intelligent communication is not possible without that.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#39 lore raw

Hi Pavel, Joey, Oliver
Please let me describe the original requirement and my understanding about hibernation encryption here, thus help us sync on the same thread:

Quoted 24 lines · Pavel Machek

Hi!

Quoted 13 lines
Quoted 13 lines
Quoted 10 lines
Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the

No, I don't think that's purpose here.

Quoted 8 lines
Quoted 3 lines

Purpose here is to prevent user from reading/modifying kernel memory content on machine he owns.

Say, A puts his laptop into hibernation and walks away, and B walks by, and opens A's laptop and wakes up the system and he can do what he wants. Although EFI key/TPM trusted key is enabled, currently there's no certification during resume, which sounds unsafe to me. Afterall, the original requirement is to probe

Quoted 3 lines

Define unsafe.

If you want security against bad people resuming your machines, please

Yes, this is one of the requirements.

Quoted 4 lines

take a look at existing uswsusp solutions. It defends against that.

If you want security against bad people tampering with your machines physically, sorry, there's no way to defend against that.

No, this is not the requirement.

Quoted 4 lines

But I thought you were trying to do something for secure boot, and "bad person resumes your machine" is out of scope there.

Not exactly, secure boot is one solution to meet the requirement.

Quoted 4 lines

So please always explain security against _what kind of attack_ you are trying to improve; intelligent communication is not possible without that.

User requirement:
A is the user, B is the attacker, user A launches a STD and encrypts A's ram data, then writes these encrypted data onto the disk, so that: Even if user B has access to the disk, B could not know the content of A. Which implies:
1. If B unplugs the disk from A's machine, and plugs the disk onto another machine, B could not decode the content without A's 'permission'.
2. If B is using the same machine as A, even A has walked away leaving the system suspend, B could not resume to A's context without A's 'permission'.

Previously, there are three proposal for this:
a. Enhance the uswsusp(Pavel)
b. Using user provided password to generate the key, for encryption(Yu) c. Using security boot(TPM or EFI key) for encryption(Joey)

Since I was proposing solution b, I'll say a little more about it. The original idea was that, the user provides a password, then this password is used to generate the key, which means, if user B has provided an incorrect password, the kernel will fail to decrypt the data and is likely to fail the resume process. That is to say, no matter which physical machine B is using, only if he has provided the password, he would be able to resume. In the first version, the key deviration was firstly done in kernel space, which satisfies the requirement and both saftey. Unfortunately it was rejected and people would like to see the key generated in user space instead. However, using user provided key directly is not safe, according to the discussion in the thread. I don't have good idea on how to improve this, but only have some workarounds, say, ask the kernel to use TPM key to protects the user provided 'key', etc.

Then let's talk a little more about secure boot. According to my understanding, the situation secure boot tries to deal with is a little different from the user case we raised above - It is an enhancement for case 1, because it refuses to resume once the machine is changed. And it does not cover case 2. But if it is a requirement from the user, that's ok.

uswsusp is to do all the staff in user space, and other two aim to do all the staff in kernel space. I'm not arguing which one is better, but I'm not sure how often user is using it, as we don't get uswsusp related bug report on kernel bugzilla (both internally)recent years. Another point is, why the compression is in kernel rather than in uswsusp, it looks like the same case as encryption here.

Best,
Yu

#40 lore raw

Hi!

Quoted 9 lines
Quoted 3 lines

Define unsafe.

If you want security against bad people resuming your machines, please

Yes, this is one of the requirements.

Quoted 3 lines

But I thought you were trying to do something for secure boot, and "bad person resumes your machine" is out of scope there.

Not exactly, secure boot is one solution to meet the requirement.

Is it? AFAICT secure boot is something else. "Not even owner can see kernel memory".

Quoted 4 lines
Quoted 4 lines

So please always explain security against _what kind of attack_ you are trying to improve; intelligent communication is not possible without that.

Quoted 11 lines

User requirement:
A is the user, B is the attacker, user A launches a STD and encrypts A's ram data, then writes these encrypted data onto the disk, so that: Even if user B has access to the disk, B could not know the content of A. Which implies:
1. If B unplugs the disk from A's machine, and plugs the disk onto another machine, B could not decode the content without A's 'permission'.
2. If B is using the same machine as A, even A has walked away leaving the system suspend, B could not resume to A's context without A's 'permission'.

Ok. Let's call this "effective resume password".

Quoted 2 lines

Previously, there are three proposal for this:
a. Enhance the uswsusp(Pavel)

Actually you don't have to enhance anything. Uswsusp already provides "effective resume password".

If you only want to ask for password on resume, RSA is needed.

Quoted 6 lines

Then let's talk a little more about secure boot. According to my understanding, the situation secure boot tries to deal with is a little different from the user case we raised above - It is an enhancement for case 1, because it refuses to resume once the machine is changed. And it does not cover case 2. But if it is a requirement from the user, that's ok.

That does not match my understanding of secure boot.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#41 lore raw
In reply to Yu Chen

On Do, 2018-08-09 at 11:01 +0800, Yu Chen wrote:

Hi,

Quoted 8 lines

User requirement:
A is the user, B is the attacker, user A launches a STD and encrypts A's ram data, then writes these encrypted data onto the disk, so that: Even if user B has access to the disk, B could not know the content of A. Which implies:
1. If B unplugs the disk from A's machine, and plugs the disk onto another machine, B could not decode the content without A's 'permission'.

That is what encrypted STD does.

Quoted 3 lines

2. If B is using the same machine as A, even A has walked away leaving the system suspend, B could not resume to A's context without A's 'permission'.

No, that is out of scope for Secure Boot

Quoted 5 lines

Previously, there are three proposal for this:
a. Enhance the uswsusp(Pavel)
b. Using user provided password to generate the key, for encryption(Yu) c. Using security boot(TPM or EFI key) for encryption(Joey)

Quoted 14 lines

Since I was proposing solution b, I'll say a little more about it. The original idea was that, the user provides a password, then this password is used to generate the key, which means, if user B has provided an incorrect password, the kernel will fail to decrypt the data and is likely to fail the resume process. That is to say, no matter which physical machine B is using, only if he has provided the password, he would be able to resume. In the first version, the key deviration was firstly done in kernel space, which satisfies the requirement and both saftey. Unfortunately it was rejected and people would like to see the key generated in user space instead. However, using user provided key directly is not safe, according to the discussion in the thread. I don't have good idea on how to improve this, but only have some workarounds, say, ask the kernel to use TPM key to protects the user provided 'key', etc.

Well, this has no relation to Secure Boot.
Secure Boot will not prevent you from booting the machine. It restricts the OS you can boot to a cryptographically signed subset.

If you want to demand a password to resume a machine, you can do so. But it has no relation to encrypted STD, other than that you need encrypted STD for this to make sense.

Quoted 7 lines

Then let's talk a little more about secure boot. According to my understanding, the situation secure boot tries to deal with is a little different from the user case we raised above - It is an enhancement for case 1, because it refuses to resume once the machine is changed. And it does not cover case 2. But if it is a requirement from the user, that's ok.

Quoted 7 lines

uswsusp is to do all the staff in user space, and other two aim to do all the staff in kernel space. I'm not arguing which one is better, but I'm not sure how often user is using it, as we don't get uswsusp related bug report on kernel bugzilla (both internally)recent years. Another point is, why the compression is in kernel rather than in uswsusp, it looks like the same case as encryption here.

Secure Boot has no concept of users. Code is trusted, not users. For Secure Boot to work, you need a key generated and RAM encrypted in kernel space.

If you want a requirement to restrict booting or resuming, you need to encrypt the key. These are different things.

Regards
Oliver

#42 lore raw
In reply to Yu Chen
Quoted 59 lines · Yu Chen

Hi Pavel, Joey, Oliver
Please let me describe the original requirement and my understanding about hibernation encryption here, thus help us sync on the same thread:

Quoted 24 lines · Pavel Machek

Hi!

Quoted 13 lines
Quoted 13 lines
Quoted 10 lines
Quoted 5 lines

User space doesn't need to involve. The EFI root key is generated by EFI boot stub and be transfer to kernel. It's stored in EFI boot service variable that it can only be accessed by trusted EFI binary when secure boot is enabled.

Okay, this apply to the 'suspend' phase, right?
I'm still a little confused about the 'resume' phase.
Taking encryption as example(not signature),
the purpose of doing hibernation encryption is to prevent other users from stealing ram content. Say, user A uses a passphrase to generate the

No, I don't think that's purpose here.

Quoted 8 lines
Quoted 3 lines

Purpose here is to prevent user from reading/modifying kernel memory content on machine he owns.

Say, A puts his laptop into hibernation and walks away, and B walks by, and opens A's laptop and wakes up the system and he can do what he wants. Although EFI key/TPM trusted key is enabled, currently there's no certification during resume, which sounds unsafe to me. Afterall, the original requirement is to probe

Quoted 3 lines

Define unsafe.

If you want security against bad people resuming your machines, please

Yes, this is one of the requirements.

Quoted 4 lines

take a look at existing uswsusp solutions. It defends against that.

If you want security against bad people tampering with your machines physically, sorry, there's no way to defend against that.

No, this is not the requirement.

Quoted 4 lines

But I thought you were trying to do something for secure boot, and "bad person resumes your machine" is out of scope there.

Not exactly, secure boot is one solution to meet the requirement.

Quoted 4 lines

So please always explain security against _what kind of attack_ you are trying to improve; intelligent communication is not possible without that.

User requirement:
A is the user, B is the attacker, user A launches a STD and encrypts A's ram data, then writes these encrypted data onto the disk, so that: Even if user B has access to the disk, B could not know the content of A. Which implies:
1. If B unplugs the disk from A's machine, and plugs the disk onto another machine, B could not decode the content without A's 'permission'.
2. If B is using the same machine as A, even A has walked away leaving the system suspend, B could not resume to A's context without A's 'permission'.

Quoted 3 lines

Previously, there are three proposal for this:
a. Enhance the uswsusp(Pavel)
b. Using user provided password to generate the key, for encryption(Yu)

Base on your A/B users case. Your requirement is a" resume password", it doesn't really neeed encryption.

Of course we can use the password to encrypt image, but it's not the key point for your requirement.

Quoted 2 lines

c. Using security boot(TPM or EFI key) for encryption(Joey)

No! The EFI key that relies on secure boot is failed. The only solution is TPM trusted key.

I agreed with Ard's comment on my EFI secure key patches:

https://lkml.org/lkml/2018/8/5/31

"'Secure boot' is a misnomer, since it is too vague: it should be called 'authenticated boot', and the catch is that authentication using public-key crypto does not involve secrets at all."

So the EFI key can not be accepted because the secure boot is not designed for confidentiality. So, please forget EFI key. The only solution to me (or secure boot) is TPM trusted key.

My purpose for developing the hibernation encryption/authentication is to prevent that the snapshot image be malicious modified. This will cause that the kernel space is not safe for secure boot (or we call it authenticated boot). In kernel space, we want to use locked-down mode to keep kernel space safe.

That's also why I said that user space helper must be authenticated by kernel. It also prevents malicious key can be enroll to kernel space.

Quoted 6 lines

Since I was proposing solution b, I'll say a little more about it. The original idea was that, the user provides a password, then this password is used to generate the key, which means, if user B has provided an incorrect password, the kernel will fail to decrypt the data and is likely to fail the resume process. That is to say, no matter which physical machine B is using, only if he has provided the

Quoted 8 lines

password, he would be able to resume. In the first version, the key deviration was firstly done in kernel space, which satisfies the requirement and both saftey. Unfortunately it was rejected and people would like to see the key generated in user space instead. However, using user provided key directly is not safe, according to the discussion in the thread. I don't have good idea on how to improve this, but only have some workarounds, say, ask the kernel to use TPM key to protects the user provided 'key', etc.

Do not need to combind two purposes to one solution. Your requirement is a "resume password", not snapshot encryption. So we can just encrypt snapshot by TPM encrypted key but still use your tool (or uswsusp) to provide "resume password" to user. It's not conflict.

If we still want to use the "resume password" to encrypt snapashot image. That's fine, but hibernation function must be locked-down when kernel runs in lock-down mode. Because "resume password" doesn't help anything in lockdown mode. Unless we found a way to authenticate the user space helper by kernel.

Regards
Joey Lee

author
#43 lore raw
In reply to Oliver Neukum

Hi Oliver,

Quoted 10 lines · Oliver Neukum
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

Quoted 4 lines

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative.

Humm, I did not quite get the point here, let's take fscrypt for example, the kernel gets user generated key from user space, and uses per-inode nonce(random bytes) as the master key to do a KDF(key derivation function) on user provided key, and uses that key for encryption. We can also added similar mechanism to generate the key in kernel space but the key should be original from user's provided key(password derived), because the security boot/signature mechanism could not cover the case that, two different users could resume to each other's context because there isn't any certification during resume if it is on the same physical hardware.

Best,
Yu

Quoted 13 lines

The whole point of Secure
Boot is a cryptographic system of trust that does not include user space.

I seriously doubt we want to use trusted computing here. So the key needs to be generated in kernel space and stored in a safe manner. As we have a saolution doing that, can we come to ausable synthesis?

Regards
Oliver

#44 lore raw
Quoted 11 lines · Yu Chen

Hi Oliver,

Quoted 9 lines · Oliver Neukum
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

As Ard and James's comments, the EFI key can not be accepted:

	https://lkml.org/lkml/2018/8/5/135

The lower entropy problem can be covered by RDRAND or EFI random protocol. But the key point is that we can not fully trust manufacturer. And, the secure boot relies on Microsoft's business interests. It's not designed for confidentiality.

So I will move to TPM trusted key + encrypted key.

Quoted 5 lines
Quoted 5 lines

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative.

Quoted 12 lines

Humm, I did not quite get the point here, let's take fscrypt for example, the kernel gets user generated key from user space, and uses per-inode nonce(random bytes) as the master key to do a KDF(key derivation function) on user provided key, and uses that key for encryption. We can also added similar mechanism to generate the key in kernel space but the key should be original from user's provided key(password derived), because the security boot/signature mechanism could not cover the case that, two different users could resume to each other's context because there isn't any certification during resume if it is on the same physical hardware.

Sounds there have two different purposes. One is to prevent that the secret in snapshop image be detected/changed outside the machine. Another one try to prevent that B user resumes to A user's context on the same machine.

In the case of B resumes A's context, I still think that the attacker must physical accesses the machine. Which means that it's out of EFI secure boot's design. Could you please explan the detail for the attack?

So I think that the password from user space is for user authentication, and the TPM trusted key is for snapshot image encryption/verification.

Thanks
Joey Lee

author
#45 lore raw
Quoted 14 lines · joeyli
Quoted 11 lines · Yu Chen

Hi Oliver,

Quoted 9 lines · Oliver Neukum
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

As Ard and James's comments, the EFI key can not be accepted:

Quoted 9 lines
	https://lkml.org/lkml/2018/8/5/135

The lower entropy problem can be covered by RDRAND or EFI random protocol. But the key point is that we can not fully trust manufacturer. And, the secure boot relies on Microsoft's business interests. It's not designed for confidentiality.

So I will move to TPM trusted key + encrypted key.

OK.

Quoted 18 lines
Quoted 5 lines
Quoted 5 lines

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative.

Quoted 12 lines

Humm, I did not quite get the point here, let's take fscrypt for example, the kernel gets user generated key from user space, and uses per-inode nonce(random bytes) as the master key to do a KDF(key derivation function) on user provided key, and uses that key for encryption. We can also added similar mechanism to generate the key in kernel space but the key should be original from user's provided key(password derived), because the security boot/signature mechanism could not cover the case that, two different users could resume to each other's context because there isn't any certification during resume if it is on the same physical hardware.

Quoted 5 lines

Sounds there have two different purposes. One is to prevent that the secret in snapshop image be detected/changed outside the machine. Another one try to prevent that B user resumes to A user's context on the same machine.

Yes, it aims to prevent B from resuming to A's context no matter whether it is on the same hardware or not, and prevents others from getting the plain content on the disk.

Quoted 4 lines

In the case of B resumes A's context, I still think that the attacker must physical accesses the machine. Which means that it's out of EFI secure boot's design. Could you please explan the detail for the attack?

May I know what attack does it refer to? please refer to another mail I sent to Pavel, a simple use case has been described.

Quoted 3 lines

So I think that the password from user space is for user authentication, and the TPM trusted key is for snapshot image encryption/verification.

password generated key could also be used as encryption.

Best,
Yu

Quoted 2 lines

Thanks
Joey Lee

#46 lore raw
In reply to Yu Chen
Quoted 12 lines · Yu Chen

Hi Oliver,

Quoted 10 lines · Oliver Neukum
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

Quoted 6 lines
Quoted 4 lines

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative.

Humm, I did not quite get the point here, let's take fscrypt

While the system is running and the fs is mounted, your data is as secure as root access to your machine, right? You encrypt a disk primarily so data cannot be recovered (and altered) while the system is not running.

Secure Boot does not trust root fully. There is a cryptographic chain of trust and user space is not part of it.

Quoted 10 lines

for example, the kernel gets user generated key from user space, and uses per-inode nonce(random bytes) as the master key to do a KDF(key derivation function) on user provided key, and uses that key for encryption. We can also added similar mechanism to generate the key in kernel space but the key should be original from user's provided key(password derived), because the security boot/signature mechanism could not cover the case that, two different users could resume to each other's context because there isn't any certification during resume if it is on the same physical hardware.

Please explain. You will always have to suspend the whole machine with all tasks of all users. And STD with Secure Boot need not imply that you encrypt your discs. You need to encrypt only kernel memory to meet the requirements.

As STD affects the whole machine it must require root rights. So I cannot see how you can talk about a session belonging to a user. Please explain.

It seems to me that you can in theory encrypt the password by a key coming from user space, so that you need to know an additional key to resume the system, but that seems to me above and beyond what Secure Boot requires.

Regards
Oliver

author
#47 lore raw
Quoted 20 lines · Oliver Neukum
Quoted 12 lines · Yu Chen

Hi Oliver,

Quoted 10 lines · Oliver Neukum
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

Quoted 6 lines
Quoted 4 lines

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative.

Humm, I did not quite get the point here, let's take fscrypt

Quoted 8 lines

While the system is running and the fs is mounted, your data is as secure as root access to your machine, right? You encrypt a disk primarily so data cannot be recovered (and altered) while the system is not running.

Secure Boot does not trust root fully. There is a cryptographic chain of trust and user space is not part of it.

Okay, I see. So if we want to use secure boot mechanism for hibernation encryption, user space is trusted.

Quoted 11 lines
Quoted 10 lines

for example, the kernel gets user generated key from user space, and uses per-inode nonce(random bytes) as the master key to do a KDF(key derivation function) on user provided key, and uses that key for encryption. We can also added similar mechanism to generate the key in kernel space but the key should be original from user's provided key(password derived), because the security boot/signature mechanism could not cover the case that, two different users could resume to each other's context because there isn't any certification during resume if it is on the same physical hardware.

Quoted 9 lines

Please explain. You will always have to suspend the whole machine with all tasks of all users. And STD with Secure Boot need not imply that you encrypt your discs. You need to encrypt only kernel memory to meet the requirements.

As STD affects the whole machine it must require root rights. So I cannot see how you can talk about a session belonging to a user. Please explain.

The case is for physical access, not the 'user' in OS.

Quoted 5 lines

It seems to me that you can in theory encrypt the password by a key coming from user space, so that you need to know an additional key to resume the system, but that seems to me above and beyond what Secure Boot requires.

Understand.

Best,
Yu

Quoted 3 lines

Regards
Oliver

#48 lore raw
Quoted 27 lines · Yu Chen
Quoted 25 lines · Oliver Neukum
Quoted 12 lines · Yu Chen

Hi Oliver,

Quoted 10 lines · Oliver Neukum
Quoted 8 lines · Yu Chen

Good point, we once tried to generate key in kernel, but people suggest to generate key in userspace and provide it to the kernel, which is what ecryptfs do currently, so it seems this should also be safe for encryption in kernel.
https://www.spinics.net/lists/linux-crypto/msg33145.html
Thus Chun-Yi's signature can use EFI key and both the key from user space.

Quoted 6 lines
Quoted 4 lines

Hi,

ecryptfs can trust user space. It is supposed to keep data safe while the system is inoperative.

Humm, I did not quite get the point here, let's take fscrypt

While the system is running and the fs is mounted, your data is as secure as root access to your machine, right? You encrypt a disk primarily so data cannot be recovered (and altered) while the system is not running.

Quoted 5 lines
Quoted 3 lines

Secure Boot does not trust root fully. There is a cryptographic chain of trust and user space is not part of it.

Okay, I see. So if we want to use secure boot mechanism for hibernation encryption, user space is trusted.

s/ is trusted/is not trusted/

#49 lore raw
In reply to Yu Chen
Quoted 6 lines · Yu Chen
Quoted 4 lines

As STD affects the whole machine it must require root rights. So I cannot see how you can talk about a session belonging to a user. Please explain.

The case is for physical access, not the 'user' in OS.

Well, yes, but Secure Boot does not guard against anybody booting or halting the machine. It limits what you can boot by a chain of trust.

I think you are trying to add a feature to Secure Boot.

Regards
Oliver

#50 lore raw
In reply to Oliver Neukum

Hi Oliver,

Quoted 49 lines · Oliver Neukum
Quoted 1 line · Pavel Machek

Hi!

Hello,

Quoted 7 lines
Quoted 5 lines

Let me paste the log here:

1. (This is not to compare with uswsusp but other tools) One advantage is: Users do not have to encrypt the whole swap partition as other tools.

Well.. encrypting the partition seems like good idea anyway.

Yes, but it is a policy decision the kernel should not force. STD needs to work anyway.

Quoted 16 lines
Quoted 7 lines

2. Ideally kernel memory should be encrypted by the kernel itself. We have uswsusp to support user space hibernation, however doing the encryption in kernel space has more advantages:
2.1 Not having to transfer plain text kernel memory to
user space. Per Lee, Chun-Yi, uswsusp is disabled when the kernel is locked down:

Quoted 8 lines

https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/
linux-fs.git/commit/?h=lockdown-20180410& id=8732c1663d7c0305ae01ba5a1ee4d2299b7b4612 due to:
"There have some functions be locked-down because there have no appropriate mechanisms to check the integrity of writing data."
https://patchwork.kernel.org/patch/10476751/

Quoted 3 lines

So your goal is to make hibernation compatible with kernel lockdown? Do your patches provide sufficient security that hibernation can be enabled with kernel lockdown?

OK, maybe I am dense, but if the key comes from user space, will that be enough?

Quoted 6 lines
Quoted 4 lines

2.2 Not having to copy each page to user space
one by one not in parallel, which might introduce significant amount of copy_to_user() and it might not be efficient on servers having large amount of DRAM.

So how big speedup can be attributed by not doing copy_to_user?

That would be an argument for compression in kernel space. Not encrpting would always be faster.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

2.3 Distribution has requirement to do snapshot
signature for verification, which can be built by leveraging this patch set.

Signatures can be done by uswsusp, too, right?

Not if you want to keep the chain of trust intact. User space is not signed.

Yes, any user space key helper must be authenticated for secure boot (or the kernel locked-down mode).

If user choices the user space helper, then they should awares that this approach can not be trusted when kernel is in locked-down mode. The user space helper be protected by IMA/EVM, or the initrd be authentricated with trusted boot.

The user space key helper is useful when the machine doesn't have TPM or EFI firmware, but user still wants to use the hibernation encryption/verification.

For kernel locked-down mode, EFI key or trusted key TPM can be trusted because they can only be created/visibled in kernel space.

Thanks
Joey Lee

#51 lore raw
In reply to Pavel Machek

Hi,

Quoted 28 lines · Pavel Machek
Quoted 9 lines · Yu Chen

Hi,

Quoted 7 lines · Pavel Machek
Quoted 2 lines · Chen Yu

As security becomes more and more important, we add the in-kernel encryption support for hibernation.

Sorry, this does not really explain what security benefit it is supposed have to against what attack scenarios.

Quoted 7 lines
Quoted 5 lines

Which unfortunately means it can not reviewed.

Note that uswsusp already provides encryption. If this is supposed to have advantages over it, please say so.

The advantages are described in detail in
[PATCH 1/4]'s log, please refer to that.

Are you refering to this?

# Generally the advantage is: Users do not have to

# encrypt the whole swap partition as other tools.
# After all, ideally kernel memory should be encrypted
# by the kernel itself.

Sorry, this does not really explain what security benefit it is supposed have to against what attack scenarios.

Quoted 7 lines

Note that uswsusp already provides encryption. If this is supposed to have advantages over it, please say so.

Also note that joeyli <[email protected]> has patch series which encrypts both in-kernel and uswsusp hibernation methods. His motivation is secure boot. How does this compare to his work?

My patchset signs and encrypts the snapshot image pages in memory. The main logic is applied to snapshot.c

https://github.com/joeyli/linux-s4sign/commit/bae39460393ada4c0226dd07cd5e3afcef86b71f

The pros of my solution is that the signed/encrypted snapshot image can be stored to anywhere. Both in-kernel and userspace.

Yu's patch is encrypt the page buffer before sending to block io layer for writing to swap. The main logic is applied to swap.c. It's against the swap solution in-kernel.

The pros of Yu's solution is that it encrypts the compressed image data. So, for the huge system memory case, it has better performance.

Yu's plan is using the sysfs to switch different encrypt/sign solutions. And, we will share encrypt/sign helper and key manager in the above two solutions.

Thanks a lot!
Joey Lee

A message that is not in the archive (sent off-list or not yet received): edf92acf665b928f02104bb1835fd50723ab9980.1531924968.git.yu.c.chen@intel.com

author
#53 lore raw

Re: [PATCH 3/4][RFC v2] PM / Hibernate: Encrypt the snapshot pages before submitted to the block device

Cc [email protected] and [email protected]

Quoted 450 lines · Chen Yu

This is the core modification to encrypt the hibernation image. It leverages the helper functions to encrypt the page data before they are submitted to the block device. Besides, for the case of hibernation compression, the data are firstly compressed and then encrypted, and vice versa for the resume process.

There is also another solution suggested by Lee, Chun-Yi to re-traverse the snapshot image at one time and write them either to disk or exposed to user space. In that way if the snapshot image can be encrypted and authentication, then the uswsusp interface is available for userspace, kernel does not need to lock it down. The only disadvantages are re-traversing large number of pages in snapshot might bring overhead and makes snapshot logic a little coupling with crypto logic.

Cc Rafael J. Wysocki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Len Brown <[email protected]>
Cc "Lee, Chun-Yi" <[email protected]>
Cc Eric Biggers <[email protected]>
Cc "Theodore Ts'o" <[email protected]>
Cc Stephan Mueller <[email protected]>
Cc Denis Kenzior <[email protected]>
---
 kernel/power/power.h |  23 +++++++
 kernel/power/swap.c  | 182 ++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 197 insertions(+), 8 deletions(-)
kernel/power/power.h +23 -0
index ba3b24c..b8ddc05 100644
@@ -109,8 +109,30 @@ struct hibernation_crypto {
 
 extern void hibernation_set_crypto_ops(
 	const struct hibernation_crypto_ops *ops);
+
+/**
+ * get_crypto_cmd - Get the crypto command.
+ * @suspend: In suspend.
+ * @last_page: If this is the last page. For signature's
+ * 	       hash update/final checking.
+ */
+static inline unsigned int get_crypto_cmd(bool suspend,
+		bool last_page)
+{
+	/* TODO: signature support */
+	if (suspend) {
+		return CMD_ENCRYPT;
+	} else {
+		return CMD_DECRYPT;
+	}
+}
 #else
 #define HIBERNATE_MAX_SALT_BYTES	0
+static inline unsigned int get_crypto_cmd(bool suspend,
+		bool last_page)
+{
+	return -EINVAL;
+}
 #endif
 
 #else /* !CONFIG_HIBERNATION */
@@ -214,6 +236,7 @@ extern int swsusp_swap_in_use(void);
 #define SF_PLATFORM_MODE	1
 #define SF_NOCOMPRESS_MODE	2
 #define SF_CRC32_MODE	        4
+#define SF_CRYPTO_MODE		8
 
 /* kernel/power/hibernate.c */
 extern int swsusp_check(void);
kernel/power/swap.c +174 -8
index c2bcf97..4b36fb7 100644
@@ -102,14 +102,16 @@ struct swap_map_handle {
 	unsigned int k;
 	unsigned long reqd_free_pages;
 	u32 crc32;
+	bool crypto;
 };
 
 struct swsusp_header {
 	char reserved[PAGE_SIZE - 20 - sizeof(sector_t) - sizeof(int) -
-	              sizeof(u32)];
+			sizeof(u32) - HIBERNATE_MAX_SALT_BYTES];
 	u32	crc32;
 	sector_t image;
 	unsigned int flags;	/* Flags to pass to the "boot" kernel */
+	char salt[HIBERNATE_MAX_SALT_BYTES];
 	char	orig_sig[10];
 	char	sig[10];
 } __packed;
@@ -318,6 +320,10 @@ static int mark_swapfiles(struct swap_map_handle *handle, unsigned int flags)
 		swsusp_header->flags = flags;
 		if (flags & SF_CRC32_MODE)
 			swsusp_header->crc32 = handle->crc32;
+		if (handle->crypto) {
+			swsusp_header->flags |= SF_CRYPTO_MODE;
+			hibernation_crypto_save((void *)swsusp_header->salt);
+		}
 		error = hib_submit_io(REQ_OP_WRITE, REQ_SYNC,
 				      swsusp_resume_block, swsusp_header, NULL);
 	} else {
@@ -536,10 +542,12 @@ static int save_image(struct swap_map_handle *handle,
 	unsigned int m;
 	int ret;
 	int nr_pages;
+	int crypto_page_idx;
 	int err2;
 	struct hib_bio_batch hb;
 	ktime_t start;
 	ktime_t stop;
+	void *tmp = NULL, *crypt_buf = NULL;
 
 	hib_init_batch(&hb);
 
@@ -549,12 +557,36 @@ static int save_image(struct swap_map_handle *handle,
 	if (!m)
 		m = 1;
 	nr_pages = 0;
+	crypto_page_idx = 0;
+	/* Allocate temporary buffer for crypto. */
+	if (handle->crypto) {
+		crypt_buf = (void *)get_zeroed_page(GFP_KERNEL);
+		if (!crypt_buf)
+			return -ENOMEM;
+	}
+
 	start = ktime_get();
 	while (1) {
 		ret = snapshot_read_next(snapshot);
 		if (ret <= 0)
 			break;
-		ret = swap_write_page(handle, data_of(*snapshot), &hb);
+		tmp = data_of(*snapshot);
+		if (handle->crypto) {
+			/* Encryption before submit_io.*/
+			ret = hibernation_crypto_data(data_of(*snapshot),
+				PAGE_SIZE,
+				crypt_buf,
+				PAGE_SIZE,
+				get_crypto_cmd(true,
+				 (crypto_page_idx ==
+				  (nr_to_write - 1))),
+				crypto_page_idx);
+			if (ret)
+				goto out;
+			crypto_page_idx++;
+			tmp = crypt_buf;
+		}
+		ret = swap_write_page(handle, tmp, &hb);
 		if (ret)
 			break;
 		if (!(nr_pages % m))
@@ -569,6 +601,9 @@ static int save_image(struct swap_map_handle *handle,
 	if (!ret)
 		pr_info("Image saving done\n");
 	swsusp_show_speed(start, stop, nr_to_write, "Wrote");
+ out:
+	if (crypt_buf)
+		free_page((unsigned long)crypt_buf);
 	return ret;
 }
 
@@ -672,6 +707,7 @@ static int save_image_lzo(struct swap_map_handle *handle,
 	unsigned int m;
 	int ret = 0;
 	int nr_pages;
+	int crypto_page_idx;
 	int err2;
 	struct hib_bio_batch hb;
 	ktime_t start;
@@ -767,6 +803,7 @@ static int save_image_lzo(struct swap_map_handle *handle,
 	if (!m)
 		m = 1;
 	nr_pages = 0;
+	crypto_page_idx = 0;
 	start = ktime_get();
 	for (;;) {
 		for (thr = 0; thr < nr_threads; thr++) {
@@ -835,7 +872,28 @@ static int save_image_lzo(struct swap_map_handle *handle,
 			for (off = 0;
 			     off < LZO_HEADER + data[thr].cmp_len;
 			     off += PAGE_SIZE) {
-				memcpy(page, data[thr].cmp + off, PAGE_SIZE);
+				if (handle->crypto) {
+					/*
+					 * Encrypt the compressed data
+					 * before we write them to the
+					 * block device.
+					 */
+					ret = hibernation_crypto_data(
+							data[thr].cmp + off,
+							PAGE_SIZE,
+							page,
+							PAGE_SIZE,
+							get_crypto_cmd(true,
+							 (crypto_page_idx ==
+							 (nr_to_write - 1))),
+							crypto_page_idx);
+					if (ret)
+						goto out_finish;
+					crypto_page_idx++;
+				} else {
+					memcpy(page, data[thr].cmp + off,
+						PAGE_SIZE);
+				}
 
 				ret = swap_write_page(handle, page, &hb);
 				if (ret)
@@ -909,6 +967,7 @@ int swsusp_write(unsigned int flags)
 	int error;
 
 	pages = snapshot_get_image_size();
+	memset(&handle, 0, sizeof(struct swap_map_handle));
 	error = get_swap_writer(&handle);
 	if (error) {
 		pr_err("Cannot get swap writer\n");
@@ -922,6 +981,9 @@ int swsusp_write(unsigned int flags)
 		}
 	}
 	memset(&snapshot, 0, sizeof(struct snapshot_handle));
+	if (!hibernation_crypto_init(true))
+		/* The image needs to be encrypted or signature. */
+		handle.crypto = true;
 	error = snapshot_read_next(&snapshot);
 	if (error < PAGE_SIZE) {
 		if (error >= 0)
@@ -1060,6 +1122,8 @@ static int load_image(struct swap_map_handle *handle,
 	struct hib_bio_batch hb;
 	int err2;
 	unsigned nr_pages;
+	unsigned int crypto_page_idx;
+	void *crypt_buf = NULL;
 
 	hib_init_batch(&hb);
 
@@ -1069,18 +1133,46 @@ static int load_image(struct swap_map_handle *handle,
 	if (!m)
 		m = 1;
 	nr_pages = 0;
+	crypto_page_idx = 0;
+	/* Allocate temporary buffer for crypto. */
+	if (handle->crypto) {
+		crypt_buf = (void *)get_zeroed_page(GFP_KERNEL);
+		if (!crypt_buf)
+			return -ENOMEM;
+	}
 	start = ktime_get();
 	for ( ; ; ) {
 		ret = snapshot_write_next(snapshot);
 		if (ret <= 0)
 			break;
-		ret = swap_read_page(handle, data_of(*snapshot), &hb);
+		if (handle->crypto)
+			ret = swap_read_page(handle, crypt_buf, &hb);
+		else
+			ret = swap_read_page(handle, data_of(*snapshot), &hb);
 		if (ret)
 			break;
-		if (snapshot->sync_read)
+		/* If encryption is enabled, disable async io. */
+		if (handle->crypto || snapshot->sync_read)
 			ret = hib_wait_io(&hb);
 		if (ret)
 			break;
+		if (handle->crypto) {
+			/*
+			 * Need a decryption for the
+			 * data read from the block
+			 * device.
+			 */
+			ret = hibernation_crypto_data(crypt_buf, PAGE_SIZE,
+					  data_of(*snapshot),
+					  PAGE_SIZE,
+					  get_crypto_cmd(false,
+					   (crypto_page_idx ==
+					   (nr_to_read - 1))),
+					  crypto_page_idx);
+			if (ret)
+				break;
+			crypto_page_idx++;
+		}
 		if (!(nr_pages % m))
 			pr_info("Image loading progress: %3d%%\n",
 				nr_pages / m * 10);
@@ -1097,6 +1189,8 @@ static int load_image(struct swap_map_handle *handle,
 			ret = -ENODATA;
 	}
 	swsusp_show_speed(start, stop, nr_to_read, "Read");
+	if (crypt_buf)
+		free_page((unsigned long)crypt_buf);
 	return ret;
 }
 
@@ -1165,6 +1259,7 @@ static int load_image_lzo(struct swap_map_handle *handle,
 	ktime_t start;
 	ktime_t stop;
 	unsigned nr_pages;
+	unsigned int crypto_page_idx;
 	size_t off;
 	unsigned i, thr, run_threads, nr_threads;
 	unsigned ring = 0, pg = 0, ring_size = 0,
@@ -1173,6 +1268,7 @@ static int load_image_lzo(struct swap_map_handle *handle,
 	unsigned char **page = NULL;
 	struct dec_data *data = NULL;
 	struct crc_data *crc = NULL;
+	void *first_page = NULL;
 
 	hib_init_batch(&hb);
 
@@ -1278,6 +1374,18 @@ static int load_image_lzo(struct swap_map_handle *handle,
 	}
 	want = ring_size = i;
 
+	/*
+	 * The first page of data[thr] contains the length of
+	 * compressed data, this page should not mess up the
+	 * read buffer, so we allocate a separate page for it.
+	 */
+	if (handle->crypto) {
+		first_page = (void *)get_zeroed_page(GFP_KERNEL);
+		if (!first_page) {
+			ret = -ENOMEM;
+			goto out_clean;
+		}
+	}
 	pr_info("Using %u thread(s) for decompression\n", nr_threads);
 	pr_info("Loading and decompressing image data (%u pages)...\n",
 		nr_to_read);
@@ -1285,6 +1393,7 @@ static int load_image_lzo(struct swap_map_handle *handle,
 	if (!m)
 		m = 1;
 	nr_pages = 0;
+	crypto_page_idx = 0;
 	start = ktime_get();
 
 	ret = snapshot_write_next(snapshot);
@@ -1336,7 +1445,26 @@ static int load_image_lzo(struct swap_map_handle *handle,
 		}
 
 		for (thr = 0; have && thr < nr_threads; thr++) {
-			data[thr].cmp_len = *(size_t *)page[pg];
+			if (handle->crypto) {
+				/*
+				 * Need to decrypt the first page
+				 * of each data[thr], which contains
+				 * the compressed data length.
+				 */
+				ret = hibernation_crypto_data(page[pg],
+						  PAGE_SIZE,
+						  first_page,
+						  PAGE_SIZE,
+						  get_crypto_cmd(false,
+						   (crypto_page_idx ==
+						   (nr_to_read - 1))),
+						  crypto_page_idx);
+				if (ret)
+					goto out_finish;
+				data[thr].cmp_len = *(size_t *)first_page;
+			} else {
+				data[thr].cmp_len = *(size_t *)page[pg];
+			}
 			if (unlikely(!data[thr].cmp_len ||
 			             data[thr].cmp_len >
 			             lzo1x_worst_compress(LZO_UNC_SIZE))) {
@@ -1358,8 +1486,29 @@ static int load_image_lzo(struct swap_map_handle *handle,
 			for (off = 0;
 			     off < LZO_HEADER + data[thr].cmp_len;
 			     off += PAGE_SIZE) {
-				memcpy(data[thr].cmp + off,
-				       page[pg], PAGE_SIZE);
+				if (handle->crypto) {
+					/*
+					 * Decrypt the compressed data
+					 * and leverage the decompression
+					 * threads to get it done.
+					 */
+					ret = hibernation_crypto_data(
+							page[pg],
+							PAGE_SIZE,
+							data[thr].cmp + off,
+							PAGE_SIZE,
+							get_crypto_cmd(false,
+							 (crypto_page_idx ==
+							 (nr_to_read - 1))),
+							crypto_page_idx);
+					if (ret)
+						goto out_finish;
+					crypto_page_idx++;
+				} else {
+					memcpy(data[thr].cmp + off,
+						page[pg], PAGE_SIZE);
+
+				}
 				have--;
 				want++;
 				if (++pg >= ring_size)
@@ -1452,6 +1601,8 @@ static int load_image_lzo(struct swap_map_handle *handle,
 out_clean:
 	for (i = 0; i < ring_size; i++)
 		free_page((unsigned long)page[i]);
+	if (first_page)
+		free_page((unsigned long)first_page);
 	if (crc) {
 		if (crc->thr)
 			kthread_stop(crc->thr);
@@ -1482,6 +1633,7 @@ int swsusp_read(unsigned int *flags_p)
 	struct swsusp_info *header;
 
 	memset(&snapshot, 0, sizeof(struct snapshot_handle));
+	memset(&handle, 0, sizeof(struct swap_map_handle));
 	error = snapshot_write_next(&snapshot);
 	if (error < PAGE_SIZE)
 		return error < 0 ? error : -EFAULT;
@@ -1489,6 +1641,16 @@ int swsusp_read(unsigned int *flags_p)
 	error = get_swap_reader(&handle, flags_p);
 	if (error)
 		goto end;
+	if (*flags_p & SF_CRYPTO_MODE) {
+		error = hibernation_crypto_init(false);
+		if (!error) {
+			/* The image has been encrypted. */
+			handle.crypto = true;
+		} else {
+			pr_err("Failed to init cipher during resume.\n");
+			goto end;
+		}
+	}
 	if (!error)
 		error = swap_read_page(&handle, header, NULL);
 	if (!error) {
@@ -1526,6 +1688,10 @@ int swsusp_check(void)
 
 		if (!memcmp(HIBERNATE_SIG, swsusp_header->sig, 10)) {
 			memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10);
+			/* Read salt passed from previous kernel. */
+			if (swsusp_header->flags & SF_CRYPTO_MODE)
+				hibernation_crypto_restore(
+						(void *)&swsusp_header->salt);
 			/* Reset swap signature now */
 			error = hib_submit_io(REQ_OP_WRITE, REQ_SYNC,
 						swsusp_resume_block,
Signature · 1 line
2.7.4