Skip to contentSkip to conversation

certs: Prevent spurious errors on repeated blacklisting

PATCH Superseded Thomas Weißschuh 3 participants 9 messages Nov 18, 2022 – Dec 12, 2022

Subsystems (4)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#7 lore raw

PATCH v3 3/3 certs: don't try to update blacklist keys

In reply to Thomas Weißschuh

When the same key is blacklisted repeatedly logging at pr_err() level is excessive as no functionality is impaired.
When these duplicates are provided by buggy firmware there is nothing the enduser can do to fix the situation.
Instead of spamming the bootlog with errors we use a warning that can still be seen by OEMs when testing their firmware.

---
 certs/blacklist.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
certs/blacklist.c +12 -9
index 6e260c4b6a19..675dd7a8f07a 100644
@@ -183,16 +183,19 @@ static int mark_raw_hash_blacklisted(const char *hash)
 {
 	key_ref_t key;
 
-	key = key_create_or_update(make_key_ref(blacklist_keyring, true),
-				   "blacklist",
-				   hash,
-				   NULL,
-				   0,
-				   BLACKLIST_KEY_PERM,
-				   KEY_ALLOC_NOT_IN_QUOTA |
-				   KEY_ALLOC_BUILT_IN);
+	key = key_create(make_key_ref(blacklist_keyring, true),
+			 "blacklist",
+			 hash,
+			 NULL,
+			 0,
+			 BLACKLIST_KEY_PERM,
+			 KEY_ALLOC_NOT_IN_QUOTA |
+			 KEY_ALLOC_BUILT_IN);
 	if (IS_ERR(key)) {
-		pr_err("Problem blacklisting hash %s: %pe\n", hash, key);
+		if (PTR_ERR(key) == -EEXIST)
+			pr_warn("Duplicate blacklisted hash %s\n", hash);
+		else
+			pr_err("Problem blacklisting hash %s: %pe\n", hash, key);
 		return PTR_ERR(key);
 	}
 	return 0;
Signature · 1 line
2.38.1
#5 lore raw

PATCH v3 2/3 KEYS: Add key_create()

In reply to Thomas Weißschuh

This function works like key_create_or_update() but does not allow updating an existing key, instead returning -EEXIST.

This new function will be used by the blacklist keyring to handle EEXIST errors specially by logging a different message with lower severity.

---
 include/linux/key.h |   8 +++
 security/keys/key.c | 149 +++++++++++++++++++++++++++++++++-----------
 2 files changed, 120 insertions(+), 37 deletions(-)
include/linux/key.h +8 -0
index d27477faf00d..8dc7f7c3088b 100644
@@ -386,6 +386,14 @@ extern int wait_for_key_construction(struct key *key, bool intr);
 
 extern int key_validate(const struct key *key);
 
+extern key_ref_t key_create(key_ref_t keyring,
+			    const char *type,
+			    const char *description,
+			    const void *payload,
+			    size_t plen,
+			    key_perm_t perm,
+			    unsigned long flags);
+
 extern key_ref_t key_create_or_update(key_ref_t keyring,
 				      const char *type,
 				      const char *description,
security/keys/key.c +112 -37

172 lines not on this page · raw message

Signature · 1 line
2.38.1
#0 lore raw

v3 cover certs: Prevent spurious errors on repeated blacklisting

When the blacklist keyring was changed to allow updates from the root user it gained an ->update() function that disallows all updates. When the a hash is blacklisted multiple times from the builtin or firmware-provided blacklist this spams prominent logs during boot:

[    0.890814] blacklist: Problem blacklisting hash (-13)

This affects the firmware of various vendors. Reported have been at least:
* Samsung: https://askubuntu.com/questions/1436856/
* Acer: https://ubuntuforums.org/showthread.php?t=2478840
* MSI: https://forum.archlabslinux.com/t/blacklist-problem-blacklisting-hash-13-errors-on-boot/6674/7
* Micro-Star: https://bbs.archlinux.org/viewtopic.php?id=278860
* Lenovo: https://lore.kernel.org/lkml/[email protected]/

Changelog:

v1: https://lore.kernel.org/all/[email protected]/
v1 -> v2:
* Improve logging message to include the failed hash
* Add key_create() function without update semantics
* Use key_create() from mark_raw_hash_blacklisted() and log specific message on -EEXIST

v2: https://lore.kernel.org/lkml/[email protected]/
v2 -> v3:
* Clarify commit titles and messages
* Drop the change to BLACKLIST_KEY_PERM from patch 3, as it was an artifact of some obsolete version of the patch and not needed

Only the first patch has been marked for stable as otherwise the whole of key_create() would need to be applied to stable.

Thomas Weißschuh (3):
certs: log hash value on blacklist error
KEYS: Add key_create()
certs: don't try to update blacklist keys

 certs/blacklist.c   |  21 ++++---
 include/linux/key.h |   8 +++
 security/keys/key.c | 149 +++++++++++++++++++++++++++++++++-----------
 3 files changed, 132 insertions(+), 46 deletions(-)

base-commit: 84368d882b9688bfac77ce48d33b1e20a4e4a787

Signature · 1 line
2.38.1
#1 lore raw

PATCH v3 1/3 certs: log hash value on blacklist error

Without this information these logs are not actionable.

For example on duplicate blacklisted hashes reported by the system firmware users should be able to report the erroneous hashes to their system vendors.

While we are at it use the dedicated format string for ERR_PTR.

Fixes 6364d106e041 ("certs: Allow root user to append signed hashes to the blacklist keyring")
---
 certs/blacklist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
certs/blacklist.c +1 -1
index 41f10601cc72..6e260c4b6a19 100644
@@ -192,7 +192,7 @@ static int mark_raw_hash_blacklisted(const char *hash)
 				   KEY_ALLOC_NOT_IN_QUOTA |
 				   KEY_ALLOC_BUILT_IN);
 	if (IS_ERR(key)) {
-		pr_err("Problem blacklisting hash (%ld)\n", PTR_ERR(key));
+		pr_err("Problem blacklisting hash %s: %pe\n", hash, key);
 		return PTR_ERR(key);
 	}
 	return 0;
Signature · 1 line
2.38.1
maintainer
#2 lore raw

Re: [PATCH v3 1/3] certs: log hash value on blacklist error

"Make blacklisted hash available in klog"

Quoted 1 line · Thomas Weißschuh

Without this information these logs are not actionable.

Without blacklisted hash?

Quoted 5 lines

For example on duplicate blacklisted hashes reported by the system firmware users should be able to report the erroneous hashes to their system vendors.

While we are at it use the dedicated format string for ERR_PTR.

Lacks the beef so saying "while we are at it" makes no sense.

Quoted 1 line
Fixes 6364d106e041 ("certs: Allow root user to append signed hashes to the blacklist keyring")

Why does this count as a bug?

Quoted 21 lines
---
 certs/blacklist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
certs/blacklist.c +1 -1
index 41f10601cc72..6e260c4b6a19 100644
@@ -192,7 +192,7 @@ static int mark_raw_hash_blacklisted(const char *hash)
 				   KEY_ALLOC_NOT_IN_QUOTA |
 				   KEY_ALLOC_BUILT_IN);
 	if (IS_ERR(key)) {
-		pr_err("Problem blacklisting hash (%ld)\n", PTR_ERR(key));
+		pr_err("Problem blacklisting hash %s: %pe\n", hash, key);
 		return PTR_ERR(key);
 	}
 	return 0;
Signature · 1 line
2.38.1

BR, Jarkko

maintainer
#6 lore raw

Re: [PATCH v3 2/3] KEYS: Add key_create()

In reply to Thomas Weißschuh
Quoted 2 lines · Thomas Weißschuh

This function works like key_create_or_update() but does not allow updating an existing key, instead returning -EEXIST.

What is "this"??

Quoted 1 line

This new function will be used by the blacklist keyring to handle EEXIST

Ditto.

BR, Jarkko

#3 lore raw

Re: [PATCH v3 1/3] certs: log hash value on blacklist error

In reply to Jarkko Sakkinen
Quoted 7 lines · Jarkko Sakkinen

"Make blacklisted hash available in klog"

Quoted 1 line · Thomas Weißschuh

Without this information these logs are not actionable.

Without blacklisted hash?

Quoted 7 lines
Quoted 5 lines

For example on duplicate blacklisted hashes reported by the system firmware users should be able to report the erroneous hashes to their system vendors.

While we are at it use the dedicated format string for ERR_PTR.

Lacks the beef so saying "while we are at it" makes no sense.

What about this:

[PATCH] certs: make blacklisted hash available in klog

One common situation triggering this log statement are duplicate hashes reported by the system firmware.

These duplicates should be removed from the firmware.

Without logging the blacklisted hash triggering the issue however the users can not report it properly to the firmware vendors and the firmware vendors can not easily see which specific hash is duplicated.

While changing the log message also use the dedicated ERR_PTR format placeholder for the returned error value.

Quoted 3 lines
Quoted 1 line
Fixes 6364d106e041 ("certs: Allow root user to append signed hashes to the blacklist keyring")

Why does this count as a bug?

These error logs are confusing to users, prompting them to waste time investigating them and even mess with their firmware settings. (As indicated in the threads linked from the cover letter)

The most correct fix would be patches 2 and 3 from this series.

I was not sure if patch 2 would be acceptable for stable as it introduces new infrastructure code.
So patch 1 enables users to report the issue to their firmware vendors and get the spurious logs resolved that way.

If these assumptions are incorrect I can fold patch 1 into patch 3.

But are patch 2 and 3 material for stable?

Quoted 23 lines
Quoted 21 lines
---
 certs/blacklist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
certs/blacklist.c +1 -1
index 41f10601cc72..6e260c4b6a19 100644
@@ -192,7 +192,7 @@ static int mark_raw_hash_blacklisted(const char *hash)
 				   KEY_ALLOC_NOT_IN_QUOTA |
 				   KEY_ALLOC_BUILT_IN);
 	if (IS_ERR(key)) {
-		pr_err("Problem blacklisting hash (%ld)\n", PTR_ERR(key));
+		pr_err("Problem blacklisting hash %s: %pe\n", hash, key);
 		return PTR_ERR(key);
 	}
 	return 0;
Signature · 1 line
2.38.1

BR, Jarkko

maintainer
#4 lore raw

Re: [PATCH v3 1/3] certs: log hash value on blacklist error

Quoted 23 lines · Thomas Weißschuh
Quoted 7 lines · Jarkko Sakkinen

"Make blacklisted hash available in klog"

Quoted 1 line · Thomas Weißschuh

Without this information these logs are not actionable.

Without blacklisted hash?

Quoted 7 lines
Quoted 5 lines

For example on duplicate blacklisted hashes reported by the system firmware users should be able to report the erroneous hashes to their system vendors.

While we are at it use the dedicated format string for ERR_PTR.

Lacks the beef so saying "while we are at it" makes no sense.

What about this:

[PATCH] certs: make blacklisted hash available in klog

One common situation triggering this log statement are duplicate hashes reported by the system firmware.

Quoted 8 lines

These duplicates should be removed from the firmware.

Without logging the blacklisted hash triggering the issue however the users can not report it properly to the firmware vendors and the firmware vendors can not easily see which specific hash is duplicated.

While changing the log message also use the dedicated ERR_PTR format placeholder for the returned error value.

Looks looks a lot better thank you!

Quoted 10 lines
Quoted 3 lines
Quoted 1 line
Fixes 6364d106e041 ("certs: Allow root user to append signed hashes to the blacklist keyring")

Why does this count as a bug?

These error logs are confusing to users, prompting them to waste time investigating them and even mess with their firmware settings. (As indicated in the threads linked from the cover letter)

The most correct fix would be patches 2 and 3 from this series.

Quoted 8 lines

I was not sure if patch 2 would be acceptable for stable as it introduces new infrastructure code.
So patch 1 enables users to report the issue to their firmware vendors and get the spurious logs resolved that way.

If these assumptions are incorrect I can fold patch 1 into patch 3.

But are patch 2 and 3 material for stable?

I cannot say anything conclusive to this before seeing updated version of the patch set.

BR, Jarkko

Tested-by on the v3 series
#8 lore raw
In reply to Thomas Weißschuh

Dear Thomas,

Am 18.11.22 um 05:03 schrieb Thomas Weißschuh:

Quoted 1 line
[    0.890814] blacklist: Problem blacklisting hash (-13)

After updating the UEFI firmware of the MSI B350M-MORTAR [1] from BIOS 1.MV 06/23/2020 to BIOS 1.O6 07/13/2022 (7A37v1O6 (Beta version)), the same (uninformative) errors were logged by Linux. With your patches, the errors are gone.

Kind regards,

Paul

[1]: https://de.msi.com/Motherboard/B350M-MORTAR/support