* [PATCH 0/2] s390/cert_store: Restrict link creation and key type creation
@ 2026-11-23 10:23 Heiko Carstens
2026-11-23 10:23 ` [PATCH 1/2] s390/cert_store: Allocate keyring with link restriction Heiko Carstens
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Heiko Carstens @ 2026-11-23 10:23 UTC (permalink / raw)
To: Jarkko Sakkinen, Anastasia Eskova
Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik,
Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390
Two more patches from Anastasia, which apply on top of linux-next
20261120, which includes all the previous cert_store fixes:
Patch 1 allocates the keyring with a restriction which rejects all
links, so a possessor of the keyring can no longer link arbitrary keys
into it before the certificates have been added.
Patch 2 only allows the kernel to create cert_store_key keys. Fixes
potential disclosure of adjacent kernel heap memory to user space.
Thanks,
Heiko
Anastasia Eskova (2):
s390/cert_store: Allocate keyring with link restriction
s390/cert_store: Only allow the kernel to create cert_store_key keys
arch/s390/kernel/cert_store.c | 38 ++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 10 deletions(-)
base-commit: 909ef7a9a30fa139e69e555e3606680f5cca7726
--
2.53.0
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 1/2] s390/cert_store: Allocate keyring with link restriction 2026-11-23 10:23 [PATCH 0/2] s390/cert_store: Restrict link creation and key type creation Heiko Carstens @ 2026-11-23 10:23 ` Heiko Carstens 2026-11-23 13:42 ` Jarkko Sakkinen 2026-11-23 10:23 ` [PATCH 2/2] s390/cert_store: Only allow the kernel to create cert_store_key keys Heiko Carstens 2026-11-23 10:31 ` [PATCH 0/2] s390/cert_store: Restrict link creation and key type creation sashiko-bot 2 siblings, 1 reply; 9+ messages in thread From: Heiko Carstens @ 2026-11-23 10:23 UTC (permalink / raw) To: Jarkko Sakkinen, Anastasia Eskova Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390 From: Anastasia Eskova <anastasia.eskova@ibm.com> The keyring is linked into the user session keyring on allocation, but keyring_restrict() is only called after all certificates were added. Until then a possessor of the keyring can link arbitrary keys into it. If keyring_restrict() fails, the error is only logged and the keyring stays writable. Allocate the keyring with a restriction which rejects all links, create the certificate keys with KEY_ALLOC_BYPASS_RESTRICTION and drop the late keyring_restrict() call. Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates") Signed-off-by: Anastasia Eskova <anastasia.eskova@ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> --- arch/s390/kernel/cert_store.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c index e3cc9389a50a..6f5c63cd907f 100644 --- a/arch/s390/kernel/cert_store.c +++ b/arch/s390/kernel/cert_store.c @@ -409,6 +409,7 @@ static void cleanup_cs_keys(void) static struct key *create_cs_keyring(void) { + struct key_restriction *restriction; struct key *cs_keyring, *us_keyring; /* Cleanup previous cs_keyring and all associated keys if any. */ @@ -416,13 +417,21 @@ static struct key *create_cs_keyring(void) us_keyring = get_user_session_keyring(); if (IS_ERR(us_keyring)) return NULL; + restriction = kzalloc_obj(*restriction); + if (!restriction) { + key_put(us_keyring); + return NULL; + } + /* Reject all links, the kernel bypasses the restriction. */ + restriction->check = restrict_link_reject; 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, us_keyring); + restriction, us_keyring); key_put(us_keyring); if (IS_ERR(cs_keyring)) { + kfree(restriction); pr_dbf_msg("Can't allocate cert_store keyring"); return NULL; } @@ -485,7 +494,7 @@ static int create_key_from_vce(struct vcssb *vcssb, struct vce *vce, desc, (u8 *)vce + vce->vce_hdr.vc_offset, vce->vce_hdr.vc_length, (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW | KEY_USR_READ, - KEY_ALLOC_NOT_IN_QUOTA); + KEY_ALLOC_NOT_IN_QUOTA | KEY_ALLOC_BYPASS_RESTRICTION); rc = PTR_ERR_OR_ZERO(newkey); if (rc) { @@ -653,14 +662,6 @@ static int add_certificates_to_keyring(struct vcssb *vcssb, struct key *keyring) pr_info("Added %d of %d keys to cert_store keyring", added, count); - /* - * Do not allow to link more keys to certificate store keyring after all - * the VCEs were processed. - */ - rc = keyring_restrict(make_key_ref(keyring, true), NULL, NULL); - if (rc) - pr_dbf_msg("Failed to set restriction to cert_store keyring (%d)", rc); - return 0; } -- 2.53.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] s390/cert_store: Allocate keyring with link restriction 2026-11-23 10:23 ` [PATCH 1/2] s390/cert_store: Allocate keyring with link restriction Heiko Carstens @ 2026-11-23 13:42 ` Jarkko Sakkinen 2026-11-23 14:11 ` Heiko Carstens 0 siblings, 1 reply; 9+ messages in thread From: Jarkko Sakkinen @ 2026-11-23 13: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 23, 2026 at 11:23:23AM +0100, Heiko Carstens wrote: > From: Anastasia Eskova <anastasia.eskova@ibm.com> > > The keyring is linked into the user session keyring on allocation, but > keyring_restrict() is only called after all certificates were added. > Until then a possessor of the keyring can link arbitrary keys into it. > If keyring_restrict() fails, the error is only logged and the keyring > stays writable. > > Allocate the keyring with a restriction which rejects all links, create > the certificate keys with KEY_ALLOC_BYPASS_RESTRICTION and drop the late > keyring_restrict() call. > > Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates") > Signed-off-by: Anastasia Eskova <anastasia.eskova@ibm.com> > Signed-off-by: Heiko Carstens <hca@linux.ibm.com> I think it is best for overall good that earliest possible release for my intersecting changes is v4.7. I think that it is good to do that architectural change but since it is a problem solved there's no need to rush it in. Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Br, Jarkko ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] s390/cert_store: Allocate keyring with link restriction 2026-11-23 13:42 ` Jarkko Sakkinen @ 2026-11-23 14:11 ` Heiko Carstens 2026-11-23 14:18 ` Jarkko Sakkinen 0 siblings, 1 reply; 9+ messages in thread From: Heiko Carstens @ 2026-11-23 14:11 UTC (permalink / raw) To: Jarkko Sakkinen Cc: Anastasia Eskova, Sven Schnelle, Peter Oberparleiter, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390 On Mon, Nov 23, 2026 at 03:42:13PM +0200, Jarkko Sakkinen wrote: > On Mon, Nov 23, 2026 at 11:23:23AM +0100, Heiko Carstens wrote: > > From: Anastasia Eskova <anastasia.eskova@ibm.com> > > > > The keyring is linked into the user session keyring on allocation, but > > keyring_restrict() is only called after all certificates were added. > > Until then a possessor of the keyring can link arbitrary keys into it. > > If keyring_restrict() fails, the error is only logged and the keyring > > stays writable. > > > > Allocate the keyring with a restriction which rejects all links, create > > the certificate keys with KEY_ALLOC_BYPASS_RESTRICTION and drop the late > > keyring_restrict() call. > > > > Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates") > > Signed-off-by: Anastasia Eskova <anastasia.eskova@ibm.com> > > Signed-off-by: Heiko Carstens <hca@linux.ibm.com> > > I think it is best for overall good that earliest possible release > for my intersecting changes is v4.7. I think that it is good to I guess you meant to write 7.4? > do that architectural change but since it is a problem solved > there's no need to rush it in. All the fixes are planned to hit upstream before 7.4 is released. > Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Thanks a lot! ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] s390/cert_store: Allocate keyring with link restriction 2026-11-23 14:11 ` Heiko Carstens @ 2026-11-23 14:18 ` Jarkko Sakkinen 2026-11-23 14:20 ` Jarkko Sakkinen 0 siblings, 1 reply; 9+ messages in thread From: Jarkko Sakkinen @ 2026-11-23 14:18 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 23, 2026 at 03:11:00PM +0100, Heiko Carstens wrote: > On Mon, Nov 23, 2026 at 03:42:13PM +0200, Jarkko Sakkinen wrote: > > On Mon, Nov 23, 2026 at 11:23:23AM +0100, Heiko Carstens wrote: > > > From: Anastasia Eskova <anastasia.eskova@ibm.com> > > > > > > The keyring is linked into the user session keyring on allocation, but > > > keyring_restrict() is only called after all certificates were added. > > > Until then a possessor of the keyring can link arbitrary keys into it. > > > If keyring_restrict() fails, the error is only logged and the keyring > > > stays writable. > > > > > > Allocate the keyring with a restriction which rejects all links, create > > > the certificate keys with KEY_ALLOC_BYPASS_RESTRICTION and drop the late > > > keyring_restrict() call. > > > > > > Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates") > > > Signed-off-by: Anastasia Eskova <anastasia.eskova@ibm.com> > > > Signed-off-by: Heiko Carstens <hca@linux.ibm.com> > > > > I think it is best for overall good that earliest possible release > > for my intersecting changes is v4.7. I think that it is good to > > I guess you meant to write 7.4? Yes, 7.4 :-) > > > do that architectural change but since it is a problem solved > > there's no need to rush it in. > > All the fixes are planned to hit upstream before 7.4 is released. > > > Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> > > Thanks a lot! NP :-) Br, Jarkko ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] s390/cert_store: Allocate keyring with link restriction 2026-11-23 14:18 ` Jarkko Sakkinen @ 2026-11-23 14:20 ` Jarkko Sakkinen 0 siblings, 0 replies; 9+ messages in thread From: Jarkko Sakkinen @ 2026-11-23 14:20 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 23, 2026 at 04:18:15PM +0200, Jarkko Sakkinen wrote: > On Mon, Nov 23, 2026 at 03:11:00PM +0100, Heiko Carstens wrote: > > On Mon, Nov 23, 2026 at 03:42:13PM +0200, Jarkko Sakkinen wrote: > > > On Mon, Nov 23, 2026 at 11:23:23AM +0100, Heiko Carstens wrote: > > > > From: Anastasia Eskova <anastasia.eskova@ibm.com> > > > > > > > > The keyring is linked into the user session keyring on allocation, but > > > > keyring_restrict() is only called after all certificates were added. > > > > Until then a possessor of the keyring can link arbitrary keys into it. > > > > If keyring_restrict() fails, the error is only logged and the keyring > > > > stays writable. > > > > > > > > Allocate the keyring with a restriction which rejects all links, create > > > > the certificate keys with KEY_ALLOC_BYPASS_RESTRICTION and drop the late > > > > keyring_restrict() call. > > > > > > > > Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates") > > > > Signed-off-by: Anastasia Eskova <anastasia.eskova@ibm.com> > > > > Signed-off-by: Heiko Carstens <hca@linux.ibm.com> > > > > > > I think it is best for overall good that earliest possible release > > > for my intersecting changes is v4.7. I think that it is good to > > > > I guess you meant to write 7.4? > > Yes, 7.4 :-) I'll open code this fully. My plan for keyrings is: 1. v7.5: assoc_array to rhashtable migration. 2. v7.6: make keys to bind key type's LKM. This went all wrong but anyway. Both are architectural overturns so I think it is better to stage them like this. Br, Jarkko ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/2] s390/cert_store: Only allow the kernel to create cert_store_key keys 2026-11-23 10:23 [PATCH 0/2] s390/cert_store: Restrict link creation and key type creation Heiko Carstens 2026-11-23 10:23 ` [PATCH 1/2] s390/cert_store: Allocate keyring with link restriction Heiko Carstens @ 2026-11-23 10:23 ` Heiko Carstens 2026-11-23 13:43 ` Jarkko Sakkinen 2026-11-23 10:31 ` [PATCH 0/2] s390/cert_store: Restrict link creation and key type creation sashiko-bot 2 siblings, 1 reply; 9+ messages in thread From: Heiko Carstens @ 2026-11-23 10:23 UTC (permalink / raw) To: Jarkko Sakkinen, Anastasia Eskova Cc: Sven Schnelle, Peter Oberparleiter, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger, keyrings, linux-s390 From: Anastasia Eskova <anastasia.eskova@ibm.com> Keys of type cert_store_key can be created by any user with add_key() in any keyring, as the key type has no vet_description() callback. The type is registered whenever CONFIG_CERT_STORE is enabled, even if the machine has no DIAG 320 support. cert_store_key_describe() expects a description in the format created by get_key_description(), i.e. a 64 byte key name followed by the VCE index and the certificate store token. If a key with a shorter description is created, seq_puts() may read beyond the end of the description allocation. Reading /proc/keys may then disclose adjacent kernel heap memory to the user space. Also, a consumer which trusts keys by type can be fooled by keys that were not created from the certificate store. Add a vet_description() callback which only accepts the task currently executing refresh_store(), which creates all valid keys of this type. Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates") Signed-off-by: Anastasia Eskova <anastasia.eskova@ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> --- arch/s390/kernel/cert_store.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c index 6f5c63cd907f..6e518ff38322 100644 --- a/arch/s390/kernel/cert_store.c +++ b/arch/s390/kernel/cert_store.c @@ -46,6 +46,9 @@ static debug_info_t *cert_store_dbf; static debug_info_t *cert_store_hexdump; +/* Task currently running refresh_store(). Written under cs_refresh_lock. */ +static struct task_struct *cs_refresh_task; + #define pr_dbf_msg(fmt, ...) \ debug_sprintf_event(cert_store_dbf, 3, fmt "\n", ## __VA_ARGS__) @@ -148,12 +151,24 @@ static void cert_store_key_describe(const struct key *key, struct seq_file *m) seq_printf(m, ": %u", key->datalen); } +/* + * Only the kernel may create keys of this type. Accept the task which runs + * refresh_store(), as it cannot execute userspace during the refresh. + */ +static int cert_store_key_vet_description(const char *description) +{ + if (READ_ONCE(cs_refresh_task) != current) + return -EPERM; + return 0; +} + /* * Certificate store key type takes over properties of * user key but cannot be updated. */ static struct key_type key_type_cert_store_key = { .name = CERT_STORE_KEY_TYPE_NAME, + .vet_description = cert_store_key_vet_description, .preparse = user_preparse, .free_preparse = user_free_preparse, .instantiate = generic_key_instantiate, @@ -768,6 +783,7 @@ static ssize_t refresh_store(struct kobject *kobj, struct kobj_attribute *attr, if (rc) return rc; + WRITE_ONCE(cs_refresh_task, current); for (retries = 0; retries < DIAG_MAX_RETRIES; retries++) { /* Request certificates from certificate store. */ rc = fill_cs_keyring(); @@ -776,6 +792,7 @@ static ssize_t refresh_store(struct kobject *kobj, struct kobj_attribute *attr, if (rc != -EAGAIN) break; } + WRITE_ONCE(cs_refresh_task, NULL); cs_status_val = rc; mutex_unlock(&cs_refresh_lock); -- 2.53.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] s390/cert_store: Only allow the kernel to create cert_store_key keys 2026-11-23 10:23 ` [PATCH 2/2] s390/cert_store: Only allow the kernel to create cert_store_key keys Heiko Carstens @ 2026-11-23 13:43 ` Jarkko Sakkinen 0 siblings, 0 replies; 9+ messages in thread From: Jarkko Sakkinen @ 2026-11-23 13:43 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 23, 2026 at 11:23:24AM +0100, Heiko Carstens wrote: > From: Anastasia Eskova <anastasia.eskova@ibm.com> > > Keys of type cert_store_key can be created by any user with add_key() in > any keyring, as the key type has no vet_description() callback. The type > is registered whenever CONFIG_CERT_STORE is enabled, even if the machine > has no DIAG 320 support. > > cert_store_key_describe() expects a description in the format created by > get_key_description(), i.e. a 64 byte key name followed by the VCE index > and the certificate store token. If a key with a shorter description is > created, seq_puts() may read beyond the end of the description > allocation. Reading /proc/keys may then disclose adjacent kernel heap > memory to the user space. Also, a consumer which trusts keys by type can > be fooled by keys that were not created from the certificate store. > > Add a vet_description() callback which only accepts the task currently > executing refresh_store(), which creates all valid keys of this type. > > Fixes: 8cf57d7217c3 ("s390: add support for user-defined certificates") > Signed-off-by: Anastasia Eskova <anastasia.eskova@ibm.com> > Signed-off-by: Heiko Carstens <hca@linux.ibm.com> > --- > arch/s390/kernel/cert_store.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c > index 6f5c63cd907f..6e518ff38322 100644 > --- a/arch/s390/kernel/cert_store.c > +++ b/arch/s390/kernel/cert_store.c > @@ -46,6 +46,9 @@ > static debug_info_t *cert_store_dbf; > static debug_info_t *cert_store_hexdump; > > +/* Task currently running refresh_store(). Written under cs_refresh_lock. */ > +static struct task_struct *cs_refresh_task; > + > #define pr_dbf_msg(fmt, ...) \ > debug_sprintf_event(cert_store_dbf, 3, fmt "\n", ## __VA_ARGS__) > > @@ -148,12 +151,24 @@ static void cert_store_key_describe(const struct key *key, struct seq_file *m) > seq_printf(m, ": %u", key->datalen); > } > > +/* > + * Only the kernel may create keys of this type. Accept the task which runs > + * refresh_store(), as it cannot execute userspace during the refresh. > + */ > +static int cert_store_key_vet_description(const char *description) > +{ > + if (READ_ONCE(cs_refresh_task) != current) > + return -EPERM; > + return 0; > +} > + > /* > * Certificate store key type takes over properties of > * user key but cannot be updated. > */ > static struct key_type key_type_cert_store_key = { > .name = CERT_STORE_KEY_TYPE_NAME, > + .vet_description = cert_store_key_vet_description, > .preparse = user_preparse, > .free_preparse = user_free_preparse, > .instantiate = generic_key_instantiate, > @@ -768,6 +783,7 @@ static ssize_t refresh_store(struct kobject *kobj, struct kobj_attribute *attr, > if (rc) > return rc; > > + WRITE_ONCE(cs_refresh_task, current); > for (retries = 0; retries < DIAG_MAX_RETRIES; retries++) { > /* Request certificates from certificate store. */ > rc = fill_cs_keyring(); > @@ -776,6 +792,7 @@ static ssize_t refresh_store(struct kobject *kobj, struct kobj_attribute *attr, > if (rc != -EAGAIN) > break; > } > + WRITE_ONCE(cs_refresh_task, NULL); > cs_status_val = rc; > mutex_unlock(&cs_refresh_lock); > > -- > 2.53.0 > I can give this despite a bit out of context for me because I'm already somewhat familiar with the implementation overall: Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Br, Jarkko ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/2] s390/cert_store: Restrict link creation and key type creation 2026-11-23 10:23 [PATCH 0/2] s390/cert_store: Restrict link creation and key type creation Heiko Carstens 2026-11-23 10:23 ` [PATCH 1/2] s390/cert_store: Allocate keyring with link restriction Heiko Carstens 2026-11-23 10:23 ` [PATCH 2/2] s390/cert_store: Only allow the kernel to create cert_store_key keys Heiko Carstens @ 2026-11-23 10:31 ` sashiko-bot 2 siblings, 0 replies; 9+ messages in thread From: sashiko-bot @ 2026-11-23 10:31 UTC (permalink / raw) To: Heiko Carstens Cc: linux-s390, Vasily Gorbik, Alexander Gordeev, Christian Borntraeger Sashiko has reviewed this 2-patch series and found no issues. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261123102324.483917-1-hca@linux.ibm.com ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-23 14:20 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-23 10:23 [PATCH 0/2] s390/cert_store: Restrict link creation and key type creation Heiko Carstens 2026-11-23 10:23 ` [PATCH 1/2] s390/cert_store: Allocate keyring with link restriction Heiko Carstens 2026-11-23 13:42 ` Jarkko Sakkinen 2026-11-23 14:11 ` Heiko Carstens 2026-11-23 14:18 ` Jarkko Sakkinen 2026-11-23 14:20 ` Jarkko Sakkinen 2026-11-23 10:23 ` [PATCH 2/2] s390/cert_store: Only allow the kernel to create cert_store_key keys Heiko Carstens 2026-11-23 13:43 ` Jarkko Sakkinen 2026-11-23 10:31 ` [PATCH 0/2] s390/cert_store: Restrict link creation and key type creation sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox