From: Jarkko Sakkinen <jarkko@kernel.org>
To: David Howells <dhowells@redhat.com>
Cc: keyrings@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Jarkko Sakkinen <jarkko@kernel.org>,
Alasdair Kergon <agk@redhat.com>,
Mike Snitzer <snitzer@kernel.org>,
Mikulas Patocka <mpatocka@redhat.com>,
Benjamin Marzinski <bmarzins@redhat.com>,
Eric Biggers <ebiggers@kernel.org>,
"Theodore Y. Ts'o" <tytso@mit.edu>,
Paul Moore <paul@paul-moore.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
Shuah Khan <shuah@kernel.org>,
Christian Brauner <brauner@kernel.org>,
dm-devel@lists.linux.dev (open list:DEVICE-MAPPER (LVM)),
linux-kernel@vger.kernel.org (open list),
fsverity@lists.linux.dev (open list:FSVERITY: READ-ONLY
FILE-BASED AUTHENTICITY PRO...),
linux-security-module@vger.kernel.org (open list:SECURITY
SUBSYSTEM),
linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST
FRAMEWORK)
Subject: [RFC PATCH 4/6] keys: Add keyring_is_empty() for {fs,dm}-verity
Date: Sat, 17 Oct 2026 00:53:02 +0300 [thread overview]
Message-ID: <20261016215326.4110064-5-jarkko@kernel.org> (raw)
In-Reply-To: <20261016215326.4110064-1-jarkko@kernel.org>
fs-verity and dm-verity read assoc_array's nr_leaves_on_tree directly to
check whether a keyring is empty.
Add keyring_is_empty() and use it in the both callers.
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
drivers/md/dm-verity-verify-sig.c | 2 +-
fs/verity/signature.c | 2 +-
include/linux/key.h | 1 +
security/keys/keyring.c | 10 ++++++++++
.../selftests/dm-verity/test-dm-verity-keyring.sh | 2 +-
5 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/drivers/md/dm-verity-verify-sig.c b/drivers/md/dm-verity-verify-sig.c
index b2b55c41e2cb..2ccb71bfb3ca 100644
--- a/drivers/md/dm-verity-verify-sig.c
+++ b/drivers/md/dm-verity-verify-sig.c
@@ -153,7 +153,7 @@ int verity_verify_root_hash(const void *root_hash, size_t root_hash_len,
if (ret != -ENOKEY && ret != -EKEYREJECTED)
return ret;
- if (dm_verity_keyring->keys.nr_leaves_on_tree &&
+ if (!keyring_is_empty(dm_verity_keyring) &&
dm_verity_keyring->restrict_link)
ret = verify_pkcs7_signature(root_hash, root_hash_len,
sig_data, sig_len,
diff --git a/fs/verity/signature.c b/fs/verity/signature.c
index 0302a4e506ec..890d33b9d812 100644
--- a/fs/verity/signature.c
+++ b/fs/verity/signature.c
@@ -67,7 +67,7 @@ int fsverity_verify_signature(const struct fsverity_info *vi,
return 0;
}
- if (fsverity_keyring->keys.nr_leaves_on_tree == 0) {
+ if (keyring_is_empty(fsverity_keyring)) {
/*
* The ".fs-verity" keyring is empty, due to builtin signatures
* being supported by the kernel but not actually being used.
diff --git a/include/linux/key.h b/include/linux/key.h
index 26139c3adf62..d82253b06c54 100644
--- a/include/linux/key.h
+++ b/include/linux/key.h
@@ -436,6 +436,7 @@ extern int restrict_link_reject(struct key *keyring,
struct key *restriction_key);
extern int keyring_clear(struct key *keyring);
+bool keyring_is_empty(const struct key *keyring);
extern key_ref_t keyring_search(key_ref_t keyring,
struct key_type *type,
diff --git a/security/keys/keyring.c b/security/keys/keyring.c
index 9ccce0db0665..613d1db41611 100644
--- a/security/keys/keyring.c
+++ b/security/keys/keyring.c
@@ -443,6 +443,16 @@ static void keyring_destroy(struct key *keyring)
assoc_array_destroy(&keyring->keys, &keyring_assoc_array_ops);
}
+/**
+ * keyring_is_empty - Check whether a keyring contains any links
+ * @keyring: The keyring to check.
+ */
+bool keyring_is_empty(const struct key *keyring)
+{
+ return READ_ONCE(keyring->keys.nr_leaves_on_tree) == 0;
+}
+EXPORT_SYMBOL(keyring_is_empty);
+
/*
* Describe a keyring for /proc.
*/
diff --git a/tools/testing/selftests/dm-verity/test-dm-verity-keyring.sh b/tools/testing/selftests/dm-verity/test-dm-verity-keyring.sh
index 1f9601ef22f8..792449d356cf 100755
--- a/tools/testing/selftests/dm-verity/test-dm-verity-keyring.sh
+++ b/tools/testing/selftests/dm-verity/test-dm-verity-keyring.sh
@@ -746,7 +746,7 @@ test_keyring_inactive_when_empty() {
log_info "TEST: Verify dm-verity keyring is inactive when sealed empty"
# When keyring_unsealed=0, the keyring is sealed immediately while empty
- # This means it should NOT be used for verification (nr_leaves_on_tree=0)
+ # An empty keyring should NOT be used for verification.
log_info "Keyring state (should be empty and sealed):"
list_keyring_keys
--
2.47.3
next prev parent reply other threads:[~2026-10-16 21:54 UTC|newest]
Thread overview: 10+ 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-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-16 21:53 ` [RFC PATCH 3/6] keys: verify key identity on unlink and move Jarkko Sakkinen
2026-10-16 21:53 ` Jarkko Sakkinen [this message]
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-16 21:53 ` [RFC PATCH 6/6] lib: Remove unused assoc_array 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=20261016215326.4110064-5-jarkko@kernel.org \
--to=jarkko@kernel.org \
--cc=agk@redhat.com \
--cc=bmarzins@redhat.com \
--cc=brauner@kernel.org \
--cc=dhowells@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=ebiggers@kernel.org \
--cc=fsverity@lists.linux.dev \
--cc=jmorris@namei.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
--cc=shuah@kernel.org \
--cc=snitzer@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®