]> git.ipfire.org Git - thirdparty/systemd.git/commit
homework-luks: add new key slots before destroying old ones
authorLuca Boccassi <luca.boccassi@gmail.com>
Thu, 9 Jul 2026 14:07:54 +0000 (15:07 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 14 Jul 2026 15:57:14 +0000 (16:57 +0100)
commit41fc062c491ebdc0e5ccce8da1669f31d48e970a
tree311bcc21eb63859b2622d9611efb37e487f49d33
parent39fa094b0d958b2d6c0dcd55377eb2b22370df48
homework-luks: add new key slots before destroying old ones

home_passwd_luks() rotates the LUKS key slots with a single loop that
destroys slot i before adding its replacement at the same index. If
adding the replacement fails (e.g.: argon2 OOMs), slot i is left
destroyed with no replacement and no rollback. If the user has only
one password, its only key slot is now gone and the home directory can
no longer be unlocked.

Rotate in two passes instead: first add every new password into a free
slot (CRYPT_ANY_SLOT), and only once all adds succeed, destroy the old
slots. If an add fails, roll back the slots added so far and return
with the pre-existing slots untouched, so at least one valid key slot
always remains for each password the user holds.

Follow-up for 70a5db5822c8056b53d9a4a9273ad12cb5f87a92
src/home/homework-luks.c