From: David Howells <dhowells@redhat.com>
To: Jarkko Sakkinen <jarkko@kernel.org>
Cc: dhowells@redhat.com, keyrings@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Paul Moore <paul@paul-moore.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
linux-kernel@vger.kernel.org (open list),
linux-security-module@vger.kernel.org (open list:SECURITY
SUBSYSTEM)
Subject: Re: [RFC PATCH 5/6] KEYS: Replace assoc_array with struct keyring_index
Date: Mon, 19 Oct 2026 16:02:48 +0100 [thread overview]
Message-ID: <2608630.1792422168@warthog.procyon.org.uk> (raw)
In-Reply-To: <20261016215326.4110064-6-jarkko@kernel.org>
Jarkko Sakkinen <jarkko@kernel.org> wrote:
> Maintain two linked lists in the index:
>
> - all: enumerate committed links without retrying hash table walks when
> the table resizes.
> - keyrings: visit nested keyrings during recursive search without scanning
> links to other key types.
Do you actually need two lists? Can you just "sort" the list to put all the
keyrings first?
> + struct keyring_index __rcu *links;
Does that actually need an __rcu mark? Is it going to get replaced once
allocated?
> +struct keyring_link;
> +
Somewhere near the top of internal.h, please, not sandwiched in the middle of
some func declarations.
> --- a/security/keys/keyring.c
> +++ b/security/keys/keyring.c
> @@ -14,12 +14,12 @@
> #include <linux/err.h>
> #include <linux/user_namespace.h>
> #include <linux/nsproxy.h>
> +#include <keys/keyring-type.h>
> +#include <keys/user-type.h>
Why #include user-type.h here?
> +struct keyring_index {
> + struct rhashtable ht;
> + struct list_head all;
> + struct list_head keyrings;
> + unsigned long nr; /* Number of committed links */
Given key->serial is 1-INT_MAX, nr probably doesn't need to be unsigned long -
otoh, it's not likely to leave a hole, I guess.
> +struct keyring_link {
I wonder if keyring_entry would be a better name, but the docs do mention
making and removing links.
> + unsigned long hash;
> ...
> + struct rcu_head rcu;
Can they be in a union? And I would put rcu first as I think there are (or
maybe used to be) some things that required it to be first.
> + struct list_head keyrings_link; /* in keyring_index::keyrings */
This may be unnecessary if you can put keyrings at the front of the list.
> + struct keyring_link *replaces; /* Link this one replaces, or NULL */
Please don't put this in keyring_link. It's only needed by __key_link() and
friends and could be passed around in a context struct as the edit script is
done now:
struct keyring_link_context {
struct keyring_link *spare; /* Spare link block */
struct keyring_link *replace; /* Link being replaced */
};
then:
int __key_link_begin(struct key *keyring,
const struct keyring_index_key *index_key,
- struct assoc_array_edit **_edit)
+ struct keyring_link_context **_edit)
> +/*
> + * Remove every link from a keyring. The caller holds keyring->sem
> + * write-locked. A concurrent RCU reader can see some of the links gone and
> + * others not yet.
> + */
> +static void keyring_remove_all_links(struct key *keyring)
> +{
> + struct keyring_index *links = keyring_index_locked(keyring);
> + struct keyring_link *link, *tmp;
> +
> + if (!links)
> + return;
> + list_for_each_entry_safe(link, tmp, &links->all, all_link)
> + keyring_remove_link(links, link);
> }
> ...
> int keyring_clear(struct key *keyring)
> {
> ...
> + keyring_remove_all_links(keyring);
This can be made atomic by replacing the key->links pointer value with NULL
(since key->links is marked __rcu), then destroying the content afterwards.
David
next prev parent reply other threads:[~2026-10-19 15:02 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 21:52 [RFC PATCH 0/6] KEYS: From assoc_array to rhashtable migration Jarkko Sakkinen
2026-10-16 21:52 ` [RFC PATCH 1/6] keys: prevent quota overflow and widen quotalen and datalen to 32 bits Jarkko Sakkinen
2026-10-17 5:28 ` Eric Biggers
2026-10-17 16:48 ` Jarkko Sakkinen
2026-10-16 21:53 ` [RFC PATCH 2/6] keys: reclaim link quota during keyring garbage collection Jarkko Sakkinen
2026-10-17 5:42 ` Eric Biggers
2026-10-17 17:06 ` Jarkko Sakkinen
2026-10-16 21:53 ` [RFC PATCH 3/6] keys: verify key identity on unlink and move Jarkko Sakkinen
2026-10-16 21:53 ` [RFC PATCH 4/6] keys: Add keyring_is_empty() for {fs,dm}-verity Jarkko Sakkinen
2026-10-16 21:53 ` [RFC PATCH 5/6] KEYS: Replace assoc_array with struct keyring_index Jarkko Sakkinen
2026-10-16 22:27 ` Jarkko Sakkinen
2026-10-18 7:08 ` Eric Biggers
2026-10-18 15:09 ` Jarkko Sakkinen
2026-10-18 15:12 ` Jarkko Sakkinen
2026-10-19 15:02 ` David Howells [this message]
2026-10-19 15:27 ` Jarkko Sakkinen
2026-10-16 21:53 ` [RFC PATCH 6/6] lib: Remove unused assoc_array Jarkko Sakkinen
2026-10-19 21:46 ` David Howells
2026-10-19 21:50 ` Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2608630.1792422168@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=jarkko@kernel.org \
--cc=jmorris@namei.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.