I’m working on getting key_type_dead wiped off from Linux.
This changes behavior from rmmod always succeeding into returning -EBUSY if callers have the LKM pinned, which is what any normal LKM does.
So while this would be so much better it might require tweaks to the user space. I have no idea. I will test the changes with SystemD at least, which I already have as part of my regular kernel test image.
This will be bundled into keyring GC sanitization patch set that I’ll send later today. It also includes a patch that amortizes work items into 64 key chunks in order to resolve workqueue lockups (with only ~2% added to the time taken by serial tree traversal).
EDIT:
v2: https://lore.kernel.org/keyrings/20261103030226.2685251-1-jarkko@kernel.org/