Skip to content

Pin goroutine to OS thread when reading the primary key - #165

Merged
julian-klode merged 1 commit into
canonical:mainfrom
gerald-yang-tw:main
Aug 25, 2026
Merged

Pin goroutine to OS thread when reading the primary key#165
julian-klode merged 1 commit into
canonical:mainfrom
gerald-yang-tw:main

Conversation

@gerald-yang-tw

Copy link
Copy Markdown
Contributor

The keyring links established by KEYCTL_LINK are per-thread, but Go may reschedule the goroutine onto a different OS thread between the link and the subsequent key read, making the read intermittently fail with permission denied:
final reseal failed: cannot obtain auth key from kernel: cannot read key from kernel: cannot determine size of key payload: permission denied

Wrap the link and read in runtime.LockOSThread()/UnlockOSThread() so both syscalls run on the same thread.

The keyring links established by KEYCTL_LINK are per-thread, but Go
may reschedule the goroutine onto a different OS thread between the
link and the subsequent key read, making the read intermittently
fail with permission denied:
final reseal failed: cannot obtain auth key from kernel: cannot read key from kernel: cannot determine size of key payload: permission denied

Wrap the link and read in runtime.LockOSThread()/UnlockOSThread() so
both syscalls run on the same thread.

Signed-off-by: Gerald Yang <gerald.yang@canonical.com>
@gerald-yang-tw

gerald-yang-tw commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

This issue can be reproduced on a azure CVM instance by running the following script:

#!/bin/bash

for i in {1..100}; do
if ! sudo apt reinstall nullboot; then
echo " ##### ITERATION #$i #####"
echo "reproduced the issue"
exit 1
fi
echo " ##### ITERATION #$i #####"
done

@frederic-hoerni
frederic-hoerni self-requested a review August 25, 2026 06:38
@julian-klode
julian-klode merged commit 5ea1aea into canonical:main Aug 25, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants