Skip to content

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

Open
gerald-yang-tw wants to merge 1 commit into
canonical:mainfrom
gerald-yang-tw:main
Open

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

Conversation

@gerald-yang-tw

Copy link
Copy Markdown

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
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

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.

1 participant