Re: [PATCH v4 1/2] KEYS: Return user session keyring on lookup

From: Guicai Ma

Date: Fri Nov 27 2026 - 21:11:30 EST


On Fri, Nov 27, 2026 at 02:14:31PM +0200, Jarkko Sakkinen wrote:
> A process without a session keyring looking up KEY_SPEC_SESSION_KEYRING
> without KEY_LOOKUP_CREATE mutates the credentials. This causes struct creds
> instances shared with other subsystems to become stale.
>
> Address this by returning the resolved user session keyring directly
> without installing it into credentials.

Tested on jarkko/for-next-keys (aa9e16503df9) in an arm64/KVM guest with
KASAN and lockdep. With a small module calling
lookup_user_key(KEY_SPEC_SESSION_KEYRING, 0, KEY_NEED_SEARCH) under
override_creds(), the unpatched kernel hits the BUG at kernel/cred.c:376
and the patched one returns the user session keyring without setting
cred->session_keyring.

Userspace checks for KEYCTL_GET_KEYRING_ID (create=0 and 1) and
KEYCTL_SESSION_TO_PARENT (shared NULL and non-NULL session keyrings)
also pass cleanly.

Reviewed-by: Guicai Ma <maguicai@xxxxxxxxxx>
Tested-by: Guicai Ma <maguicai@xxxxxxxxxx>