A crash while softhsm2-util --import rewrites token.object leaves it empty, and the token with every key in it unreadable

Aperta
#908 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
databases

Direzione di ricerca

Start in src/lib/object_store/ObjectFile.cpp at ObjectFile::writeAttributes and trace how file-backend writes persist token.object; the report reproduces the failure by killing the write after truncation. Check existing tests for object-store writes and add coverage showing an interrupted rewrite leaves either the old or new content intact. Done when the token remains readable after an interrupted softhsm2-util --import rewrite.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

With the file backend, ObjectFile::writeAttributes truncates an object file and then writes it (src/lib/object_store/ObjectFile.cpp, unchanged on main at 9ad87341c9). softhsm2-util --import rewrites the token's own token.object this way. If the process is killed between the truncation and the write, token.object is left at 0 bytes, and the token disappears from its slot. The keys already in it are lost with it: their object files are still on disk, but token.object held the SO and user PIN blobs SoftHSM unwraps their key from.

To reproduce (SoftHSM 2.6.1, Debian 13 arm64):

export SOFTHSM2_CONF=$PWD/softhsm2.conf
mkdir tokens
printf 'directories.tokendir = %s/tokens\nobjectstore.backend = file\n' "$PWD" > softhsm2.conf
softhsm2-util --init-token --free --label t --pin 1234 --so-pin 5678
openssl genpkey -algorithm RSA -out k1.pem; openssl genpkey -algorithm RSA -out k2.pem
softhsm2-util --import k1.pem --token t --pin 1234 --label k1 --id 01
tok=$(ls -d tokens/*/)
strace -f -qq -P "$PWD/${tok}token.object" -e inject=write:signal=KILL \
  softhsm2-util --import k2.pem --token t --pin 1234 --label k2 --id 02
ls -l "$tok"; softhsm2-util --show-slots

strace shows ftruncate(3, 0) on token.object and the kill at the write that follows. Afterwards token.object is 0 bytes, --show-slots lists the slot with an empty label, and pkcs11-tool --token-label t --login --pin 1234 --list-objects answers No slot with token named "t" found, while k1's object file is still in the directory.

Expected: token.object holds its old content or its new content.

Found with Sideeye, a personal open-source tool, no commercial interest; say if you would rather not have such reports. Not measured: power loss, the database backend, and which other operations rewrite token.object.

Lingua principale
C++
Stelle
1.1k
Fork
434
Merge medio
12g 14h
PR unite (30g)
2

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di softhsm/SoftHSMv2

Tutte le issue di softhsm/SoftHSMv2

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.