Linux s390 Architecture development
 help / color / mirror / Atom feed
* [PATCH 03/15] s390/cert_store: Fix potential use-after-free in invalidate_keyring_keys()
       [not found] <20261116143534.158375-1-hca@linux.ibm.com>
@ 2026-11-16 14:35 ` Heiko Carstens
  2026-11-16 14:35 ` [PATCH 04/15] s390/cert_store: Check key_lookup() return code " Heiko Carstens
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 10+ 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] 10+ messages in thread

* [PATCH 04/15] s390/cert_store: Check key_lookup() return code in invalidate_keyring_keys()
       [not found] <20261116143534.158375-1-hca@linux.ibm.com>
  2026-11-16 14:35 ` [PATCH 03/15] s390/cert_store: Fix potential use-after-free in invalidate_keyring_keys() Heiko Carstens
@ 2026-11-16 14:35 ` Heiko Carstens
  2026-11-16 14:35 ` [PATCH 05/15] s390/cert_store: Unlink before invalidate " Heiko Carstens
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 10+ 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] 10+ messages in thread

* [PATCH 05/15] s390/cert_store: Unlink before invalidate in invalidate_keyring_keys()
       [not found] <20261116143534.158375-1-hca@linux.ibm.com>
  2026-11-16 14:35 ` [PATCH 03/15] s390/cert_store: Fix potential use-after-free in invalidate_keyring_keys() Heiko Carstens
  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 14:35 ` [PATCH 06/15] s390/cert_store: Fix cs_keyring reference leak in fill_cs_keyring() Heiko Carstens
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 10+ 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] 10+ messages in thread

* [PATCH 06/15] s390/cert_store: Fix cs_keyring reference leak in fill_cs_keyring()
       [not found] <20261116143534.158375-1-hca@linux.ibm.com>
                   ` (2 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 14:35 ` [PATCH 07/15] s390/cert_store: Fix potential use-after-free caused by find_cs_keyring() Heiko Carstens
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 10+ 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] 10+ messages in thread

* [PATCH 07/15] s390/cert_store: Fix potential use-after-free caused by find_cs_keyring()
       [not found] <20261116143534.158375-1-hca@linux.ibm.com>
                   ` (3 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 14:35 ` [PATCH 08/15] s390/cert_store: Remove unnecessary static specifier in create_cs_keyring() Heiko Carstens
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 10+ 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] 10+ messages in thread

* [PATCH 08/15] s390/cert_store: Remove unnecessary static specifier in create_cs_keyring()
       [not found] <20261116143534.158375-1-hca@linux.ibm.com>
                   ` (4 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 14:35 ` [PATCH 10/15] s390/cert_store: Fix keyring refcount handling in get_user_session_keyring() Heiko Carstens
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 10+ 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] 10+ messages in thread

* [PATCH 10/15] s390/cert_store: Fix keyring refcount handling in get_user_session_keyring()
       [not found] <20261116143534.158375-1-hca@linux.ibm.com>
                   ` (5 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 14:35 ` [PATCH 11/15] s390/cert_store: Do not search the process keyrings for the cert_store keyring Heiko Carstens
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 10+ 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] 10+ messages in thread

* [PATCH 11/15] s390/cert_store: Do not search the process keyrings for the cert_store keyring
       [not found] <20261116143534.158375-1-hca@linux.ibm.com>
                   ` (6 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 14:35 ` [PATCH 13/15] s390/cert_store: Fix max_vcxe_length output in pr_dbf_vcssb() Heiko Carstens
  2026-11-16 14:35 ` [PATCH 14/15] s390/cert_store: Fix out-of-bounds read in pr_dbf_vce() Heiko Carstens
  9 siblings, 0 replies; 10+ 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] 10+ messages in thread

* [PATCH 13/15] s390/cert_store: Fix max_vcxe_length output in pr_dbf_vcssb()
       [not found] <20261116143534.158375-1-hca@linux.ibm.com>
                   ` (7 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 14:35 ` [PATCH 14/15] s390/cert_store: Fix out-of-bounds read in pr_dbf_vce() Heiko Carstens
  9 siblings, 0 replies; 10+ 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] 10+ messages in thread

* [PATCH 14/15] s390/cert_store: Fix out-of-bounds read in pr_dbf_vce()
       [not found] <20261116143534.158375-1-hca@linux.ibm.com>
                   ` (8 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
  9 siblings, 0 replies; 10+ 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] 10+ messages in thread

end of thread, other threads:[~2026-11-16 14:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261116143534.158375-1-hca@linux.ibm.com>
2026-11-16 14:35 ` [PATCH 03/15] s390/cert_store: Fix potential use-after-free in invalidate_keyring_keys() Heiko Carstens
2026-11-16 14:35 ` [PATCH 04/15] s390/cert_store: Check key_lookup() return code " Heiko Carstens
2026-11-16 14:35 ` [PATCH 05/15] s390/cert_store: Unlink before invalidate " Heiko Carstens
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 ` [PATCH 07/15] s390/cert_store: Fix potential use-after-free caused by find_cs_keyring() Heiko Carstens
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 ` [PATCH 10/15] s390/cert_store: Fix keyring refcount handling in get_user_session_keyring() Heiko Carstens
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 ` [PATCH 13/15] s390/cert_store: Fix max_vcxe_length output in pr_dbf_vcssb() Heiko Carstens
2026-11-16 14:35 ` [PATCH 14/15] s390/cert_store: Fix out-of-bounds read in pr_dbf_vce() Heiko Carstens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox