* [PATCH 01/15] s390/cert_store: Hold keyring->sem while reading the keyring
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 17:57 ` sashiko-bot
2026-11-16 14:35 ` [PATCH 02/15] s390/cert_store: Fix return code handling in invalidate_keyring_keys() Heiko Carstens
` (13 subsequent siblings)
14 siblings, 1 reply; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
From: Jarkko Sakkinen <jarkko@kernel.org>
invalidate_keyring_keys() does not hold keyring->sem while calling
keyring_read(), which is contrary to what keyring assumes from its callers,
and can lead to recurring bugs.
KEY_FLAG_KEEP alone does not protect from e.g. the following call path:
1. keyctl_keyring_move()
2. key_move()
3. __key_unlink()
Address the issue by guarding the critical section.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index 998f2da56175..d35b1ea22507 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -18,6 +18,7 @@
#include <linux/keyctl.h>
#include <linux/kobject.h>
#include <linux/module.h>
+#include <linux/rwsem.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
@@ -320,13 +321,17 @@ static int invalidate_keyring_keys(struct key *keyring)
struct key *current_key;
int rc;
- keyring_payload_len = key_type_keyring.read(keyring, NULL, 0);
- num_keys = keyring_payload_len / sizeof(key_serial_t);
- key_array = kzalloc_objs(key_serial_t, num_keys);
- if (!key_array)
- return -ENOMEM;
+ scoped_guard(rwsem_read, &keyring->sem) {
+ keyring_payload_len = key_type_keyring.read(keyring, NULL, 0);
+ num_keys = keyring_payload_len / sizeof(key_serial_t);
+
+ key_array = kzalloc_objs(key_serial_t, num_keys);
+ if (!key_array)
+ return -ENOMEM;
+
+ rc = key_type_keyring.read(keyring, (char *)key_array, keyring_payload_len);
+ }
- rc = key_type_keyring.read(keyring, (char *)key_array, keyring_payload_len);
if (rc != keyring_payload_len) {
pr_dbf_msg("Couldn't read keyring payload");
goto out;
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread* [PATCH 02/15] s390/cert_store: Fix return code handling in invalidate_keyring_keys()
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
2026-11-16 14:35 ` [PATCH 01/15] s390/cert_store: Hold keyring->sem while reading the keyring Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 17:55 ` sashiko-bot
2026-11-16 14:35 ` [PATCH 03/15] s390/cert_store: Fix potential use-after-free " Heiko Carstens
` (12 subsequent siblings)
14 siblings, 1 reply; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
Add missing error handling in case key_type_keyring.read() returns an
error.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index d35b1ea22507..89cc3a1683a3 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -316,15 +316,16 @@ static struct key *get_user_session_keyring(void)
static int invalidate_keyring_keys(struct key *keyring)
{
unsigned long num_keys, key_index;
- size_t keyring_payload_len;
+ long keyring_payload_len, rc;
key_serial_t *key_array;
struct key *current_key;
- int rc;
scoped_guard(rwsem_read, &keyring->sem) {
keyring_payload_len = key_type_keyring.read(keyring, NULL, 0);
- num_keys = keyring_payload_len / sizeof(key_serial_t);
+ if (keyring_payload_len <= 0)
+ return keyring_payload_len;
+ num_keys = keyring_payload_len / sizeof(key_serial_t);
key_array = kzalloc_objs(key_serial_t, num_keys);
if (!key_array)
return -ENOMEM;
@@ -334,6 +335,7 @@ static int invalidate_keyring_keys(struct key *keyring)
if (rc != keyring_payload_len) {
pr_dbf_msg("Couldn't read keyring payload");
+ rc = rc < 0 ? rc : -EINVAL;
goto out;
}
@@ -345,7 +347,7 @@ static int invalidate_keyring_keys(struct key *keyring)
key_put(current_key);
rc = key_unlink(keyring, current_key);
if (rc) {
- pr_dbf_msg("Couldn't unlink key %08x: %d", current_key->serial, rc);
+ pr_dbf_msg("Couldn't unlink key %08x: %ld", current_key->serial, rc);
break;
}
}
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread* Re: [PATCH 02/15] s390/cert_store: Fix return code handling in invalidate_keyring_keys()
2026-11-16 14:35 ` [PATCH 02/15] s390/cert_store: Fix return code handling in invalidate_keyring_keys() Heiko Carstens
@ 2026-11-16 17:55 ` sashiko-bot
0 siblings, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-16 17:55 UTC (permalink / raw)
To: Heiko Carstens, Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] s390/cert_store: unchecked key_lookup() and UAF in
invalidate_keyring_keys() [1]
--
commit ad52ff18526194809b9921405599d976809c02b9
Author: Heiko Carstens <hca@linux.ibm.com>
s390/cert_store: Fix return code handling in invalidate_keyring_keys()
This commit adds error handling to invalidate_keyring_keys() when
key_type_keyring.read() returns an error or a short read.
> diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
> index d35b1ea22507d..89cc3a1683a32 100644
> --- a/arch/s390/kernel/cert_store.c
> +++ b/arch/s390/kernel/cert_store.c
[ ... ]
> @@ -345,7 +347,7 @@ static int invalidate_keyring_keys(struct key *keyring)
> key_put(current_key);
> rc = key_unlink(keyring, current_key);
> if (rc) {
> - pr_dbf_msg("Couldn't unlink key %08x: %d", current_key->serial, rc);
> + pr_dbf_msg("Couldn't unlink key %08x: %ld", current_key->serial, rc);
> break;
> }
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but can current_key in this loop
[1] be an error pointer or be used after free?
keyring->sem is released after reading key_array, without holding references
to the keys. If a concurrent keyctl operation unlinks a key and garbage
collection frees it before key_lookup(key_array[key_index]) runs, key_lookup()
returns ERR_PTR(-ENOKEY), and dereferencing current_key->serial or passing
current_key to key_invalidate() crashes.
In addition, when key_lookup() succeeds, calling key_put(current_key) before
key_unlink(keyring, current_key) and the current_key->serial debug print drops
the caller's reference early, which allows a concurrent unlink and garbage
collection to free current_key and cause a use-after-free.
[1] https://sashiko.dev/#/bug/linux-3ea8bbf3-6016-4165-bad4-2a5916ce887e
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116143534.158375-2-hca@linux.ibm.com?part=2
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 03/15] s390/cert_store: Fix potential use-after-free in invalidate_keyring_keys()
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
2026-11-16 14:35 ` [PATCH 01/15] s390/cert_store: Hold keyring->sem while reading the keyring Heiko Carstens
2026-11-16 14:35 ` [PATCH 02/15] s390/cert_store: Fix return code handling in invalidate_keyring_keys() Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 17:08 ` Jarkko Sakkinen
2026-11-16 18:01 ` sashiko-bot
2026-11-16 14:35 ` [PATCH 04/15] s390/cert_store: Check key_lookup() return code " Heiko Carstens
` (11 subsequent siblings)
14 siblings, 2 replies; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
Drop the refcount of current_key behind all users of current_key which
dereference it, like e.g. error logging.
Fixes a potential use-after-free bug.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index 89cc3a1683a3..e5060777ce6f 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -344,12 +344,12 @@ static int invalidate_keyring_keys(struct key *keyring)
pr_dbf_msg("Invalidating key %08x", current_key->serial);
key_invalidate(current_key);
- key_put(current_key);
rc = key_unlink(keyring, current_key);
- if (rc) {
+ if (rc)
pr_dbf_msg("Couldn't unlink key %08x: %ld", current_key->serial, rc);
+ key_put(current_key);
+ if (rc)
break;
- }
}
out:
kfree(key_array);
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread* Re: [PATCH 03/15] s390/cert_store: Fix potential use-after-free in invalidate_keyring_keys()
2026-11-16 14:35 ` [PATCH 03/15] s390/cert_store: Fix potential use-after-free " Heiko Carstens
@ 2026-11-16 17:08 ` Jarkko Sakkinen
2026-11-16 18:01 ` sashiko-bot
1 sibling, 0 replies; 40+ messages in thread
From: Jarkko Sakkinen @ 2026-11-16 17:08 UTC (permalink / raw)
To: Heiko Carstens
Cc: Anastasia Eskova, Sven Schnelle, Peter Oberparleiter,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, keyrings,
linux-s390
On Mon, Nov 16, 2026 at 03:35:22PM +0100, Heiko Carstens wrote:
> Drop the refcount of current_key behind all users of current_key which
> dereference it, like e.g. error logging.
>
> Fixes a potential use-after-free bug.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> ---
> arch/s390/kernel/cert_store.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
> index 89cc3a1683a3..e5060777ce6f 100644
> --- a/arch/s390/kernel/cert_store.c
> +++ b/arch/s390/kernel/cert_store.c
> @@ -344,12 +344,12 @@ static int invalidate_keyring_keys(struct key *keyring)
> pr_dbf_msg("Invalidating key %08x", current_key->serial);
>
> key_invalidate(current_key);
> - key_put(current_key);
> rc = key_unlink(keyring, current_key);
> - if (rc) {
> + if (rc)
> pr_dbf_msg("Couldn't unlink key %08x: %ld", current_key->serial, rc);
> + key_put(current_key);
> + if (rc)
> break;
> - }
> }
> out:
> kfree(key_array);
> --
> 2.56.1
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Br, Jarkko
^ permalink raw reply [flat|nested] 40+ messages in thread* Re: [PATCH 03/15] s390/cert_store: Fix potential use-after-free in invalidate_keyring_keys()
2026-11-16 14:35 ` [PATCH 03/15] s390/cert_store: Fix potential use-after-free " Heiko Carstens
2026-11-16 17:08 ` Jarkko Sakkinen
@ 2026-11-16 18:01 ` sashiko-bot
1 sibling, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-16 18:01 UTC (permalink / raw)
To: Heiko Carstens
Cc: linux-s390, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger
> Drop the refcount of current_key behind all users of current_key which
> dereference it, like e.g. error logging.
>
> Fixes a potential use-after-free bug.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116143534.158375-2-hca@linux.ibm.com?part=3
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 04/15] s390/cert_store: Check key_lookup() return code in invalidate_keyring_keys()
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
` (2 preceding siblings ...)
2026-11-16 14:35 ` [PATCH 03/15] s390/cert_store: Fix potential use-after-free " Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 17:09 ` Jarkko Sakkinen
2026-11-16 17:52 ` sashiko-bot
2026-11-16 14:35 ` [PATCH 05/15] s390/cert_store: Unlink before invalidate " Heiko Carstens
` (10 subsequent siblings)
14 siblings, 2 replies; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
keyring->sem is released after writing the key serial numbers into
key_array. Keys corresponding to those serial numbers may have been
removed before key_lookup() is called.
Therefore check the return code of key_lookup() before dereferencing it.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index e5060777ce6f..8eb32497ca24 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -339,8 +339,11 @@ static int invalidate_keyring_keys(struct key *keyring)
goto out;
}
+ rc = 0;
for (key_index = 0; key_index < num_keys; key_index++) {
current_key = key_lookup(key_array[key_index]);
+ if (IS_ERR(current_key))
+ continue;
pr_dbf_msg("Invalidating key %08x", current_key->serial);
key_invalidate(current_key);
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread* Re: [PATCH 04/15] s390/cert_store: Check key_lookup() return code in invalidate_keyring_keys()
2026-11-16 14:35 ` [PATCH 04/15] s390/cert_store: Check key_lookup() return code " Heiko Carstens
@ 2026-11-16 17:09 ` Jarkko Sakkinen
2026-11-16 17:52 ` sashiko-bot
1 sibling, 0 replies; 40+ messages in thread
From: Jarkko Sakkinen @ 2026-11-16 17:09 UTC (permalink / raw)
To: Heiko Carstens
Cc: Anastasia Eskova, Sven Schnelle, Peter Oberparleiter,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, keyrings,
linux-s390
On Mon, Nov 16, 2026 at 03:35:23PM +0100, Heiko Carstens wrote:
> keyring->sem is released after writing the key serial numbers into
> key_array. Keys corresponding to those serial numbers may have been
> removed before key_lookup() is called.
>
> Therefore check the return code of key_lookup() before dereferencing it.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> ---
> arch/s390/kernel/cert_store.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
> index e5060777ce6f..8eb32497ca24 100644
> --- a/arch/s390/kernel/cert_store.c
> +++ b/arch/s390/kernel/cert_store.c
> @@ -339,8 +339,11 @@ static int invalidate_keyring_keys(struct key *keyring)
> goto out;
> }
>
> + rc = 0;
> for (key_index = 0; key_index < num_keys; key_index++) {
> current_key = key_lookup(key_array[key_index]);
> + if (IS_ERR(current_key))
> + continue;
> pr_dbf_msg("Invalidating key %08x", current_key->serial);
>
> key_invalidate(current_key);
> --
> 2.56.1
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Br, Jarkko
^ permalink raw reply [flat|nested] 40+ messages in thread* Re: [PATCH 04/15] s390/cert_store: Check key_lookup() return code in invalidate_keyring_keys()
2026-11-16 14:35 ` [PATCH 04/15] s390/cert_store: Check key_lookup() return code " Heiko Carstens
2026-11-16 17:09 ` Jarkko Sakkinen
@ 2026-11-16 17:52 ` sashiko-bot
1 sibling, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-16 17:52 UTC (permalink / raw)
To: Heiko Carstens
Cc: linux-s390, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger
> keyring->sem is released after writing the key serial numbers into
> key_array. Keys corresponding to those serial numbers may have been
> removed before key_lookup() is called.
>
> Therefore check the return code of key_lookup() before dereferencing it.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116143534.158375-2-hca@linux.ibm.com?part=4
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 05/15] s390/cert_store: Unlink before invalidate in invalidate_keyring_keys()
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
` (3 preceding siblings ...)
2026-11-16 14:35 ` [PATCH 04/15] s390/cert_store: Check key_lookup() return code " Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 17:53 ` sashiko-bot
2026-11-16 18:40 ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 06/15] s390/cert_store: Fix cs_keyring reference leak in fill_cs_keyring() Heiko Carstens
` (9 subsequent siblings)
14 siblings, 2 replies; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
If a key is invalidated, the key garbage collector may remove its link
from the keyring at any time. If that happens the subsequent key_unlink()
fails.
invalidate_keyring_keys() would then incorrectly return an error, which
would lead to unregistering the cert_store key type.
Unlink the key first and invalidate it afterwards to avoid this race.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index 8eb32497ca24..a69eccf6affd 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -346,10 +346,10 @@ static int invalidate_keyring_keys(struct key *keyring)
continue;
pr_dbf_msg("Invalidating key %08x", current_key->serial);
- key_invalidate(current_key);
rc = key_unlink(keyring, current_key);
if (rc)
pr_dbf_msg("Couldn't unlink key %08x: %ld", current_key->serial, rc);
+ key_invalidate(current_key);
key_put(current_key);
if (rc)
break;
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread* Re: [PATCH 05/15] s390/cert_store: Unlink before invalidate in invalidate_keyring_keys()
2026-11-16 14:35 ` [PATCH 05/15] s390/cert_store: Unlink before invalidate " Heiko Carstens
@ 2026-11-16 17:53 ` sashiko-bot
2026-11-16 18:40 ` Jarkko Sakkinen
1 sibling, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-16 17:53 UTC (permalink / raw)
To: Heiko Carstens, Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] s390/cert_store: key reference count underflow and
use-after-free in fill_cs_keyring() [1]
--
commit fbd12b78eb8c69fc439e6febd3b649bd06084a33
Author: Heiko Carstens <hca@linux.ibm.com>
s390/cert_store: Unlink before invalidate in invalidate_keyring_keys()
This commit reorders key_unlink() before key_invalidate() in
invalidate_keyring_keys() so that the key garbage collector cannot unlink
the key first and cause key_unlink() to fail.
> diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
> index 8eb32497ca24d..a69eccf6affd3 100644
> --- a/arch/s390/kernel/cert_store.c
> +++ b/arch/s390/kernel/cert_store.c
> @@ -346,10 +346,10 @@ static int invalidate_keyring_keys(struct key *keyring)
> continue;
> pr_dbf_msg("Invalidating key %08x", current_key->serial);
>
> - key_invalidate(current_key);
> rc = key_unlink(keyring, current_key);
> if (rc)
> pr_dbf_msg("Couldn't unlink key %08x: %ld", current_key->serial, rc);
> + key_invalidate(current_key);
> key_put(current_key);
> if (rc)
> break;
[Severity: Critical]
This problem wasn't introduced by this patch, but can cleanup_cs_keys()
and fill_cs_keyring() underflow cs_keyring->usage and cause a
use-after-free [1]?
In create_cs_keyring(), keyring_alloc() links cs_keyring into the user
session keyring, starting cs_keyring->usage at 2 (one allocation reference
and one link reference). However, find_cs_keyring() drops its lookup
reference before returning the raw pointer, and cleanup_cs_keys() drops
another reference before unlinking cs_keyring:
arch/s390/kernel/cert_store.c:find_cs_keyring() {
...
if (!IS_ERR(cs_keyring_ref)) {
cs_keyring = key_ref_to_ptr(cs_keyring_ref);
key_ref_put(cs_keyring_ref);
goto found;
}
...
key_put(cs_keyring);
found:
return cs_keyring;
}
arch/s390/kernel/cert_store.c:cleanup_cs_keys() {
...
cs_keyring = find_cs_keyring();
if (!cs_keyring)
return;
...
key_put(cs_keyring);
key_unlink(get_user_session_keyring(), cs_keyring);
}
arch/s390/kernel/cert_store.c:fill_cs_keyring() {
...
rc = add_certificates_to_keyring(vcssb, cs_keyring);
if (rc)
goto cleanup_cs_keyring;
goto out;
cleanup_cs_keyring:
key_put(cs_keyring);
cleanup_keys:
cleanup_cs_keys();
}
When add_certificates_to_keyring() fails in fill_cs_keyring(), the
cleanup_cs_keyring label drops cs_keyring->usage from 2 to 1 and falls
through to cleanup_cs_keys(). There, find_cs_keyring() returns cs_keyring
without holding a lookup reference, key_put(cs_keyring) drops the
remaining reference from 1 to 0 (scheduling the keyring for garbage
collection), and key_unlink() then accesses the zero-refcount key and
drops the link reference an extra time. The same extra key_put() happens
when create_cs_keyring() calls cleanup_cs_keys() to purge an existing
keyring whose initial allocation reference was already dropped.
[1] https://sashiko.dev/#/bug/linux-6c517b55-b772-4ca6-8a47-30730e6a9177
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116143534.158375-2-hca@linux.ibm.com?part=5
^ permalink raw reply [flat|nested] 40+ messages in thread* Re: [PATCH 05/15] s390/cert_store: Unlink before invalidate in invalidate_keyring_keys()
2026-11-16 14:35 ` [PATCH 05/15] s390/cert_store: Unlink before invalidate " Heiko Carstens
2026-11-16 17:53 ` sashiko-bot
@ 2026-11-16 18:40 ` Jarkko Sakkinen
1 sibling, 0 replies; 40+ messages in thread
From: Jarkko Sakkinen @ 2026-11-16 18:40 UTC (permalink / raw)
To: Heiko Carstens
Cc: Anastasia Eskova, Sven Schnelle, Peter Oberparleiter,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, keyrings,
linux-s390
On Mon, Nov 16, 2026 at 03:35:24PM +0100, Heiko Carstens wrote:
> If a key is invalidated, the key garbage collector may remove its link
> from the keyring at any time. If that happens the subsequent key_unlink()
> fails.
>
> invalidate_keyring_keys() would then incorrectly return an error, which
> would lead to unregistering the cert_store key type.
>
> Unlink the key first and invalidate it afterwards to avoid this race.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> ---
> arch/s390/kernel/cert_store.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
> index 8eb32497ca24..a69eccf6affd 100644
> --- a/arch/s390/kernel/cert_store.c
> +++ b/arch/s390/kernel/cert_store.c
> @@ -346,10 +346,10 @@ static int invalidate_keyring_keys(struct key *keyring)
> continue;
> pr_dbf_msg("Invalidating key %08x", current_key->serial);
>
> - key_invalidate(current_key);
> rc = key_unlink(keyring, current_key);
> if (rc)
> pr_dbf_msg("Couldn't unlink key %08x: %ld", current_key->serial, rc);
> + key_invalidate(current_key);
> key_put(current_key);
> if (rc)
> break;
> --
> 2.56.1
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Br, Jarkko
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 06/15] s390/cert_store: Fix cs_keyring reference leak in fill_cs_keyring()
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
` (4 preceding siblings ...)
2026-11-16 14:35 ` [PATCH 05/15] s390/cert_store: Unlink before invalidate " Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 17:57 ` sashiko-bot
2026-11-16 18:42 ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 07/15] s390/cert_store: Fix potential use-after-free caused by find_cs_keyring() Heiko Carstens
` (8 subsequent siblings)
14 siblings, 2 replies; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
create_cs_keyring() returns cs_keyring with a reference held. On the
success path fill_cs_keyring() never drops it, leaking the reference.
The keyring is kept alive by its link to the session keyring.
Drop the reference after add_certificates_to_keyring() returns.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index a69eccf6affd..386fe39fe8bd 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -723,6 +723,7 @@ static int fill_cs_keyring(void)
if (rc)
goto cleanup_cs_keyring;
+ key_put(cs_keyring);
goto out;
cleanup_cs_keyring:
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread* Re: [PATCH 06/15] s390/cert_store: Fix cs_keyring reference leak in fill_cs_keyring()
2026-11-16 14:35 ` [PATCH 06/15] s390/cert_store: Fix cs_keyring reference leak in fill_cs_keyring() Heiko Carstens
@ 2026-11-16 17:57 ` sashiko-bot
2026-11-16 18:42 ` Jarkko Sakkinen
1 sibling, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-16 17:57 UTC (permalink / raw)
To: Heiko Carstens
Cc: linux-s390, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger
> create_cs_keyring() returns cs_keyring with a reference held. On the
> success path fill_cs_keyring() never drops it, leaking the reference.
> The keyring is kept alive by its link to the session keyring.
>
> Drop the reference after add_certificates_to_keyring() returns.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116143534.158375-2-hca@linux.ibm.com?part=6
^ permalink raw reply [flat|nested] 40+ messages in thread* Re: [PATCH 06/15] s390/cert_store: Fix cs_keyring reference leak in fill_cs_keyring()
2026-11-16 14:35 ` [PATCH 06/15] s390/cert_store: Fix cs_keyring reference leak in fill_cs_keyring() Heiko Carstens
2026-11-16 17:57 ` sashiko-bot
@ 2026-11-16 18:42 ` Jarkko Sakkinen
1 sibling, 0 replies; 40+ messages in thread
From: Jarkko Sakkinen @ 2026-11-16 18:42 UTC (permalink / raw)
To: Heiko Carstens
Cc: Anastasia Eskova, Sven Schnelle, Peter Oberparleiter,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, keyrings,
linux-s390
On Mon, Nov 16, 2026 at 03:35:25PM +0100, Heiko Carstens wrote:
> create_cs_keyring() returns cs_keyring with a reference held. On the
> success path fill_cs_keyring() never drops it, leaking the reference.
> The keyring is kept alive by its link to the session keyring.
>
> Drop the reference after add_certificates_to_keyring() returns.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> ---
> arch/s390/kernel/cert_store.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
> index a69eccf6affd..386fe39fe8bd 100644
> --- a/arch/s390/kernel/cert_store.c
> +++ b/arch/s390/kernel/cert_store.c
> @@ -723,6 +723,7 @@ static int fill_cs_keyring(void)
> if (rc)
> goto cleanup_cs_keyring;
>
> + key_put(cs_keyring);
> goto out;
>
> cleanup_cs_keyring:
> --
> 2.56.1
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Br, Jarkko
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 07/15] s390/cert_store: Fix potential use-after-free caused by find_cs_keyring()
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
` (5 preceding siblings ...)
2026-11-16 14:35 ` [PATCH 06/15] s390/cert_store: Fix cs_keyring reference leak in fill_cs_keyring() Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 18:00 ` sashiko-bot
2026-11-16 18:44 ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 08/15] s390/cert_store: Remove unnecessary static specifier in create_cs_keyring() Heiko Carstens
` (7 subsequent siblings)
14 siblings, 2 replies; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
find_cs_keyring() drops the refcount of cs_keyring before returning it.
Which means that callers operate on potentially already freed memory.
Let find_cs_keyring() return cs_keyring with a reference. Since
cleanup_cs_keys() now performs a balanced put via find_cs_keyring(),
remove the separate cleanup_cs_keyring error label in fill_cs_keyring()
and drop the reference unconditionally instead.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index 386fe39fe8bd..b720dd26a557 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -367,17 +367,13 @@ static struct key *find_cs_keyring(void)
cs_keyring_ref = keyring_search(make_key_ref(get_user_session_keyring(), true),
&key_type_keyring, CERT_STORE_KEYRING_NAME,
false);
- if (!IS_ERR(cs_keyring_ref)) {
- cs_keyring = key_ref_to_ptr(cs_keyring_ref);
- key_ref_put(cs_keyring_ref);
- goto found;
- }
+ if (!IS_ERR(cs_keyring_ref))
+ return key_ref_to_ptr(cs_keyring_ref);
+
/* Search default locations: thread, process, session keyrings */
cs_keyring = request_key(&key_type_keyring, CERT_STORE_KEYRING_NAME, NULL);
if (IS_ERR(cs_keyring))
return NULL;
- key_put(cs_keyring);
-found:
return cs_keyring;
}
@@ -720,14 +716,12 @@ static int fill_cs_keyring(void)
goto cleanup_keys;
rc = add_certificates_to_keyring(vcssb, cs_keyring);
- if (rc)
- goto cleanup_cs_keyring;
-
key_put(cs_keyring);
+ if (rc)
+ goto cleanup_keys;
+
goto out;
-cleanup_cs_keyring:
- key_put(cs_keyring);
cleanup_keys:
cleanup_cs_keys();
out:
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread* Re: [PATCH 07/15] s390/cert_store: Fix potential use-after-free caused by find_cs_keyring()
2026-11-16 14:35 ` [PATCH 07/15] s390/cert_store: Fix potential use-after-free caused by find_cs_keyring() Heiko Carstens
@ 2026-11-16 18:00 ` sashiko-bot
2026-11-16 18:44 ` Jarkko Sakkinen
1 sibling, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-16 18:00 UTC (permalink / raw)
To: Heiko Carstens
Cc: linux-s390, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger
> find_cs_keyring() drops the refcount of cs_keyring before returning it.
> Which means that callers operate on potentially already freed memory.
>
> Let find_cs_keyring() return cs_keyring with a reference. Since
> cleanup_cs_keys() now performs a balanced put via find_cs_keyring(),
> remove the separate cleanup_cs_keyring error label in fill_cs_keyring()
> and drop the reference unconditionally instead.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116143534.158375-2-hca@linux.ibm.com?part=7
^ permalink raw reply [flat|nested] 40+ messages in thread* Re: [PATCH 07/15] s390/cert_store: Fix potential use-after-free caused by find_cs_keyring()
2026-11-16 14:35 ` [PATCH 07/15] s390/cert_store: Fix potential use-after-free caused by find_cs_keyring() Heiko Carstens
2026-11-16 18:00 ` sashiko-bot
@ 2026-11-16 18:44 ` Jarkko Sakkinen
1 sibling, 0 replies; 40+ messages in thread
From: Jarkko Sakkinen @ 2026-11-16 18:44 UTC (permalink / raw)
To: Heiko Carstens
Cc: Anastasia Eskova, Sven Schnelle, Peter Oberparleiter,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, keyrings,
linux-s390
On Mon, Nov 16, 2026 at 03:35:26PM +0100, Heiko Carstens wrote:
> find_cs_keyring() drops the refcount of cs_keyring before returning it.
> Which means that callers operate on potentially already freed memory.
>
> Let find_cs_keyring() return cs_keyring with a reference. Since
> cleanup_cs_keys() now performs a balanced put via find_cs_keyring(),
> remove the separate cleanup_cs_keyring error label in fill_cs_keyring()
> and drop the reference unconditionally instead.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> ---
> arch/s390/kernel/cert_store.c | 18 ++++++------------
> 1 file changed, 6 insertions(+), 12 deletions(-)
>
> diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
> index 386fe39fe8bd..b720dd26a557 100644
> --- a/arch/s390/kernel/cert_store.c
> +++ b/arch/s390/kernel/cert_store.c
> @@ -367,17 +367,13 @@ static struct key *find_cs_keyring(void)
> cs_keyring_ref = keyring_search(make_key_ref(get_user_session_keyring(), true),
> &key_type_keyring, CERT_STORE_KEYRING_NAME,
> false);
> - if (!IS_ERR(cs_keyring_ref)) {
> - cs_keyring = key_ref_to_ptr(cs_keyring_ref);
> - key_ref_put(cs_keyring_ref);
> - goto found;
> - }
> + if (!IS_ERR(cs_keyring_ref))
> + return key_ref_to_ptr(cs_keyring_ref);
> +
> /* Search default locations: thread, process, session keyrings */
> cs_keyring = request_key(&key_type_keyring, CERT_STORE_KEYRING_NAME, NULL);
> if (IS_ERR(cs_keyring))
> return NULL;
> - key_put(cs_keyring);
> -found:
> return cs_keyring;
> }
>
> @@ -720,14 +716,12 @@ static int fill_cs_keyring(void)
> goto cleanup_keys;
>
> rc = add_certificates_to_keyring(vcssb, cs_keyring);
> - if (rc)
> - goto cleanup_cs_keyring;
> -
> key_put(cs_keyring);
> + if (rc)
> + goto cleanup_keys;
> +
> goto out;
>
> -cleanup_cs_keyring:
> - key_put(cs_keyring);
> cleanup_keys:
> cleanup_cs_keys();
> out:
> --
> 2.56.1
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Br, Jarkko
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 08/15] s390/cert_store: Remove unnecessary static specifier in create_cs_keyring()
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
` (6 preceding siblings ...)
2026-11-16 14:35 ` [PATCH 07/15] s390/cert_store: Fix potential use-after-free caused by find_cs_keyring() Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 17:48 ` sashiko-bot
2026-11-16 19:00 ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 09/15] s390/cert_store: Fix error handling of get_user_session_keyring() Heiko Carstens
` (6 subsequent siblings)
14 siblings, 2 replies; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
The local variable cs_keyring in create_cs_keyring() never reuses its
assigned value, therefore remove the static specifier. Callers are
serialized by cs_refresh_lock, so this does not fix a bug.
Even though this is not a bug fix, this contains a Fixes tag since other
commits require this as a prereq.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index b720dd26a557..aefbefb40c74 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -401,7 +401,7 @@ static void cleanup_cs_keys(void)
static struct key *create_cs_keyring(void)
{
- static struct key *cs_keyring;
+ struct key *cs_keyring;
/* Cleanup previous cs_keyring and all associated keys if any. */
cleanup_cs_keys();
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread* Re: [PATCH 08/15] s390/cert_store: Remove unnecessary static specifier in create_cs_keyring()
2026-11-16 14:35 ` [PATCH 08/15] s390/cert_store: Remove unnecessary static specifier in create_cs_keyring() Heiko Carstens
@ 2026-11-16 17:48 ` sashiko-bot
2026-11-16 19:00 ` Jarkko Sakkinen
1 sibling, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-16 17:48 UTC (permalink / raw)
To: Heiko Carstens
Cc: linux-s390, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger
> The local variable cs_keyring in create_cs_keyring() never reuses its
> assigned value, therefore remove the static specifier. Callers are
> serialized by cs_refresh_lock, so this does not fix a bug.
>
> Even though this is not a bug fix, this contains a Fixes tag since other
> commits require this as a prereq.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116143534.158375-2-hca@linux.ibm.com?part=8
^ permalink raw reply [flat|nested] 40+ messages in thread* Re: [PATCH 08/15] s390/cert_store: Remove unnecessary static specifier in create_cs_keyring()
2026-11-16 14:35 ` [PATCH 08/15] s390/cert_store: Remove unnecessary static specifier in create_cs_keyring() Heiko Carstens
2026-11-16 17:48 ` sashiko-bot
@ 2026-11-16 19:00 ` Jarkko Sakkinen
1 sibling, 0 replies; 40+ messages in thread
From: Jarkko Sakkinen @ 2026-11-16 19:00 UTC (permalink / raw)
To: Heiko Carstens
Cc: Anastasia Eskova, Sven Schnelle, Peter Oberparleiter,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, keyrings,
linux-s390
On Mon, Nov 16, 2026 at 03:35:27PM +0100, Heiko Carstens wrote:
> The local variable cs_keyring in create_cs_keyring() never reuses its
> assigned value, therefore remove the static specifier. Callers are
> serialized by cs_refresh_lock, so this does not fix a bug.
>
> Even though this is not a bug fix, this contains a Fixes tag since other
> commits require this as a prereq.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> ---
> arch/s390/kernel/cert_store.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
> index b720dd26a557..aefbefb40c74 100644
> --- a/arch/s390/kernel/cert_store.c
> +++ b/arch/s390/kernel/cert_store.c
> @@ -401,7 +401,7 @@ static void cleanup_cs_keys(void)
>
> static struct key *create_cs_keyring(void)
> {
> - static struct key *cs_keyring;
> + struct key *cs_keyring;
>
> /* Cleanup previous cs_keyring and all associated keys if any. */
> cleanup_cs_keys();
> --
> 2.56.1
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Br, Jarkko
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 09/15] s390/cert_store: Fix error handling of get_user_session_keyring()
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
` (7 preceding siblings ...)
2026-11-16 14:35 ` [PATCH 08/15] s390/cert_store: Remove unnecessary static specifier in create_cs_keyring() Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 17:58 ` sashiko-bot
2026-11-16 19:01 ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 10/15] s390/cert_store: Fix keyring refcount handling in get_user_session_keyring() Heiko Carstens
` (5 subsequent siblings)
14 siblings, 2 replies; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
create_cs_keyring(), cleanup_cs_keys(), and find_cs_keyring() all pass
the return value of get_user_session_keyring() to other functions without
checking it. This can lead to dereferencing an error pointer.
Check the return value before using it.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index aefbefb40c74..d11637c85063 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -361,15 +361,18 @@ static int invalidate_keyring_keys(struct key *keyring)
static struct key *find_cs_keyring(void)
{
+ struct key *cs_keyring, *us_keyring;
key_ref_t cs_keyring_ref;
- struct key *cs_keyring;
-
- cs_keyring_ref = keyring_search(make_key_ref(get_user_session_keyring(), true),
- &key_type_keyring, CERT_STORE_KEYRING_NAME,
- false);
- if (!IS_ERR(cs_keyring_ref))
- return key_ref_to_ptr(cs_keyring_ref);
+ us_keyring = get_user_session_keyring();
+ if (!IS_ERR(us_keyring)) {
+ cs_keyring_ref = keyring_search(make_key_ref(us_keyring, true),
+ &key_type_keyring,
+ CERT_STORE_KEYRING_NAME,
+ false);
+ if (!IS_ERR(cs_keyring_ref))
+ return key_ref_to_ptr(cs_keyring_ref);
+ }
/* Search default locations: thread, process, session keyrings */
cs_keyring = request_key(&key_type_keyring, CERT_STORE_KEYRING_NAME, NULL);
if (IS_ERR(cs_keyring))
@@ -379,7 +382,7 @@ static struct key *find_cs_keyring(void)
static void cleanup_cs_keys(void)
{
- struct key *cs_keyring;
+ struct key *cs_keyring, *us_keyring;
cs_keyring = find_cs_keyring();
if (!cs_keyring)
@@ -395,21 +398,26 @@ static void cleanup_cs_keys(void)
keyring_clear(cs_keyring);
key_invalidate(cs_keyring);
+ us_keyring = get_user_session_keyring();
+ if (!IS_ERR(us_keyring))
+ key_unlink(us_keyring, cs_keyring);
key_put(cs_keyring);
- key_unlink(get_user_session_keyring(), cs_keyring);
}
static struct key *create_cs_keyring(void)
{
- struct key *cs_keyring;
+ struct key *cs_keyring, *us_keyring;
/* Cleanup previous cs_keyring and all associated keys if any. */
cleanup_cs_keys();
+ us_keyring = get_user_session_keyring();
+ if (IS_ERR(us_keyring))
+ return NULL;
cs_keyring = keyring_alloc(CERT_STORE_KEYRING_NAME, GLOBAL_ROOT_UID,
GLOBAL_ROOT_GID, current_cred(),
(KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW | KEY_USR_READ,
KEY_ALLOC_NOT_IN_QUOTA | KEY_ALLOC_SET_KEEP,
- NULL, get_user_session_keyring());
+ NULL, us_keyring);
if (IS_ERR(cs_keyring)) {
pr_dbf_msg("Can't allocate cert_store keyring");
return NULL;
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread* Re: [PATCH 09/15] s390/cert_store: Fix error handling of get_user_session_keyring()
2026-11-16 14:35 ` [PATCH 09/15] s390/cert_store: Fix error handling of get_user_session_keyring() Heiko Carstens
@ 2026-11-16 17:58 ` sashiko-bot
2026-11-16 19:01 ` Jarkko Sakkinen
1 sibling, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-16 17:58 UTC (permalink / raw)
To: Heiko Carstens
Cc: linux-s390, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger
> create_cs_keyring(), cleanup_cs_keys(), and find_cs_keyring() all pass
> the return value of get_user_session_keyring() to other functions without
> checking it. This can lead to dereferencing an error pointer.
>
> Check the return value before using it.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116143534.158375-2-hca@linux.ibm.com?part=9
^ permalink raw reply [flat|nested] 40+ messages in thread* Re: [PATCH 09/15] s390/cert_store: Fix error handling of get_user_session_keyring()
2026-11-16 14:35 ` [PATCH 09/15] s390/cert_store: Fix error handling of get_user_session_keyring() Heiko Carstens
2026-11-16 17:58 ` sashiko-bot
@ 2026-11-16 19:01 ` Jarkko Sakkinen
1 sibling, 0 replies; 40+ messages in thread
From: Jarkko Sakkinen @ 2026-11-16 19:01 UTC (permalink / raw)
To: Heiko Carstens
Cc: Anastasia Eskova, Sven Schnelle, Peter Oberparleiter,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, keyrings,
linux-s390
On Mon, Nov 16, 2026 at 03:35:28PM +0100, Heiko Carstens wrote:
> create_cs_keyring(), cleanup_cs_keys(), and find_cs_keyring() all pass
> the return value of get_user_session_keyring() to other functions without
> checking it. This can lead to dereferencing an error pointer.
>
> Check the return value before using it.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> ---
> arch/s390/kernel/cert_store.c | 30 +++++++++++++++++++-----------
> 1 file changed, 19 insertions(+), 11 deletions(-)
>
> diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
> index aefbefb40c74..d11637c85063 100644
> --- a/arch/s390/kernel/cert_store.c
> +++ b/arch/s390/kernel/cert_store.c
> @@ -361,15 +361,18 @@ static int invalidate_keyring_keys(struct key *keyring)
>
> static struct key *find_cs_keyring(void)
> {
> + struct key *cs_keyring, *us_keyring;
> key_ref_t cs_keyring_ref;
> - struct key *cs_keyring;
> -
> - cs_keyring_ref = keyring_search(make_key_ref(get_user_session_keyring(), true),
> - &key_type_keyring, CERT_STORE_KEYRING_NAME,
> - false);
> - if (!IS_ERR(cs_keyring_ref))
> - return key_ref_to_ptr(cs_keyring_ref);
>
> + us_keyring = get_user_session_keyring();
> + if (!IS_ERR(us_keyring)) {
> + cs_keyring_ref = keyring_search(make_key_ref(us_keyring, true),
> + &key_type_keyring,
> + CERT_STORE_KEYRING_NAME,
> + false);
> + if (!IS_ERR(cs_keyring_ref))
> + return key_ref_to_ptr(cs_keyring_ref);
> + }
> /* Search default locations: thread, process, session keyrings */
> cs_keyring = request_key(&key_type_keyring, CERT_STORE_KEYRING_NAME, NULL);
> if (IS_ERR(cs_keyring))
> @@ -379,7 +382,7 @@ static struct key *find_cs_keyring(void)
>
> static void cleanup_cs_keys(void)
> {
> - struct key *cs_keyring;
> + struct key *cs_keyring, *us_keyring;
>
> cs_keyring = find_cs_keyring();
> if (!cs_keyring)
> @@ -395,21 +398,26 @@ static void cleanup_cs_keys(void)
>
> keyring_clear(cs_keyring);
> key_invalidate(cs_keyring);
> + us_keyring = get_user_session_keyring();
> + if (!IS_ERR(us_keyring))
> + key_unlink(us_keyring, cs_keyring);
> key_put(cs_keyring);
> - key_unlink(get_user_session_keyring(), cs_keyring);
> }
>
> static struct key *create_cs_keyring(void)
> {
> - struct key *cs_keyring;
> + struct key *cs_keyring, *us_keyring;
>
> /* Cleanup previous cs_keyring and all associated keys if any. */
> cleanup_cs_keys();
> + us_keyring = get_user_session_keyring();
> + if (IS_ERR(us_keyring))
> + return NULL;
> cs_keyring = keyring_alloc(CERT_STORE_KEYRING_NAME, GLOBAL_ROOT_UID,
> GLOBAL_ROOT_GID, current_cred(),
> (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW | KEY_USR_READ,
> KEY_ALLOC_NOT_IN_QUOTA | KEY_ALLOC_SET_KEEP,
> - NULL, get_user_session_keyring());
> + NULL, us_keyring);
> if (IS_ERR(cs_keyring)) {
> pr_dbf_msg("Can't allocate cert_store keyring");
> return NULL;
> --
> 2.56.1
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Br, Jarkko
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 10/15] s390/cert_store: Fix keyring refcount handling in get_user_session_keyring()
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
` (8 preceding siblings ...)
2026-11-16 14:35 ` [PATCH 09/15] s390/cert_store: Fix error handling of get_user_session_keyring() Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 17:49 ` sashiko-bot
2026-11-16 19:01 ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 11/15] s390/cert_store: Do not search the process keyrings for the cert_store keyring Heiko Carstens
` (4 subsequent siblings)
14 siblings, 2 replies; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
get_user_session_keyring() drops the reference of the looked up keyring
before returning it. Callers therefore use the keyring without holding a
reference.
Return the keyring with the reference and let callers drop the reference.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index d11637c85063..ec6352528a2b 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -308,7 +308,6 @@ static struct key *get_user_session_keyring(void)
PTR_ERR(us_keyring_ref));
return ERR_PTR(-ENOKEY);
}
- key_ref_put(us_keyring_ref);
return key_ref_to_ptr(us_keyring_ref);
}
@@ -370,6 +369,7 @@ static struct key *find_cs_keyring(void)
&key_type_keyring,
CERT_STORE_KEYRING_NAME,
false);
+ key_put(us_keyring);
if (!IS_ERR(cs_keyring_ref))
return key_ref_to_ptr(cs_keyring_ref);
}
@@ -399,8 +399,10 @@ static void cleanup_cs_keys(void)
keyring_clear(cs_keyring);
key_invalidate(cs_keyring);
us_keyring = get_user_session_keyring();
- if (!IS_ERR(us_keyring))
+ if (!IS_ERR(us_keyring)) {
key_unlink(us_keyring, cs_keyring);
+ key_put(us_keyring);
+ }
key_put(cs_keyring);
}
@@ -418,6 +420,7 @@ static struct key *create_cs_keyring(void)
(KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW | KEY_USR_READ,
KEY_ALLOC_NOT_IN_QUOTA | KEY_ALLOC_SET_KEEP,
NULL, us_keyring);
+ key_put(us_keyring);
if (IS_ERR(cs_keyring)) {
pr_dbf_msg("Can't allocate cert_store keyring");
return NULL;
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread* Re: [PATCH 10/15] s390/cert_store: Fix keyring refcount handling in get_user_session_keyring()
2026-11-16 14:35 ` [PATCH 10/15] s390/cert_store: Fix keyring refcount handling in get_user_session_keyring() Heiko Carstens
@ 2026-11-16 17:49 ` sashiko-bot
2026-11-16 19:01 ` Jarkko Sakkinen
1 sibling, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-16 17:49 UTC (permalink / raw)
To: Heiko Carstens
Cc: linux-s390, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger
> get_user_session_keyring() drops the reference of the looked up keyring
> before returning it. Callers therefore use the keyring without holding a
> reference.
>
> Return the keyring with the reference and let callers drop the reference.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116143534.158375-2-hca@linux.ibm.com?part=10
^ permalink raw reply [flat|nested] 40+ messages in thread* Re: [PATCH 10/15] s390/cert_store: Fix keyring refcount handling in get_user_session_keyring()
2026-11-16 14:35 ` [PATCH 10/15] s390/cert_store: Fix keyring refcount handling in get_user_session_keyring() Heiko Carstens
2026-11-16 17:49 ` sashiko-bot
@ 2026-11-16 19:01 ` Jarkko Sakkinen
1 sibling, 0 replies; 40+ messages in thread
From: Jarkko Sakkinen @ 2026-11-16 19:01 UTC (permalink / raw)
To: Heiko Carstens
Cc: Anastasia Eskova, Sven Schnelle, Peter Oberparleiter,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, keyrings,
linux-s390
On Mon, Nov 16, 2026 at 03:35:29PM +0100, Heiko Carstens wrote:
> get_user_session_keyring() drops the reference of the looked up keyring
> before returning it. Callers therefore use the keyring without holding a
> reference.
>
> Return the keyring with the reference and let callers drop the reference.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> ---
> arch/s390/kernel/cert_store.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
> index d11637c85063..ec6352528a2b 100644
> --- a/arch/s390/kernel/cert_store.c
> +++ b/arch/s390/kernel/cert_store.c
> @@ -308,7 +308,6 @@ static struct key *get_user_session_keyring(void)
> PTR_ERR(us_keyring_ref));
> return ERR_PTR(-ENOKEY);
> }
> - key_ref_put(us_keyring_ref);
> return key_ref_to_ptr(us_keyring_ref);
> }
>
> @@ -370,6 +369,7 @@ static struct key *find_cs_keyring(void)
> &key_type_keyring,
> CERT_STORE_KEYRING_NAME,
> false);
> + key_put(us_keyring);
> if (!IS_ERR(cs_keyring_ref))
> return key_ref_to_ptr(cs_keyring_ref);
> }
> @@ -399,8 +399,10 @@ static void cleanup_cs_keys(void)
> keyring_clear(cs_keyring);
> key_invalidate(cs_keyring);
> us_keyring = get_user_session_keyring();
> - if (!IS_ERR(us_keyring))
> + if (!IS_ERR(us_keyring)) {
> key_unlink(us_keyring, cs_keyring);
> + key_put(us_keyring);
> + }
> key_put(cs_keyring);
> }
>
> @@ -418,6 +420,7 @@ static struct key *create_cs_keyring(void)
> (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW | KEY_USR_READ,
> KEY_ALLOC_NOT_IN_QUOTA | KEY_ALLOC_SET_KEEP,
> NULL, us_keyring);
> + key_put(us_keyring);
> if (IS_ERR(cs_keyring)) {
> pr_dbf_msg("Can't allocate cert_store keyring");
> return NULL;
> --
> 2.56.1
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Br, Jarkko
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 11/15] s390/cert_store: Do not search the process keyrings for the cert_store keyring
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
` (9 preceding siblings ...)
2026-11-16 14:35 ` [PATCH 10/15] s390/cert_store: Fix keyring refcount handling in get_user_session_keyring() Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 17:53 ` sashiko-bot
2026-11-16 19:02 ` Jarkko Sakkinen
2026-11-16 14:35 ` [PATCH 12/15] s390/cert_store: Validate hash length in check_certificate_valid() Heiko Carstens
` (3 subsequent siblings)
14 siblings, 2 replies; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
find_cs_keyring() first searches the user session keyring for the
cert_store keyring, and falls back to request_key(), which searches the
thread, process and session keyrings of the calling task. Any keyring
named "cert_store" found this way is accepted.
cleanup_cs_keys() then invalidates and unlinks all of its keys, and
clears and invalidates the keyring itself, without checking permissions.
If the refresh is triggered by a task which inherited a session keyring
that contains a keyring named "cert_store" not created by this code, this
keyring and its keys are destroyed.
create_cs_keyring() always links the keyring into the user session
keyring, so the first search is sufficient. Remove the request_key()
fallback.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index ec6352528a2b..551b538ea930 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -360,7 +360,7 @@ static int invalidate_keyring_keys(struct key *keyring)
static struct key *find_cs_keyring(void)
{
- struct key *cs_keyring, *us_keyring;
+ struct key *us_keyring;
key_ref_t cs_keyring_ref;
us_keyring = get_user_session_keyring();
@@ -373,11 +373,7 @@ static struct key *find_cs_keyring(void)
if (!IS_ERR(cs_keyring_ref))
return key_ref_to_ptr(cs_keyring_ref);
}
- /* Search default locations: thread, process, session keyrings */
- cs_keyring = request_key(&key_type_keyring, CERT_STORE_KEYRING_NAME, NULL);
- if (IS_ERR(cs_keyring))
- return NULL;
- return cs_keyring;
+ return NULL;
}
static void cleanup_cs_keys(void)
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread* Re: [PATCH 11/15] s390/cert_store: Do not search the process keyrings for the cert_store keyring
2026-11-16 14:35 ` [PATCH 11/15] s390/cert_store: Do not search the process keyrings for the cert_store keyring Heiko Carstens
@ 2026-11-16 17:53 ` sashiko-bot
2026-11-16 19:02 ` Jarkko Sakkinen
1 sibling, 0 replies; 40+ messages in thread
From: sashiko-bot @ 2026-11-16 17:53 UTC (permalink / raw)
To: Heiko Carstens
Cc: linux-s390, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger
> find_cs_keyring() first searches the user session keyring for the
> cert_store keyring, and falls back to request_key(), which searches the
> thread, process and session keyrings of the calling task. Any keyring
> named "cert_store" found this way is accepted.
>
> cleanup_cs_keys() then invalidates and unlinks all of its keys, and
> clears and invalidates the keyring itself, without checking permissions.
> If the refresh is triggered by a task which inherited a session keyring
> that contains a keyring named "cert_store" not created by this code, this
> keyring and its keys are destroyed.
>
> create_cs_keyring() always links the keyring into the user session
> keyring, so the first search is sufficient. Remove the request_key()
> fallback.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116143534.158375-2-hca@linux.ibm.com?part=11
^ permalink raw reply [flat|nested] 40+ messages in thread* Re: [PATCH 11/15] s390/cert_store: Do not search the process keyrings for the cert_store keyring
2026-11-16 14:35 ` [PATCH 11/15] s390/cert_store: Do not search the process keyrings for the cert_store keyring Heiko Carstens
2026-11-16 17:53 ` sashiko-bot
@ 2026-11-16 19:02 ` Jarkko Sakkinen
1 sibling, 0 replies; 40+ messages in thread
From: Jarkko Sakkinen @ 2026-11-16 19:02 UTC (permalink / raw)
To: Heiko Carstens
Cc: Anastasia Eskova, Sven Schnelle, Peter Oberparleiter,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, keyrings,
linux-s390
On Mon, Nov 16, 2026 at 03:35:30PM +0100, Heiko Carstens wrote:
> find_cs_keyring() first searches the user session keyring for the
> cert_store keyring, and falls back to request_key(), which searches the
> thread, process and session keyrings of the calling task. Any keyring
> named "cert_store" found this way is accepted.
>
> cleanup_cs_keys() then invalidates and unlinks all of its keys, and
> clears and invalidates the keyring itself, without checking permissions.
> If the refresh is triggered by a task which inherited a session keyring
> that contains a keyring named "cert_store" not created by this code, this
> keyring and its keys are destroyed.
>
> create_cs_keyring() always links the keyring into the user session
> keyring, so the first search is sufficient. Remove the request_key()
> fallback.
>
> Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> ---
> arch/s390/kernel/cert_store.c | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
> index ec6352528a2b..551b538ea930 100644
> --- a/arch/s390/kernel/cert_store.c
> +++ b/arch/s390/kernel/cert_store.c
> @@ -360,7 +360,7 @@ static int invalidate_keyring_keys(struct key *keyring)
>
> static struct key *find_cs_keyring(void)
> {
> - struct key *cs_keyring, *us_keyring;
> + struct key *us_keyring;
> key_ref_t cs_keyring_ref;
>
> us_keyring = get_user_session_keyring();
> @@ -373,11 +373,7 @@ static struct key *find_cs_keyring(void)
> if (!IS_ERR(cs_keyring_ref))
> return key_ref_to_ptr(cs_keyring_ref);
> }
> - /* Search default locations: thread, process, session keyrings */
> - cs_keyring = request_key(&key_type_keyring, CERT_STORE_KEYRING_NAME, NULL);
> - if (IS_ERR(cs_keyring))
> - return NULL;
> - return cs_keyring;
> + return NULL;
> }
>
> static void cleanup_cs_keys(void)
> --
> 2.56.1
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Br, Jarkko
^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 12/15] s390/cert_store: Validate hash length in check_certificate_valid()
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
` (10 preceding siblings ...)
2026-11-16 14:35 ` [PATCH 11/15] s390/cert_store: Do not search the process keyrings for the cert_store keyring Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 17:51 ` sashiko-bot
2026-11-16 14:35 ` [PATCH 13/15] s390/cert_store: Fix max_vcxe_length output in pr_dbf_vcssb() Heiko Carstens
` (2 subsequent siblings)
14 siblings, 1 reply; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
Validate that vc_hash_length is SHA256_DIGEST_SIZE before checking the
hash and use sizeof(hash) in memcmp(). This avoids an out-of-bounds
read if vc_hash_length is incorrect.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index 551b538ea930..ecfb7641d427 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -261,13 +261,11 @@ static int diag320(unsigned long subcode, void *addr)
static int check_certificate_hash(const struct vce *vce)
{
u8 hash[SHA256_DIGEST_SIZE];
- u16 vc_hash_length;
u8 *vce_hash;
vce_hash = (u8 *)vce + vce->vce_hdr.vc_hash_offset;
- vc_hash_length = vce->vce_hdr.vc_hash_length;
sha256((u8 *)vce + vce->vce_hdr.vc_offset, vce->vce_hdr.vc_length, hash);
- if (memcmp(vce_hash, hash, vc_hash_length) == 0)
+ if (memcmp(vce_hash, hash, sizeof(hash)) == 0)
return 0;
pr_dbf_msg("SHA256 hash of received certificate does not match");
@@ -293,6 +291,10 @@ static int check_certificate_valid(const struct vce *vce)
pr_dbf_msg("Hash type is not supported");
return -EINVAL;
}
+ if (vce->vce_hdr.vc_hash_length != SHA256_DIGEST_SIZE) {
+ pr_dbf_msg("Hash length is not supported");
+ return -EINVAL;
+ }
return check_certificate_hash(vce);
}
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread* [PATCH 13/15] s390/cert_store: Fix max_vcxe_length output in pr_dbf_vcssb()
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
` (11 preceding siblings ...)
2026-11-16 14:35 ` [PATCH 12/15] s390/cert_store: Validate hash length in check_certificate_valid() Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 17:53 ` sashiko-bot
2026-11-16 14:35 ` [PATCH 14/15] s390/cert_store: Fix out-of-bounds read in pr_dbf_vce() Heiko Carstens
2026-11-16 14:35 ` [PATCH 15/15] s390/cert_store: Initialize ism array in query_diag320_subcodes() Heiko Carstens
14 siblings, 1 reply; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
Print the correct value for max_vcxe_length.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index ecfb7641d427..996ca3025629 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -225,7 +225,7 @@ static void pr_dbf_vcssb(const struct vcssb *s)
pr_dbf_msg("total_vc_index_count: %u", s->total_vc_index_count);
pr_dbf_msg("max_vc_index_count: %u", s->max_vc_index_count);
pr_dbf_msg("max_vce_length: %u", s->max_vce_length);
- pr_dbf_msg("max_vcxe_length: %u", s->max_vce_length);
+ pr_dbf_msg("max_vcxe_length: %u", s->max_vcxe_length);
pr_dbf_msg("max_single_vcb_length: %u", s->max_single_vcb_length);
pr_dbf_msg("total_vcb_length: %u", s->total_vcb_length);
pr_dbf_msg("max_single_vcxb_length: %u", s->max_single_vcxb_length);
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread* [PATCH 14/15] s390/cert_store: Fix out-of-bounds read in pr_dbf_vce()
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
` (12 preceding siblings ...)
2026-11-16 14:35 ` [PATCH 13/15] s390/cert_store: Fix max_vcxe_length output in pr_dbf_vcssb() Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 17:56 ` sashiko-bot
2026-11-16 14:35 ` [PATCH 15/15] s390/cert_store: Initialize ism array in query_diag320_subcodes() Heiko Carstens
14 siblings, 1 reply; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
pr_dbf_vce() dumps the last 128 bytes of the certificate data of a
Verification Certificate Entry (VCE) into a debug area.
However the address calculation is wrong: vce_length is the length of
the whole entry including the header, while cert_data_buf starts
behind the header. Therefore the dump starts at the end of the entry
and starts reading behind it.
Dump the last 128 bytes of the entry like intended. Limit dumps to the
data length.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index 996ca3025629..12fc0ee87f3b 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -181,6 +181,7 @@ static void pr_dbf_vce(const struct vce *e)
{
unsigned char vc_name[VC_NAME_LEN_BYTES + 1];
char log_string[VC_NAME_LEN_BYTES + 40];
+ u32 data_len = 0;
pr_dbf_msg("VCE Header:");
pr_dbf_msg("vce_hdr.vce_length: %d", e->vce_hdr.vce_length);
@@ -206,11 +207,13 @@ static void pr_dbf_vce(const struct vce *e)
debug_text_event(cert_store_hexdump, 3, log_string);
/* Certificate data. */
+ if (e->vce_hdr.vce_length > sizeof(e->vce_hdr))
+ data_len = e->vce_hdr.vce_length - sizeof(e->vce_hdr);
debug_text_event(cert_store_hexdump, 3, "VCE: Certificate data start");
- debug_event(cert_store_hexdump, 3, (u8 *)e->cert_data_buf, 128);
+ debug_event(cert_store_hexdump, 3, (u8 *)e->cert_data_buf, min(data_len, 128U));
debug_text_event(cert_store_hexdump, 3, "VCE: Certificate data end");
- debug_event(cert_store_hexdump, 3,
- (u8 *)e->cert_data_buf + e->vce_hdr.vce_length - 128, 128);
+ if (data_len > 128)
+ debug_event(cert_store_hexdump, 3, (u8 *)e + e->vce_hdr.vce_length - 128, 128);
}
static void pr_dbf_vcssb(const struct vcssb *s)
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread* [PATCH 15/15] s390/cert_store: Initialize ism array in query_diag320_subcodes()
2026-11-16 14:35 [PATCH 00/15] s390/cert_store: Various fixes Heiko Carstens
` (13 preceding siblings ...)
2026-11-16 14:35 ` [PATCH 14/15] s390/cert_store: Fix out-of-bounds read in pr_dbf_vce() Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
2026-11-16 17:55 ` sashiko-bot
14 siblings, 1 reply; 40+ messages in thread
From: Heiko Carstens @ 2026-11-16 14:35 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
The Installed Subcode Block returned by DIAG 320 subcode 0 may be smaller
than the ism array. Initialize it to avoid copying uninitialized data to
the debug area.
Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/cert_store.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index 12fc0ee87f3b..e3cc9389a50a 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -670,7 +670,7 @@ static int add_certificates_to_keyring(struct vcssb *vcssb, struct key *keyring)
*/
static int query_diag320_subcodes(void)
{
- unsigned long ism[ISM_LEN_DWORDS];
+ unsigned long ism[ISM_LEN_DWORDS] = {};
int rc;
rc = diag320(0, ism);
--
2.56.1
^ permalink raw reply related [flat|nested] 40+ messages in thread