Skip to content

keys: Fix ownership lifetime and accounting races

Chengfeng Ye keyrings linux-security-module lkml stable 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v3 Latest2 patches 7 repliesIn review

Changes in v3 from the cover letter

- Split v2 into a lifetime fix and an accounting-serialization fix.
- Rebase onto fd179f8a05be (current mainline at preparation time).
- Include a short, explicitly historical instrumented KASAN excerpt in patch 1, and add stable trailers for these long-standing bugs.
- Keep explicit lock acquisition at each reader; no locking accessor.

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2keys: Protect key_user lifetime during ownership changessecurity/keys/key.c security/keys/keyctl.c security/keys/keyring.c +1 more+32 -52 replies
2/2keys: Serialize ownership transfers with key accountingsecurity/keys/key.c security/keys/keyctl.c+6 -45 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchJarkko Sakkinen
1/2R-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/2] keys: Fix ownership lifetime and accounting races

This series splits the previous bundled fix into two logical changes, as requested by Jarkko.

Patch 1 protects key_user lifetime while key->user is replaced. It covers namespace filtering, quota reservation and instantiated-key count updates, with explicit locking at the affected access sites.

Patch 2 depends on patch 1 and extends the same critical sections so that quota and instantiated-key accounting move together with ownership. Notifications and reference release remain outside the spinlock.

The combined code change is identical to v2 applied to the current base. Patch 1 fixes the lifetime race; the existing accounting races remain until patch 2 is applied. Each commit has its own explanation and interleaving.

Changes in v3:
- Split v2 into a lifetime fix and an accounting-serialization fix.
- Rebase onto fd179f8a05be (current mainline at preparation time).
- Include a short, explicitly historical instrumented KASAN excerpt in patch 1, and add stable trailers for these long-standing bugs.
- Keep explicit lock acquisition at each reader; no locking accessor.

Validation:
- Built the four affected objects after each patch.
- Built the full x86_64 kernel after applying both patches, with KEYS, PROC_FS, USER_NS, WATCH_QUEUE and KEY_NOTIFICATIONS enabled.
- Both patches pass checkpatch --strict without errors or warnings.

Previous version:
https://lore.kernel.org/r/[email protected]/
Reviewer request:
https://lore.kernel.org/r/[email protected]/

Chengfeng Ye (2):
keys: Protect key_user lifetime during ownership changes
keys: Serialize ownership transfers with key accounting

 security/keys/key.c     | 13 +++++++++++--
 security/keys/keyctl.c  |  4 ++++
 security/keys/keyring.c |  7 ++++++-
 security/keys/proc.c    | 15 +++++++++++++--
 4 files changed, 34 insertions(+), 5 deletions(-)

base-commit: fd179f8a05be3ccae366b9b96e176b51fbe54aab

Signature · 1 line
2.43.0