mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: jarkko@kernel.org,dhowells@redhat.com
Cc: jarkko@kernel.org,bpf@vger.kernel.org,dm-devel@lists.linux.dev,fsverity@lists.linux.dev,keyrings@vger.kernel.org,linux-doc@vger.kernel.org,linux-kernel@vger.kernel.org,linux-kselftest@vger.kernel.org,linux-security-module@vger.kernel.org,agk@redhat.com,agordeev@linux.ibm.com,ast@kernel.org,alexs@kernel.org,anastasia.eskova@ibm.com,akpm@linux-foundation.org,andrii@kernel.org,bmarzins@redhat.com,borntraeger@linux.ibm.com,daniel@iogearbox.net,dzm91@hust.edu.cn,eddyz87@gmail.com,emil@etsalapatis.com,ebiggers@kernel.org,ignat@linux.win,hca@linux.ibm.com,ihor.solodrai@linux.dev,James.Bottomley@HansenPartnership.com,jmorris@namei.org,jolsa@kernel.org,corbet@lwn.net,memxor@gmail.com,torvalds@linux-foundation.org,martin.lau@linux.dev,snitzer@kernel.org,mpatocka@redhat.com,zohar@linux.ibm.com,paul@paul-moore.com,oberpar@linux.ibm.com,rdunlap@infradead.org,roberto.sassu@huawei.com,serge@hallyn.com,skhan@linuxfoundation.org,song@kernel.org,svens@linux.ibm.com,tytso@mit.edu,gor@linux.ibm.com,
	si.yanteng@linux.dev,yonghong.song@linux.dev,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH v13 6/7] KEYS: Replace assoc_array with rhashtable
Date: Sat, 14 Nov 2026 20:24:27 +0000 (UTC)	[thread overview]
Message-ID: <717a43d830b7a6544a51f3c227592eaadcd0afcf61ec9bf922ad517a280b8bfe@mail.kernel.org> (raw)
In-Reply-To: <20261114193631.731615-7-jarkko@kernel.org>

[-- Attachment #1: Type: text/plain, Size: 2819 bytes --]

> KEYS: Replace assoc_array with rhashtable

TL;DR: Comment only, not a bug today: the new keyring_read() comment says no
semaphore is needed and concurrent changes are possible, but the caller's
semaphore prevents that. Suggests rewording it.

> diff --git a/security/keys/keyring.c b/security/keys/keyring.c
> --- a/security/keys/keyring.c
> +++ b/security/keys/keyring.c

[ ... ]

>  /*
>   * Read a list of key IDs from the keyring's contents in binary form
>   *
> - * The keyring's semaphore is read-locked by the caller.  This prevents someone
> - * from modifying it under us - which could cause us to read key IDs multiple
> - * times.
> + * The walk is RCU-protected, so the keyring's semaphore is not required.  A
> + * keyring modified concurrently may list a key twice or miss one, but it can
> + * never have a link freed under the walk.
>   */
>  static long keyring_read(const struct key *keyring,
>  			 char *buffer, size_t buflen)

[ ... ]

> +		ret = keyring_iterate(keyring, keyring_read_iterator, &ctx);
> +		if (ret < 0)
>  			return ret;

[ ... ]

This isn't a bug today, but the new comment looks inaccurate.  It says the
keyring's semaphore is not required and that a concurrent modification may
list a key twice or miss one.

keyring_read() walks the list under RCU, but the length it returns is
computed separately afterwards:

    ret = keyring_iterate(keyring, keyring_read_iterator, &ctx);
    ...
    ret = keyring_nr_links(keyring) * sizeof(key_serial_t);

keyctl_read_key() allocates key_data with kvmalloc(), which is not zeroed,
and when the returned length is <= buflen it does:

    ret = __keyctl_read_key(key, key_data, key_data_len);
    if (ret <= 0 || ret > buflen)
        break;
    ...
    if (copy_to_user(buffer, key_data, ret))

If a link were added between the walk and keyring_nr_links(), ret would
cover more entries than were written, and the extra uninitialised bytes
would be copied to userspace.

Today this can't happen, because __keyctl_read_key() does
down_read(&key->sem) (as does the s390 invalidate_keyring_keys()), and every
writer of index->list and index->nr (__key_link_lock(), __key_move_lock(),
__key_unlink_lock(), keyring_clear(), keyring_gc(), and key_revoke() via
keyring_revoke()) holds the semaphore for write.  So the concurrent
modification described by the comment does not occur.

Could the comment instead say that the caller holds the keyring's semaphore,
which keeps the list and the link count stable across the walk and the
length calculation, with RCU only keeping the walk itself memory-safe?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/43634583011

  reply	other threads:[~2026-11-14 20:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 19:36 [PATCH v13 0/7] " Jarkko Sakkinen
2026-11-14 19:36 ` [PATCH v13 1/7] s390/cert_store: Pin the user session keyring Jarkko Sakkinen
2026-11-14 19:36 ` [PATCH v13 2/7] s390/cert_store: Return an owned reference from find_cs_keyring() Jarkko Sakkinen
2026-11-14 19:36 ` [PATCH v13 3/7] s390/cert_store: Skip keys that disappeared during invalidation Jarkko Sakkinen
2026-11-14 19:36 ` [PATCH v13 4/7] s390/cert_store: Read-lock keyring semaphore in invalidate_keyring_keys() Jarkko Sakkinen
2026-11-14 19:36 ` [PATCH v13 5/7] KEYS: Introduce keyring_is_empty() Jarkko Sakkinen
2026-11-14 19:36 ` [PATCH v13 6/7] KEYS: Replace assoc_array with rhashtable Jarkko Sakkinen
2026-11-14 20:24   ` bot+bpf-ci [this message]
2026-11-14 20:38     ` Jarkko Sakkinen
2026-11-14 19:36 ` [PATCH v13 7/7] lib: Remove 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=717a43d830b7a6544a51f3c227592eaadcd0afcf61ec9bf922ad517a280b8bfe@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=agk@redhat.com \
    --cc=agordeev@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexs@kernel.org \
    --cc=anastasia.eskova@ibm.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bmarzins@redhat.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=corbet@lwn.net \
    --cc=daniel@iogearbox.net \
    --cc=dhowells@redhat.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=dzm91@hust.edu.cn \
    --cc=ebiggers@kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=fsverity@lists.linux.dev \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=ignat@linux.win \
    --cc=ihor.solodrai@linux.dev \
    --cc=jarkko@kernel.org \
    --cc=jmorris@namei.org \
    --cc=jolsa@kernel.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --cc=memxor@gmail.com \
    --cc=mpatocka@redhat.com \
    --cc=oberpar@linux.ibm.com \
    --cc=paul@paul-moore.com \
    --cc=rdunlap@infradead.org \
    --cc=roberto.sassu@huawei.com \
    --cc=serge@hallyn.com \
    --cc=si.yanteng@linux.dev \
    --cc=skhan@linuxfoundation.org \
    --cc=snitzer@kernel.org \
    --cc=song@kernel.org \
    --cc=svens@linux.ibm.com \
    --cc=torvalds@linux-foundation.org \
    --cc=tytso@mit.edu \
    --cc=yonghong.song@linux.dev \
    --cc=zohar@linux.ibm.com \
    /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®