From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev, Jarkko Sakkinen <jarkko@kernel.org>,
Cen Zhang <zzzccc427@gmail.com>,
David Howells <dhowells@redhat.com>
Subject: [PATCH 7.2 74/88] keys: Protect the read method check against type removal
Date: Wed, 28 Oct 2026 18:00:22 +0100 [thread overview]
Message-ID: <20261028165943.858015842@linuxfoundation.org> (raw)
In-Reply-To: <20261028165942.107695352@linuxfoundation.org>
7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <zzzccc427@gmail.com>
commit 925c84e3cc21caf09de92d9bcafab0147790debf upstream.
keyctl_read_key() checks key->type->read without holding key->sem.
A reference keeps the key alive, but does not pin the module containing
its type. A surviving RxRPC key can therefore be read while AF_RXRPC
is being unloaded:
KEYCTL_READ task Module unload and key GC
---------------- ------------------------
lookup_user_key()
permission / possession checks
load key->type
af_rxrpc_exit()
unregister_key_type()
GC: down_write(key->sem)
GC: retype to key_type_dead
GC: up_write(key->sem)
unregister_key_type() returns
free_module()
read saved type's read member
The final access can read freed module storage. The read invocation in
__keyctl_read_key() is already protected by key->sem, but the earlier
method check is outside that critical section.
Move the method check into __keyctl_read_key(), after key_validate() and
under its existing read hold on key->sem. The check and invocation then
use the same protected type for length queries and every read retry.
The GC cannot retype the key until the semaphore is released, and type
unregistration waits for that GC pass before the module can be freed.
Return -EOPNOTSUPP when validation succeeds and the type has no read
method. A temporary buffer may now be allocated before this result;
allocation and copying to userspace remain outside the semaphore.
Assisted-by: LLM
Cc: stable@vger.kernel.org # v5.10+
Fixes: d3ec10aa9581 ("KEYS: Don't write out to userspace while holding key semaphore")
Suggested-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Reviewed-by: David Howells <dhowells@redhat.com>
Link: https://lore.kernel.org/r/pm-key-management-objects-candidate-0010-v7-fc85721ff5cfb9e33ac6@gmail.com
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
security/keys/keyctl.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -808,8 +808,12 @@ static long __keyctl_read_key(struct key
down_read(&key->sem);
ret = key_validate(key);
- if (ret == 0)
- ret = key->type->read(key, buffer, buflen);
+ if (ret == 0) {
+ if (key->type->read)
+ ret = key->type->read(key, buffer, buflen);
+ else
+ ret = -EOPNOTSUPP;
+ }
up_read(&key->sem);
return ret;
}
@@ -863,11 +867,6 @@ long keyctl_read_key(key_serial_t keyid,
/* the key is probably readable - now try to read it */
can_read_key:
- if (!key->type->read) {
- ret = -EOPNOTSUPP;
- goto key_put_out;
- }
-
if (!buffer || !buflen) {
/* Get the key length from the read method */
ret = __keyctl_read_key(key, NULL, 0);
next prev parent reply other threads:[~2026-10-28 17:10 UTC|newest]
Thread overview: 97+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 16:59 [PATCH 7.2 00/88] 7.2.14-rc1 review Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 01/88] sched_ext: Wait for SCX_OPSS_DISPATCHING before moving tasks off DSQs Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 02/88] ntfs: fix race between fallocate and mmap reads Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 03/88] ntfs: take invalidate_lock in ntfs_filemap_page_mkwrite() Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 04/88] mm/damon/core: error damos_commit_quota_goal() for zero target_value Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 05/88] sched/fair: Avoid overflow in place_entity() Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 06/88] Bluetooth: L2CAP: refuse __l2cap_chan_add if chan already has conn Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 07/88] tools/dma: fix building with O= Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 08/88] tracing: Hold trace_types_lock when updating modules in persistent instances Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 09/88] tracing: Hold trace_types_lock when resetting last boot data from readers Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 10/88] tracing: Reject incomplete event filter expressions Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 11/88] tracing: Save the event file instead of the compatible histogram Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 12/88] tracing: Unregister field variable histograms when the command fails Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 13/88] tracing: Fix 64-bit and signed histogram fields on 32-bit kernels Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 14/88] tracing/histograms: Verify event_call identity when updating synth_event refcount Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 15/88] tracing/syscalls: Use copy_from_user for the faultable syscall buffer Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 16/88] io-wq: order the exit bit against worker creation task work Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 17/88] io_uring/waitid: own the request before clearing ->head Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 18/88] io_uring/cmd: dont leave list poison in ->hash_node Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 19/88] io_uring/wait: dont spin on a stuck overflow list Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 20/88] io_uring/io-wq: dont lose the signal that ends work Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 21/88] io_uring/io-wq: dont hide a link from cancellations Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 22/88] io_uring: dont flood a cancelling task with task_work Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 23/88] io_uring: dont lose the DEFER_TASKRUN wake up Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 24/88] io_uring/cancel: rearm local work wake up before sleep Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 25/88] io_uring/mpscq: disable preemption while pushing Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 26/88] io_uring/io-wq: dont go to sleep on pending work Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 27/88] io_uring/io-wq: dont strand work when a worker exits Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 28/88] io_uring/io-wq: dont exit with a creation pending Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 29/88] io_uring/io-wq: let cancel find picked up hashed work Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 30/88] io_uring/poll: dont lose a cancel as io-wq arms poll Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 31/88] io_uring: dont lose a cancel as io-wq parks a request Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 32/88] io_uring/cancel: dont forget that the work was running Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 33/88] io_uring/cancel: recognize "no timeout" on 32-bit Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 34/88] io_uring/cancel: let CANCEL_ALL find parked requests Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 35/88] io_uring: wake ring pollers for local task_work Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 36/88] io_uring/wait: look at all CQ waiters on wake up Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 37/88] io_uring/poll: drop stale double poll entry on rearm Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 38/88] io_uring/futex: allocate private hash before waiting Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 39/88] io_uring: drop the CQE cache if a refill fails Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 40/88] io_uring: dont split 128b SQEs at the SQPOLL cap Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 41/88] io_uring/register: dont wrap 32b CQEs when resizing Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 42/88] io_uring/register: handle index wrap " Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 43/88] io_uring/register: keep 128b SQEs intact on resize Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 44/88] io_uring/fdinfo: fix CQE dump of CQE32 rings Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 45/88] io_uring/timeout: dont skip over reached sequences Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 46/88] io_uring/timeout: keep repeat count on multishot update Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 47/88] io_uring/timeout: use the right clock for ABS updates Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 48/88] io_uring/wait: no early -ETIME if min_wait finds work Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 49/88] io_uring/napi: make stale entries time out after 60s Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 50/88] io_uring/napi: dont busy poll past an expired timeout Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 51/88] io_uring/zcrx: fix buffer offsets in areas above 4GB Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 52/88] io_uring/kbuf: handle index wrap in last buffer check Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 53/88] io_uring/sqpoll: let the thread sleep on disabled rings Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 54/88] io_uring/openclose: keep the lock in io_pipe_fixed() Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 55/88] io_uring: dont pass restart error codes to userspace Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 56/88] io_uring/net: dont retry recv on uncommitted buffers Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 57/88] io_uring/timeout: no ABS update of multishot timeouts Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 58/88] io_uring/timeout: dont end a linked timeout with 1 Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 59/88] io_uring: look up the file before queueing to io-wq Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 60/88] io_uring/poll: avoid retry wakeup loss when dropping ownership Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 61/88] io_uring/timeout: dont put a sequence target behind the last flush Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 62/88] io_uring/timeout: dont flush with the sequence " Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 63/88] io_uring/timeout: dont lose a cancel as io-wq arms a timeout Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 64/88] io_uring/poll: dont loop on HUP with multiple references Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 65/88] io_uring/net: keep recv buffer select length within MAX_RW_COUNT Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 66/88] io_uring/wait: wake real-time waiters from hard interrupt context Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 67/88] io_uring/waitid: prevent cancel reference wrap Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 68/88] io_uring: end the drain when the drain request completes Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 69/88] io_uring: keep the drain active when a deferred drain request is started Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 70/88] keys: Avoid the owner account dereference in named keyring lookup Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 71/88] keys: Check the authorization payload in process keyring searches Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 72/88] keys: Protect the type name while describing a key Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 73/88] keys: make keyring indexes independent of kernel addresses Greg Kroah-Hartman
2026-10-28 17:00 ` Greg Kroah-Hartman [this message]
2026-10-28 17:00 ` [PATCH 7.2 75/88] KEYS: Fix key_reject_and_link() race with keyring restriction Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 76/88] KEYS: trusted: Fix blob allocation size in tpm2_key_decode() Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 77/88] keys/trusted_keys: return immediately after TPM unseal failure Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 78/88] asymmetric_keys: reject trust keys without IDs Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 79/88] ftrace: Initialize modname and offset in print_rec() Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 80/88] coredump: hold RCU while releasing parked threads Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 81/88] signal: only SIGKILL and the freezers interrupt a coredumping task Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 82/88] signal: dont retarget shared signals in a dying thread group Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 83/88] ptrace: refuse to change the signal mask of a user worker Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 84/88] fork: release the files of a failed fork after sched_cancel_fork() Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 85/88] exit: hang up the tty before closing the files Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 86/88] coredump: prevent TIF_NOTIFY_SIGNAL from interrupting coredumps Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 87/88] pid_namespace: prevent TIF_NOTIFY_SIGNAL from interrupting the reaper Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 88/88] signal: allow taks to temporarily block TIF_NOTIFY_SIGNAL Greg Kroah-Hartman
2026-10-28 19:39 ` [PATCH 7.2 00/88] 7.2.14-rc1 review Brett A C Sheffield
2026-10-29 4:09 ` Peter Schneider
2026-10-29 10:08 ` Pavel Machek
2026-10-29 13:49 ` Miguel Ojeda
2026-10-29 14:17 ` Ron Economos
2026-10-29 14:43 ` SJ Park
2026-10-29 15:19 ` Shuah Khan
2026-10-29 15:57 ` Barry K. Nathan
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=20261028165943.858015842@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=dhowells@redhat.com \
--cc=jarkko@kernel.org \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=zzzccc427@gmail.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