Skip to contentSkip to conversation

dm verity: fallback to platform keyring also if key in trusted keyring is rejected

PATCH In review [email protected] 6 participants 19 messages Sep 22, 2024 – Sep 27, 2024

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

PATCH 1/1 dm verity: fallback to platform keyring also if key in trusted keyring is rejected

From: Luca Boccassi <[email protected]>

If enabled, we fallback to the platform keyring if the trusted keyring doesn't have the key used to sign the roothash. But if pkcs7_verify() rejects the key for other reasons, such as usage restrictions, we do not fallback. Do so.

Follow-up for 6fce1f40e95182ebbfe1ee3096b8fc0b37903269

---
 drivers/md/dm-verity-verify-sig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-verity-verify-sig.c +1 -1
index d351d7d39c60..a9e2c6c0a33c 100644
@@ -127,7 +127,7 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,
 #endif
 				VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL);
 #ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING
-	if (ret == -ENOKEY)
+	if (ret == -ENOKEY || ret == -EKEYREJECTED)
 		ret = verify_pkcs7_signature(root_hash, root_hash_len, sig_data,
 					sig_len,
 					VERIFY_USE_PLATFORM_KEYRING,
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 10 lines · On Sun, 22 Sep 2024, [email protected] wrote:

From: Luca Boccassi <[email protected]>

If enabled, we fallback to the platform keyring if the trusted keyring doesn't have the key used to sign the roothash. But if pkcs7_verify() rejects the key for other reasons, such as usage restrictions, we do not fallback. Do so.

Follow-up for 6fce1f40e95182ebbfe1ee3096b8fc0b37903269

Hi

I'm not an expert in keyrings.

I added keyring maintainers to the CC. Please review this patch and Ack/Nack it.

Mikulas

Quoted 20 lines
---
 drivers/md/dm-verity-verify-sig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-verity-verify-sig.c +1 -1
index d351d7d39c60..a9e2c6c0a33c 100644
@@ -127,7 +127,7 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,
 #endif
 				VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL);
 #ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING
-	if (ret == -ENOKEY)
+	if (ret == -ENOKEY || ret == -EKEYREJECTED)
 		ret = verify_pkcs7_signature(root_hash, root_hash_len, sig_data,
 					sig_len,
 					VERIFY_USE_PLATFORM_KEYRING,
Signature · 1 line
2.39.5
maintainer
#2 lore raw
Quoted 28 lines · Mikulas Patocka
Quoted 10 lines · On Sun, 22 Sep 2024, [email protected] wrote:

From: Luca Boccassi <[email protected]>

If enabled, we fallback to the platform keyring if the trusted keyring doesn't have the key used to sign the roothash. But if pkcs7_verify() rejects the key for other reasons, such as usage restrictions, we do not fallback. Do so.

Follow-up for 6fce1f40e95182ebbfe1ee3096b8fc0b37903269

Hi

I'm not an expert in keyrings.

I added keyring maintainers to the CC. Please review this patch and Ack/Nack it.

Mikulas

Quoted 4 lines
---
 drivers/md/dm-verity-verify-sig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 16 lines
drivers/md/dm-verity-verify-sig.c +1 -1
index d351d7d39c60..a9e2c6c0a33c 100644
@@ -127,7 +127,7 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,
 #endif
 				VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL);
 #ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING
-	if (ret == -ENOKEY)
+	if (ret == -ENOKEY || ret == -EKEYREJECTED)
 		ret = verify_pkcs7_signature(root_hash, root_hash_len, sig_data,
 					sig_len,
 					VERIFY_USE_PLATFORM_KEYRING,
Signature · 1 line
2.39.5

I know nothing about dm-verity. What does it even do?

BR, Jarkko

maintainer
#3 lore raw
Quoted 48 lines · Jarkko Sakkinen
Quoted 28 lines · Mikulas Patocka
Quoted 10 lines · On Sun, 22 Sep 2024, [email protected] wrote:

From: Luca Boccassi <[email protected]>

If enabled, we fallback to the platform keyring if the trusted keyring doesn't have the key used to sign the roothash. But if pkcs7_verify() rejects the key for other reasons, such as usage restrictions, we do not fallback. Do so.

Follow-up for 6fce1f40e95182ebbfe1ee3096b8fc0b37903269

Hi

I'm not an expert in keyrings.

I added keyring maintainers to the CC. Please review this patch and Ack/Nack it.

Mikulas

Quoted 4 lines
---
 drivers/md/dm-verity-verify-sig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 16 lines
drivers/md/dm-verity-verify-sig.c +1 -1
index d351d7d39c60..a9e2c6c0a33c 100644
@@ -127,7 +127,7 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,
 #endif
 				VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL);
 #ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING
-	if (ret == -ENOKEY)
+	if (ret == -ENOKEY || ret == -EKEYREJECTED)
 		ret = verify_pkcs7_signature(root_hash, root_hash_len, sig_data,
 					sig_len,
 					VERIFY_USE_PLATFORM_KEYRING,
Signature · 1 line
2.39.5

I know nothing about dm-verity. What does it even do?

Quoted 1 line

BR, Jarkko

dm-verity provides a read-only device with integrity checking. dm-verity stores hash for every block on the block device and checks the hash when reading the block. If the hash doesn't match, it can do one of these actions (depending on configuration):
- return I/O error
- try to correct the data using forward error correction
- log the mismatch and do nothing
- restart the machine
- call panic()

dm-verity is mostly used for the immutable system partition on Android phones. For more info, see Documentation/admin-guide/device-mapper/verity.rst

The above patch changes the way that the signature of the root hash is verified. I have no clue whether the patch can or can't subvert system security, that's why I'd like to have some more reviews of the patch before accepting it.

Mikulas

maintainer
#4 lore raw
Quoted 64 lines · Mikulas Patocka
Quoted 48 lines · Jarkko Sakkinen
Quoted 28 lines · Mikulas Patocka
Quoted 10 lines · On Sun, 22 Sep 2024, [email protected] wrote:

From: Luca Boccassi <[email protected]>

If enabled, we fallback to the platform keyring if the trusted keyring doesn't have the key used to sign the roothash. But if pkcs7_verify() rejects the key for other reasons, such as usage restrictions, we do not fallback. Do so.

Follow-up for 6fce1f40e95182ebbfe1ee3096b8fc0b37903269

Hi

I'm not an expert in keyrings.

I added keyring maintainers to the CC. Please review this patch and Ack/Nack it.

Mikulas

Quoted 4 lines
---
 drivers/md/dm-verity-verify-sig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 16 lines
drivers/md/dm-verity-verify-sig.c +1 -1
index d351d7d39c60..a9e2c6c0a33c 100644
@@ -127,7 +127,7 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,
 #endif
 				VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL);
 #ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING
-	if (ret == -ENOKEY)
+	if (ret == -ENOKEY || ret == -EKEYREJECTED)
 		ret = verify_pkcs7_signature(root_hash, root_hash_len, sig_data,
 					sig_len,
 					VERIFY_USE_PLATFORM_KEYRING,
Signature · 1 line
2.39.5

I know nothing about dm-verity. What does it even do?

Quoted 1 line

BR, Jarkko

dm-verity provides a read-only device with integrity checking. dm-verity stores hash for every block on the block device and checks the hash when reading the block. If the hash doesn't match, it can do one of these actions (depending on configuration):
- return I/O error
- try to correct the data using forward error correction
- log the mismatch and do nothing
- restart the machine
- call panic()

Quoted 8 lines

dm-verity is mostly used for the immutable system partition on Android phones. For more info, see Documentation/admin-guide/device-mapper/verity.rst

The above patch changes the way that the signature of the root hash is verified. I have no clue whether the patch can or can't subvert system security, that's why I'd like to have some more reviews of the patch before accepting it.

I guess someone who knows all this already should review it.

Doesn't dm-verity have a maintainer?

BR, Jarkko

#5 lore raw
Quoted 69 lines · Jarkko Sakkinen
Quoted 68 lines · Mikulas Patocka
Quoted 48 lines · Jarkko Sakkinen
Quoted 28 lines · Mikulas Patocka
Quoted 10 lines · On Sun, 22 Sep 2024, [email protected] wrote:

From: Luca Boccassi <[email protected]>

If enabled, we fallback to the platform keyring if the trusted keyring doesn't have the key used to sign the roothash. But if pkcs7_verify() rejects the key for other reasons, such as usage restrictions, we do not fallback. Do so.

Follow-up for 6fce1f40e95182ebbfe1ee3096b8fc0b37903269

Hi

I'm not an expert in keyrings.

I added keyring maintainers to the CC. Please review this patch and Ack/Nack it.

Mikulas

Quoted 4 lines
---
 drivers/md/dm-verity-verify-sig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 16 lines
drivers/md/dm-verity-verify-sig.c +1 -1
index d351d7d39c60..a9e2c6c0a33c 100644
@@ -127,7 +127,7 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,
 #endif
 				VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL);
 #ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING
-	if (ret == -ENOKEY)
+	if (ret == -ENOKEY || ret == -EKEYREJECTED)
 		ret = verify_pkcs7_signature(root_hash, root_hash_len, sig_data,
 					sig_len,
 					VERIFY_USE_PLATFORM_KEYRING,
Signature · 1 line
2.39.5

I know nothing about dm-verity. What does it even do?

Quoted 1 line

BR, Jarkko

dm-verity provides a read-only device with integrity checking. dm-verity stores hash for every block on the block device and checks the hash when reading the block. If the hash doesn't match, it can do one of these actions (depending on configuration):
- return I/O error
- try to correct the data using forward error correction
- log the mismatch and do nothing
- restart the machine
- call panic()

dm-verity is mostly used for the immutable system partition on Android phones. For more info, see Documentation/admin-guide/device-mapper/verity.rst

Quoted 9 lines
Quoted 4 lines

The above patch changes the way that the signature of the root hash is verified. I have no clue whether the patch can or can't subvert system security, that's why I'd like to have some more reviews of the patch before accepting it.

I guess someone who knows all this already should review it.

Doesn't dm-verity have a maintainer?

This patch only affects dm-verity's in-kernel signature verification support, which has only been present since Linux v5.4 and is not used by Android or Chrome OS. The whole feature seems weird to me, and it is prone to be misused; signatures are best verified by trusted userspace code instead (e.g. initramfs). But apparently there are people who use the dm-verity in-kernel signatures. I think systemd has some support for it, as does the recently-upstreamed IPE LSM. I don't know what else. The exact semantics of the "trusted" and "platform" keyrings are not entirely clear to me, but given that dm-verity already trusts keys from both keyrings this patch seems reasonable. The people who actually use this feature are in the best position to make that call, though.

- Eric

maintainer
#6 lore raw
Quoted 80 lines · Eric Biggers
Quoted 69 lines · Jarkko Sakkinen
Quoted 68 lines · Mikulas Patocka
Quoted 48 lines · Jarkko Sakkinen
Quoted 28 lines · Mikulas Patocka
Quoted 10 lines · On Sun, 22 Sep 2024, [email protected] wrote:

From: Luca Boccassi <[email protected]>

If enabled, we fallback to the platform keyring if the trusted keyring doesn't have the key used to sign the roothash. But if pkcs7_verify() rejects the key for other reasons, such as usage restrictions, we do not fallback. Do so.

Follow-up for 6fce1f40e95182ebbfe1ee3096b8fc0b37903269

Hi

I'm not an expert in keyrings.

I added keyring maintainers to the CC. Please review this patch and Ack/Nack it.

Mikulas

Quoted 4 lines
---
 drivers/md/dm-verity-verify-sig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 16 lines
drivers/md/dm-verity-verify-sig.c +1 -1
index d351d7d39c60..a9e2c6c0a33c 100644
@@ -127,7 +127,7 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,
 #endif
 				VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL);
 #ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING
-	if (ret == -ENOKEY)
+	if (ret == -ENOKEY || ret == -EKEYREJECTED)
 		ret = verify_pkcs7_signature(root_hash, root_hash_len, sig_data,
 					sig_len,
 					VERIFY_USE_PLATFORM_KEYRING,
Signature · 1 line
2.39.5

I know nothing about dm-verity. What does it even do?

Quoted 1 line

BR, Jarkko

dm-verity provides a read-only device with integrity checking. dm-verity stores hash for every block on the block device and checks the hash when reading the block. If the hash doesn't match, it can do one of these actions (depending on configuration):
- return I/O error
- try to correct the data using forward error correction
- log the mismatch and do nothing
- restart the machine
- call panic()

dm-verity is mostly used for the immutable system partition on Android phones. For more info, see Documentation/admin-guide/device-mapper/verity.rst

Quoted 9 lines
Quoted 4 lines

The above patch changes the way that the signature of the root hash is verified. I have no clue whether the patch can or can't subvert system security, that's why I'd like to have some more reviews of the patch before accepting it.

I guess someone who knows all this already should review it.

Doesn't dm-verity have a maintainer?

Quoted 10 lines

This patch only affects dm-verity's in-kernel signature verification support, which has only been present since Linux v5.4 and is not used by Android or Chrome OS. The whole feature seems weird to me, and it is prone to be misused; signatures are best verified by trusted userspace code instead (e.g. initramfs). But apparently there are people who use the dm-verity in-kernel signatures. I think systemd has some support for it, as does the recently-upstreamed IPE LSM. I don't know what else. The exact semantics of the "trusted" and "platform" keyrings are not entirely clear to me, but given that dm-verity already trusts keys from both keyrings this patch seems reasonable. The people who actually use this feature are in the best position to make that call, though.

https://lwn.net/Articles/459420/

Isn't Netflix using FreeBSD these days? :-)

Right, and Chromebooks also mentioned in the same article (from 2011).

For me this looks almost like abaddonware...

Quoted 2 lines

- Eric

BR, Jarkko

#7 lore raw
In reply to Eric Biggers
Quoted 70 lines · Eric Biggers
Quoted 69 lines · Jarkko Sakkinen
Quoted 68 lines · Mikulas Patocka
Quoted 48 lines · Jarkko Sakkinen
Quoted 28 lines · Mikulas Patocka
Quoted 10 lines · On Sun, 22 Sep 2024, [email protected] wrote:

From: Luca Boccassi <[email protected]>

If enabled, we fallback to the platform keyring if the trusted keyring doesn't have the key used to sign the roothash. But if pkcs7_verify() rejects the key for other reasons, such as usage restrictions, we do not fallback. Do so.

Follow-up for 6fce1f40e95182ebbfe1ee3096b8fc0b37903269

Hi

I'm not an expert in keyrings.

I added keyring maintainers to the CC. Please review this patch and Ack/Nack it.

Mikulas

Quoted 4 lines
---
  drivers/md/dm-verity-verify-sig.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 16 lines
drivers/md/dm-verity-verify-sig.c +1 -1
index d351d7d39c60..a9e2c6c0a33c 100644
@@ -127,7 +127,7 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,
  #endif
  				VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL);
  #ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING
-	if (ret == -ENOKEY)
+	if (ret == -ENOKEY || ret == -EKEYREJECTED)
  		ret = verify_pkcs7_signature(root_hash, root_hash_len, sig_data,
  					sig_len,
  					VERIFY_USE_PLATFORM_KEYRING,
Signature · 1 line
2.39.5

I know nothing about dm-verity. What does it even do?

Quoted 1 line

BR, Jarkko

dm-verity provides a read-only device with integrity checking. dm-verity stores hash for every block on the block device and checks the hash when reading the block. If the hash doesn't match, it can do one of these actions (depending on configuration):
- return I/O error
- try to correct the data using forward error correction
- log the mismatch and do nothing
- restart the machine
- call panic()

dm-verity is mostly used for the immutable system partition on Android phones. For more info, see Documentation/admin-guide/device-mapper/verity.rst

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

The above patch changes the way that the signature of the root hash is verified. I have no clue whether the patch can or can't subvert system security, that's why I'd like to have some more reviews of the patch before accepting it.

I guess someone who knows all this already should review it.

Doesn't dm-verity have a maintainer?

(This reminds me of a nice comment from Neil about "little walled gardens" between MD & DM. Apparently it applies to other subsystems as well. Sorry, I couldn't resist to mention it :-)

Quoted 10 lines

This patch only affects dm-verity's in-kernel signature verification support, which has only been present since Linux v5.4 and is not used by Android or Chrome OS. The whole feature seems weird to me, and it is prone to be misused; signatures are best verified by trusted userspace code instead (e.g. initramfs). But apparently there are people who use the dm-verity in-kernel signatures. I think systemd has some support for it, as does the recently-upstreamed IPE LSM. I don't know what else. The exact semantics of the "trusted" and "platform" keyrings are not entirely clear to me, but given that dm-verity already trusts keys from both keyrings this patch seems reasonable. The people who actually use this feature are in the best position to make that call, though.

When we added support for this to veritysetup (--root-hash-signature), I think it was a requirement from Microsoft.

Anyway, if you have a trusted key compiled-in the kernel in one keyring, I do not think it would cause problems if stored in another.

But it scares me that we cannot easily test userspace for this in CI, as it requires compiling own kernel with our own keys.

Do people use veritysetup (libcryptsetup) here, or does it run with its separate userspace tooling?

Milan

maintainer
#8 lore raw
Quoted 5 lines · Milan Broz
Quoted 1 line
Quoted 1 line

Doesn't dm-verity have a maintainer?

(This reminds me of a nice comment from Neil about "little walled gardens" between MD & DM. Apparently it applies to other subsystems as well. Sorry, I couldn't resist to mention it :-)

Np, it's just that last and only time I've ever read anything about dm-verity was 2011 article :-)

I will rephrase question: does dm-verity have a user? ;-)

BR, Jarkko

#9 lore raw
Quoted 11 lines · Jarkko Sakkinen
Quoted 5 lines · Milan Broz
Quoted 1 line
Quoted 1 line

Doesn't dm-verity have a maintainer?

(This reminds me of a nice comment from Neil about "little walled gardens" between MD & DM. Apparently it applies to other subsystems as well. Sorry, I couldn't resist to mention it :-)

Np, it's just that last and only time I've ever read anything about dm-verity was 2011 article :-)

I will rephrase question: does dm-verity have a user? ;-)

It gets used for integrity guarantees in certain containers, where the layers of tarballs are replaced by layers of squashfs, with the dmverity root hash for each layer listed in the signed manifest, e.g.

github.com/project-stacker/stacker
github.com/project-machine/atomfs

This is used of course to verify container integrity, and also gets used by some projects and products to create an RFS from such images during initrd

github.com/project-machine/mos

-serge

maintainer Acked-by
#10 lore raw
Quoted 17 lines · Serge E. Hallyn
Quoted 11 lines · Jarkko Sakkinen
Quoted 5 lines · Milan Broz
Quoted 1 line
Quoted 1 line

Doesn't dm-verity have a maintainer?

(This reminds me of a nice comment from Neil about "little walled gardens" between MD & DM. Apparently it applies to other subsystems as well. Sorry, I couldn't resist to mention it :-)

Np, it's just that last and only time I've ever read anything about dm-verity was 2011 article :-)

I will rephrase question: does dm-verity have a user? ;-)

It gets used for integrity guarantees in certain containers, where the layers of tarballs are replaced by layers of squashfs, with the dmverity root hash for each layer listed in the signed manifest, e.g.

Quoted 7 lines

github.com/project-stacker/stacker
github.com/project-machine/atomfs

This is used of course to verify container integrity, and also gets used by some projects and products to create an RFS from such images during initrd

github.com/project-machine/mos

OK got it!

I did some studying and query and to put short it is a merkle tree for rootfs for devices like phones and tablets for instance. I.e. when you modify only on "system update".

So... let's check the mainatainers list:

❯ scripts/get_maintainer.pl drivers/md/dm-verity-verify-sig.c Alasdair Kergon <[email protected]> (maintainer:DEVICE-MAPPER (LVM)) Mike Snitzer <[email protected]> (maintainer:DEVICE-MAPPER (LVM)) Mikulas Patocka <[email protected]> (maintainer:DEVICE-MAPPER (LVM)) [email protected] (open list:DEVICE-MAPPER (LVM)) [email protected] (open list)

Mikulas, I guess you take care of this if I just ack the return value?

If that holds, and given that I actually know what verify_pkcs7_signature() does, I think the code patch makes sense to me, and thus:

I.e. I think it uses API correctly.

Quoted 2 lines

-serge

BR, Jarkko

#11 lore raw
In reply to Jarkko Sakkinen
Quoted 7 lines · Jarkko Sakkinen
Quoted 5 lines · Milan Broz
Quoted 1 line
Quoted 1 line

Doesn't dm-verity have a maintainer?

(This reminds me of a nice comment from Neil about "little walled gardens" between MD & DM. Apparently it applies to other subsystems as well. Sorry, I couldn't resist to mention it :-)

Quoted 6 lines

Np, it's just that last and only time I've ever read anything about dm-verity was 2011 article :-)

I will rephrase question: does dm-verity have a user? ;-)

BR, Jarkko

Sorry if I was unclear. dm-verity is widely used, including by all Android and Chrome OS devices. But this patch is about dm-verity's in-kernel signature verification which is an optional sub-feature that is not widely used. That sub-feature is apparently difficult to test and not clearly specified, which is why people seem to be struggling a bit with this patch.

- Eric

maintainer
#12 lore raw
Quoted 13 lines · Eric Biggers
Quoted 12 lines · Jarkko Sakkinen
Quoted 5 lines · Milan Broz
Quoted 1 line
Quoted 1 line

Doesn't dm-verity have a maintainer?

(This reminds me of a nice comment from Neil about "little walled gardens" between MD & DM. Apparently it applies to other subsystems as well. Sorry, I couldn't resist to mention it :-)

Np, it's just that last and only time I've ever read anything about dm-verity was 2011 article :-)

I will rephrase question: does dm-verity have a user? ;-)

Quoted 7 lines
Quoted 1 line

BR, Jarkko

Sorry if I was unclear. dm-verity is widely used, including by all Android and Chrome OS devices. But this patch is about dm-verity's in-kernel signature verification which is an optional sub-feature that is not widely used. That sub-feature is apparently difficult to test and not clearly specified, which is why people seem to be struggling a bit with this patch.

NP, I learned a new thing ;-)

Before Linux I worked with Symbian (ugh) so this whole scheme for doing FW updates is familiar to me from the dark ages...

And I acked the change too!

Quoted 1 line

- Eric

BR, Jarkko

#13 lore raw
In reply to Milan Broz
Quoted 98 lines · Milan Broz
Quoted 70 lines · Eric Biggers
Quoted 69 lines · Jarkko Sakkinen
Quoted 68 lines · Mikulas Patocka
Quoted 48 lines · Jarkko Sakkinen
Quoted 28 lines · Mikulas Patocka
Quoted 10 lines · On Sun, 22 Sep 2024, [email protected] wrote:

From: Luca Boccassi <[email protected]>

If enabled, we fallback to the platform keyring if the trusted keyring doesn't have the key used to sign the roothash. But if pkcs7_verify() rejects the key for other reasons, such as usage restrictions, we do not fallback. Do so.

Follow-up for 6fce1f40e95182ebbfe1ee3096b8fc0b37903269

Hi

I'm not an expert in keyrings.

I added keyring maintainers to the CC. Please review this patch and Ack/Nack it.

Mikulas

Quoted 4 lines
---
  drivers/md/dm-verity-verify-sig.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 14 lines
drivers/md/dm-verity-verify-sig.c +1 -2
index d351d7d39c60..a9e2c6c0a33c 100644
@@ -127,7 +127,7 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,
  #endif
                                 VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL);
  #ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING
-        if (ret == -ENOKEY)
+        if (ret == -ENOKEY || ret == -EKEYREJECTED)
                 ret = verify_pkcs7_signature(root_hash, root_hash_len, sig_data,
                                         sig_len,
                                         VERIFY_USE_PLATFORM_KEYRING,
--
Quoted 2 lines

2.39.5

I know nothing about dm-verity. What does it even do?

Quoted 1 line

BR, Jarkko

dm-verity provides a read-only device with integrity checking. dm-verity stores hash for every block on the block device and checks the hash when reading the block. If the hash doesn't match, it can do one of these actions (depending on configuration):
- return I/O error
- try to correct the data using forward error correction
- log the mismatch and do nothing
- restart the machine
- call panic()

dm-verity is mostly used for the immutable system partition on Android phones. For more info, see Documentation/admin-guide/device-mapper/verity.rst

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

The above patch changes the way that the signature of the root hash is verified. I have no clue whether the patch can or can't subvert system security, that's why I'd like to have some more reviews of the patch before accepting it.

I guess someone who knows all this already should review it.

Doesn't dm-verity have a maintainer?

(This reminds me of a nice comment from Neil about "little walled gardens" between MD & DM. Apparently it applies to other subsystems as well. Sorry, I couldn't resist to mention it :-)

Quoted 10 lines

This patch only affects dm-verity's in-kernel signature verification support, which has only been present since Linux v5.4 and is not used by Android or Chrome OS. The whole feature seems weird to me, and it is prone to be misused; signatures are best verified by trusted userspace code instead (e.g. initramfs). But apparently there are people who use the dm-verity in-kernel signatures. I think systemd has some support for it, as does the recently-upstreamed IPE LSM. I don't know what else. The exact semantics of the "trusted" and "platform" keyrings are not entirely clear to me, but given that dm-verity already trusts keys from both keyrings this patch seems reasonable. The people who actually use this feature are in the best position to make that call, though.

When we added support for this to veritysetup (--root-hash-signature), I think it was a requirement from Microsoft.

Quoted 7 lines

Anyway, if you have a trusted key compiled-in the kernel in one keyring, I do not think it would cause problems if stored in another.

But it scares me that we cannot easily test userspace for this in CI, as it requires compiling own kernel with our own keys.

Do people use veritysetup (libcryptsetup) here, or does it run with its separate userspace tooling?

This is used with libcryptsetup commonly, and often with veritysetup. It is fairly easy to test in a VM or on baremetal, it is not required to build your own kernel - that's the reason for supporting secondary+platform keyrings (the first one allows you to enroll keys in MOK, the second one for UEFI DB).
We would even have a CI testing this for every PR and merge in systemd on Github, _except_ there is currently an issue (unrelated to dmverity) that happens when nesting KVM with UEFI secure boot enabled on top of HyperV, which means it cannot be used reliably on Github Actions. Once that is solved, this will be again part of the systemd CI integration tests. But it is used regularly by developers on their machines.

It might not be commonly used by kernel developers, I do not know as I am not a kernel developer, but it is becoming more and more common in userspace and among image builders. For example the mkosi image builder, using systemd-repart, can very easily build distro images using signed dm verity. I am at All Systems Go and just today there were multiple talks by multiple people using dmverity images for their distros/platforms/products, especially with systemd-sysext, which is all about signed dm-verity.

In 6.12 we will also have IPE which allows to enable trusted code integrity checks that cannot be trivially bypassed by other userspace processes running with root or caps. This has been, still is and will be for the foreseeable future, in use in the Azure infrastructure.

Hope this provides some clarity, let me know if you need more info.

#14 lore raw
Quoted 15 lines · Luca Boccassi
Quoted 2 lines

Do people use veritysetup (libcryptsetup) here, or does it run with its separate userspace tooling?

This is used with libcryptsetup commonly, and often with veritysetup. It is fairly easy to test in a VM or on baremetal, it is not required to build your own kernel - that's the reason for supporting secondary+platform keyrings (the first one allows you to enroll keys in MOK, the second one for UEFI DB).
We would even have a CI testing this for every PR and merge in systemd on Github, _except_ there is currently an issue (unrelated to dmverity) that happens when nesting KVM with UEFI secure boot enabled on top of HyperV, which means it cannot be used reliably on Github Actions. Once that is solved, this will be again part of the systemd CI integration tests. But it is used regularly by developers on their machines.

Hi Luca,

good to know that libcryptswtup userspace is then used here, thanks for the info!

I have some more questions, but that is not related to this thread, I will ask in another mail later.

Thanks,
Milan

Quoted 16 lines

It might not be commonly used by kernel developers, I do not know as I am not a kernel developer, but it is becoming more and more common in userspace and among image builders. For example the mkosi image builder, using systemd-repart, can very easily build distro images using signed dm verity. I am at All Systems Go and just today there were multiple talks by multiple people using dmverity images for their distros/platforms/products, especially with systemd-sysext, which is all about signed dm-verity.

In 6.12 we will also have IPE which allows to enable trusted code integrity checks that cannot be trivially bypassed by other userspace processes running with root or caps. This has been, still is and will be for the foreseeable future, in use in the Azure infrastructure.

Hope this provides some clarity, let me know if you need more info.

maintainer
#15 lore raw
In reply to [email protected]
Quoted 29 lines · On Sun, 22 Sep 2024, [email protected] wrote:

From: Luca Boccassi <[email protected]>

If enabled, we fallback to the platform keyring if the trusted keyring doesn't have the key used to sign the roothash. But if pkcs7_verify() rejects the key for other reasons, such as usage restrictions, we do not fallback. Do so.

Follow-up for 6fce1f40e95182ebbfe1ee3096b8fc0b37903269

---
 drivers/md/dm-verity-verify-sig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-verity-verify-sig.c +1 -1
index d351d7d39c60..a9e2c6c0a33c 100644
@@ -127,7 +127,7 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,
 #endif
 				VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL);
 #ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING
-	if (ret == -ENOKEY)
+	if (ret == -ENOKEY || ret == -EKEYREJECTED)
 		ret = verify_pkcs7_signature(root_hash, root_hash_len, sig_data,
 					sig_len,
 					VERIFY_USE_PLATFORM_KEYRING,
Signature · 1 line
2.39.5

Hi

Please describe what problem does this patch solve. I.e. why would anyone put a key into the trusted keyring that could sign the roothash and restrict its usage so that it can't be used to sign the roothash?

In the other places of the kernel, only -ENOKEY is tested:
kexec_kernel_verify_pe_sig:
if (ret == -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING)) s390_verify_sig:
if (ret == -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING)) do they need to be converted to -EKEYREJECTED too?

Mikulas

#16 lore raw
Quoted 41 lines · Mikulas Patocka
Quoted 28 lines · On Sun, 22 Sep 2024, [email protected] wrote:

From: Luca Boccassi <[email protected]>

If enabled, we fallback to the platform keyring if the trusted keyring doesn't have the key used to sign the roothash. But if pkcs7_verify() rejects the key for other reasons, such as usage restrictions, we do not fallback. Do so.

Follow-up for 6fce1f40e95182ebbfe1ee3096b8fc0b37903269

---
 drivers/md/dm-verity-verify-sig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-verity-verify-sig.c +1 -2
index d351d7d39c60..a9e2c6c0a33c 100644
@@ -127,7 +127,7 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,
 #endif
                              VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL);
 #ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING
-     if (ret == -ENOKEY)
+     if (ret == -ENOKEY || ret == -EKEYREJECTED)
              ret = verify_pkcs7_signature(root_hash, root_hash_len, sig_data,
                                      sig_len,
                                      VERIFY_USE_PLATFORM_KEYRING,
--
Quoted 1 line

2.39.5

Hi

Please describe what problem does this patch solve. I.e. why would anyone put a key into the trusted keyring that could sign the roothash and restrict its usage so that it can't be used to sign the roothash?

Quoted 6 lines

In the other places of the kernel, only -ENOKEY is tested:
kexec_kernel_verify_pe_sig:
if (ret == -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING)) s390_verify_sig:
if (ret == -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING)) do they need to be converted to -EKEYREJECTED too?

To be perfectly honest, I do not have a use case for the EKEYREJECTED fallback - it was suggested by Serge when I was working on the IPE keyrings usage:

https://lore.kernel.org/all/[email protected]/

I would like to maintain the usage of keyrings in sync between the two components given they are used together, for consistency, so I counter-proposed to send the change to dmverity first. I am following up on that promise with this patch.
If there are reasons not to take this change, or if there are no convincing reasons to take it, I do not have strong opinions either way so I don't mind what the outcome is either way, as I am just following up on that review comment. I'll let Serge explain the reasoning for the request, if he wants to do it.

If this change is accepted, I will send the same for IPE. If not, I won't. I do not directly use other subsystems that use these keyrings, so I will not send changes for those even if this goes in.

maintainer
#17 lore raw
Quoted 45 lines · Luca Boccassi
Quoted 22 lines
Quoted 14 lines
drivers/md/dm-verity-verify-sig.c +1 -2
index d351d7d39c60..a9e2c6c0a33c 100644
@@ -127,7 +127,7 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,
 #endif
                              VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL);
 #ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING
-     if (ret == -ENOKEY)
+     if (ret == -ENOKEY || ret == -EKEYREJECTED)
              ret = verify_pkcs7_signature(root_hash, root_hash_len, sig_data,
                                      sig_len,
                                      VERIFY_USE_PLATFORM_KEYRING,
--
Quoted 1 line

2.39.5

Hi

Please describe what problem does this patch solve. I.e. why would anyone put a key into the trusted keyring that could sign the roothash and restrict its usage so that it can't be used to sign the roothash?

Quoted 6 lines

In the other places of the kernel, only -ENOKEY is tested:
kexec_kernel_verify_pe_sig:
if (ret == -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING)) s390_verify_sig:
if (ret == -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING)) do they need to be converted to -EKEYREJECTED too?

To be perfectly honest, I do not have a use case for the EKEYREJECTED fallback - it was suggested by Serge when I was working on the IPE keyrings usage:

https://lore.kernel.org/all/[email protected]/

I would like to maintain the usage of keyrings in sync between the two components given they are used together, for consistency, so I counter-proposed to send the change to dmverity first. I am following up on that promise with this patch.
If there are reasons not to take this change, or if there are no convincing reasons to take it, I do not have strong opinions either way so I don't mind what the outcome is either way, as I am just following up on that review comment. I'll let Serge explain the reasoning for the request, if he wants to do it.

Quoted 3 lines

If this change is accepted, I will send the same for IPE. If not, I won't. I do not directly use other subsystems that use these keyrings, so I will not send changes for those even if this goes in.

Hi

I accepted this patch, I'll send it to Linus with other device mapper patches.

Mikulas

#18 lore raw
Quoted 54 lines · Mikulas Patocka
Quoted 45 lines · Luca Boccassi
Quoted 22 lines
Quoted 14 lines
drivers/md/dm-verity-verify-sig.c +1 -2
index d351d7d39c60..a9e2c6c0a33c 100644
@@ -127,7 +127,7 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,
 #endif
                              VERIFYING_UNSPECIFIED_SIGNATURE, NULL, NULL);
 #ifdef CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING
-     if (ret == -ENOKEY)
+     if (ret == -ENOKEY || ret == -EKEYREJECTED)
              ret = verify_pkcs7_signature(root_hash, root_hash_len, sig_data,
                                      sig_len,
                                      VERIFY_USE_PLATFORM_KEYRING,
--
Quoted 1 line

2.39.5

Hi

Please describe what problem does this patch solve. I.e. why would anyone put a key into the trusted keyring that could sign the roothash and restrict its usage so that it can't be used to sign the roothash?

Quoted 6 lines

In the other places of the kernel, only -ENOKEY is tested:
kexec_kernel_verify_pe_sig:
if (ret == -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING)) s390_verify_sig:
if (ret == -ENOKEY && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING)) do they need to be converted to -EKEYREJECTED too?

To be perfectly honest, I do not have a use case for the EKEYREJECTED fallback - it was suggested by Serge when I was working on the IPE keyrings usage:

https://lore.kernel.org/all/[email protected]/

I would like to maintain the usage of keyrings in sync between the two components given they are used together, for consistency, so I counter-proposed to send the change to dmverity first. I am following up on that promise with this patch.
If there are reasons not to take this change, or if there are no convincing reasons to take it, I do not have strong opinions either way so I don't mind what the outcome is either way, as I am just following up on that review comment. I'll let Serge explain the reasoning for the request, if he wants to do it.

Quoted 3 lines

If this change is accepted, I will send the same for IPE. If not, I won't. I do not directly use other subsystems that use these keyrings, so I will not send changes for those even if this goes in.

Quoted 6 lines

Hi

I accepted this patch, I'll send it to Linus with other device mapper patches.

Mikulas

Thank you!