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 v11 5/6] KEYS: Replace assoc_array with rhashtable
Date: Sat, 14 Nov 2026 17:04:15 +0000 (UTC)	[thread overview]
Message-ID: <a75e29128bdce3037d830cd6f269f27e01a680e943df2db427a12c99971bc8be@mail.kernel.org> (raw)
In-Reply-To: <20261114161211.376859-6-jarkko@kernel.org>

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

> KEYS: Replace assoc_array with rhashtable

TL;DR: Not a bug today, but the new keyring_read() comment says the semaphore
isn't needed; without it, a missed key could possibly leak uninitialized
kvmalloc() bytes to user space. Comment should say the read lock matters.

> 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)

This isn't a bug today, but is the new comment accurate about the
semaphore not being required?

keyring_read() writes serials while walking the list, and then computes the
returned length separately from the link count:

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

keyctl_read_key() kvmalloc()s key_data without zeroing it and copies back
exactly ret bytes when ret <= buflen:

    key_data = kvmalloc(key_data_len, GFP_KERNEL);
    ret = __keyctl_read_key(key, key_data, key_data_len);
    ...
    if (copy_to_user(buffer, key_data, ret))

Both callers of ->read, __keyctl_read_key() and read_sed_opal_key(), hold
down_read(&key->sem), and every writer of index->list and index->nr
(__key_link(), __key_unlink(), keyring_gc(), keyring_clear(),
keyring_revoke()) holds down_write() on the same semaphore, so the walk
always writes exactly nr serials.

Without the semaphore, a walk that misses a key, as the comment allows
(for example a link prepended with list_add_rcu() after the walk has passed
the head), would leave keyring_nr_links() larger than the number of serials
written.  Could the uninitialized tail of the kvmalloc() buffer then be
copied to user space?

The old comment described the requirement correctly.  Could the new comment
say that the caller's read lock on the semaphore is what keeps the returned
length consistent with the serials written?


---
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/43615900108

  reply	other threads:[~2026-11-14 17:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 16:12 [PATCH v11 0/6] KEYS: Replace assoc_array with Jarkko Sakkinen
2026-11-14 16:12 ` [PATCH v11 1/6] s390/cert_store: Pin the user session keyring Jarkko Sakkinen
2026-11-14 16:51   ` bot+bpf-ci
2026-11-14 16:12 ` [PATCH v11 2/6] s390/cert_store: Return an owned reference from find_cs_keyring() Jarkko Sakkinen
2026-11-14 16:51   ` bot+bpf-ci
2026-11-14 16:12 ` [PATCH v11 3/6] s390/cert_store: Skip keys that disappeared during invalidation Jarkko Sakkinen
2026-11-14 16:12 ` [PATCH v11 4/6] KEYS: Introduce keyring_is_empty() Jarkko Sakkinen
2026-11-14 16:12 ` [PATCH v11 5/6] KEYS: Replace assoc_array with rhashtable Jarkko Sakkinen
2026-11-14 17:04   ` bot+bpf-ci [this message]
2026-11-14 16:12 ` [PATCH v11 6/6] 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=a75e29128bdce3037d830cd6f269f27e01a680e943df2db427a12c99971bc8be@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®