pcrextend,tpm2-util,tpm2-setup: gracefully skip NvPCR when TPM NV space is exhausted

Map TPM2_RC_NV_SPACE to -ENOBUFS in tpm2_define_nvpcr_nv_index() rather
than -ENOSPC, giving it a dedicated errno distinct from the -ENOSPC that
write_string_file_at() can return when /run is full — a different failure
that occurs after the NV index is already allocated on the TPM.

In extend_nvpcr_now(), propagate -ENOBUFS as-is so callers can handle it
in a nicer fashion. In vl_method_extend(), map it to the new varlink error
io.systemd.PCRExtend.NvPCRSpaceExhausted. In run(), handle -ENOBUFS
explicitly under --graceful and print an appropriate message. Update
tpm2-setup.c accordingly.

Fixes #42725
Signed-off-by: dongshengyuan <dongshengyuan@uniontech.com>
This commit is contained in:
dongshengyuan
2026-07-02 21:49:18 +02:00
committed by Lennart Poettering
parent 231176d25b
commit be8a7b418a
4 changed files with 15 additions and 4 deletions
+2 -2
View File
@@ -423,7 +423,7 @@ static int setup_nvpcr_one(
LOG_MESSAGE("The TPM does not correctly support NV indexes in NT_EXTEND mode, unable to allocate NvPCR '%s': %m", name),
LOG_MESSAGE_ID(SD_MESSAGE_TPM_NVPCR_UNSUPPORTED_STR));
}
if (r == -ENOSPC) {
if (r == -ENOBUFS) {
/* The TPM's NV index space is exhausted. Remember this so we skip the remaining (less
* important) NvPCRs, and report it gracefully at the end rather than failing the boot.
* Logged at notice level, not error. */
@@ -549,7 +549,7 @@ static int setup_nvpcr(void) {
* SuccessExitStatus= in the service unit file. */
if (ret == -EOPNOTSUPP)
return EX_UNAVAILABLE; /* e.g. no NvPCR support in TPM */
if (ret == -ENOSPC)
if (ret == -ENOBUFS)
return EX_CANTCREAT; /* NV index space on TPM exhausted */
return ret;