]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tpm2-sessions: Fix missing tpm_buf_destroy() in tpm2_read_public()
authorGunnar Kudrjavets <gunnarku@amazon.com>
Wed, 15 Apr 2026 00:00:03 +0000 (03:00 +0300)
committerJarkko Sakkinen <jarkko@kernel.org>
Tue, 21 Apr 2026 15:54:28 +0000 (18:54 +0300)
tpm2_read_public() calls tpm_buf_init() but fails to call
tpm_buf_destroy() on two exit paths, leaking a page allocation:

1. When name_size() returns an error (unrecognized hash algorithm),
   the function returns directly without destroying the buffer.

2. On the success path, the buffer is never destroyed before
   returning.

All other error paths in the function correctly call
tpm_buf_destroy() before returning.

Fix both by adding the missing tpm_buf_destroy() calls.

Cc: stable@vger.kernel.org # v6.19+
Fixes: bda1cbf73c6e ("tpm2-sessions: Fix tpm2_read_public range checks")
Signed-off-by: Gunnar Kudrjavets <gunnarku@amazon.com>
Reviewed-by: Justinien Bouron <jbouron@amazon.com>
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
drivers/char/tpm/tpm2-sessions.c

index 3b1cf1ca042005e9690a017ac39f4a789f016735..c4da6fde748f41adc8209800d2239a934c7efbb1 100644 (file)
@@ -203,8 +203,10 @@ static int tpm2_read_public(struct tpm_chip *chip, u32 handle, void *name)
        rc = tpm_buf_read_u16(&buf, &offset);
        name_size_alg = name_size(&buf.data[offset]);
 
-       if (name_size_alg < 0)
+       if (name_size_alg < 0) {
+               tpm_buf_destroy(&buf);
                return name_size_alg;
+       }
 
        if (rc != name_size_alg) {
                tpm_buf_destroy(&buf);
@@ -217,6 +219,7 @@ static int tpm2_read_public(struct tpm_chip *chip, u32 handle, void *name)
        }
 
        memcpy(name, &buf.data[offset], rc);
+       tpm_buf_destroy(&buf);
        return name_size_alg;
 }
 #endif /* CONFIG_TCG_TPM2_HMAC */