* [PATCH] tpm: Fix auth session leak in tpm2_get_random() error path
@ 2026-09-02 7:48 Jiangshan Yi
2026-09-09 15:57 ` Jarkko Sakkinen
0 siblings, 1 reply; 4+ messages in thread
From: Jiangshan Yi @ 2026-09-02 7:48 UTC (permalink / raw)
To: peterhuewe, jarkko
Cc: jgg, ross.philipson, stefanb, linux-integrity, linux-kernel,
13667453960, Jiangshan Yi, stable
When tpm_buf_fill_hmac_session() fails in tpm2_get_random(), the error
path returns without calling tpm2_end_auth_session(), leaking the auth
session. All other error paths in the function handle this correctly.
Fixes: 3d9e043dab0a ("tpm-buf: Memory-safe allocations")
Cc: stable@vger.kernel.org
Signed-off-by: Jiangshan Yi <yijiangshan@kylinos.cn>
---
drivers/char/tpm/tpm2-cmd.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 48cec39995fe..96e0e06bbbf0 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -281,8 +281,10 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
}
tpm_buf_append_u16(buf, num_bytes);
err = tpm_buf_fill_hmac_session(chip, buf);
- if (err)
+ if (err) {
+ tpm2_end_auth_session(chip);
return err;
+ }
err = tpm_transmit_cmd(chip, buf,
offsetof(struct tpm2_get_random_out,
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] tpm: Fix auth session leak in tpm2_get_random() error path
2026-09-02 7:48 [PATCH] tpm: Fix auth session leak in tpm2_get_random() error path Jiangshan Yi
@ 2026-09-09 15:57 ` Jarkko Sakkinen
0 siblings, 0 replies; 4+ messages in thread
From: Jarkko Sakkinen @ 2026-09-09 15:57 UTC (permalink / raw)
To: Jiangshan Yi
Cc: peterhuewe, jgg, ross.philipson, stefanb, linux-integrity,
linux-kernel, 13667453960, stable
On Wed, Sep 02, 2026 at 03:48:39PM +0800, Jiangshan Yi wrote:
> When tpm_buf_fill_hmac_session() fails in tpm2_get_random(), the error
> path returns without calling tpm2_end_auth_session(), leaking the auth
> session. All other error paths in the function handle this correctly.
>
> Fixes: 3d9e043dab0a ("tpm-buf: Memory-safe allocations")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jiangshan Yi <yijiangshan@kylinos.cn>
> ---
> drivers/char/tpm/tpm2-cmd.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index 48cec39995fe..96e0e06bbbf0 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -281,8 +281,10 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
> }
> tpm_buf_append_u16(buf, num_bytes);
> err = tpm_buf_fill_hmac_session(chip, buf);
> - if (err)
> + if (err) {
> + tpm2_end_auth_session(chip);
> return err;
> + }
>
> err = tpm_transmit_cmd(chip, buf,
> offsetof(struct tpm2_get_random_out,
> --
> 2.25.1
>
Thanks for the fix.
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
BR, Jarkko
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] tpm: Fix auth session leak in tpm2_get_random() error path
@ 2026-04-02 18:11 Gunnar Kudrjavets
2026-04-08 9:00 ` Jarkko Sakkinen
0 siblings, 1 reply; 4+ messages in thread
From: Gunnar Kudrjavets @ 2026-04-02 18:11 UTC (permalink / raw)
To: peterhuewe, jarkko
Cc: jgg, noodles, linux-integrity, linux-kernel, Justinien Bouron
When tpm_buf_fill_hmac_session() fails inside the do-while loop in
tpm2_get_random(), the function returns directly after destroying the
buffer, without ending the auth session via tpm2_end_auth_session().
This leaks the TPM auth session resource. All other error paths within
the loop correctly reach the 'out' label which calls both
tpm_buf_destroy() and tpm2_end_auth_session().
Fix this by replacing the early return with a goto to the existing 'out'
label, which already handles both cleanup operations. The redundant
tpm_buf_destroy() call is removed since 'out' takes care of it.
Fixes: 6e9722e9a7bf ("tpm2-sessions: Fix out of range indexing in name_size")
Signed-off-by: Gunnar Kudrjavets <gunnarku@amazon.com>
Reviewed-by: Justinien Bouron <jbouron@amazon.com>
---
drivers/char/tpm/tpm2-cmd.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index e00f668f8c84..b11e6fa8b740 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -295,10 +295,8 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
}
tpm_buf_append_u16(&buf, num_bytes);
err = tpm_buf_fill_hmac_session(chip, &buf);
- if (err) {
- tpm_buf_destroy(&buf);
- return err;
- }
+ if (err)
+ goto out;
err = tpm_transmit_cmd(chip, &buf,
offsetof(struct tpm2_get_random_out,
base-commit: 7f2a32c0e87814f0e7852b17fa9f10321f882c36
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] tpm: Fix auth session leak in tpm2_get_random() error path
2026-04-02 18:11 Gunnar Kudrjavets
@ 2026-04-08 9:00 ` Jarkko Sakkinen
0 siblings, 0 replies; 4+ messages in thread
From: Jarkko Sakkinen @ 2026-04-08 9:00 UTC (permalink / raw)
To: Gunnar Kudrjavets
Cc: peterhuewe, jgg, noodles, linux-integrity, linux-kernel,
Justinien Bouron
On Thu, Apr 02, 2026 at 06:11:39PM +0000, Gunnar Kudrjavets wrote:
> When tpm_buf_fill_hmac_session() fails inside the do-while loop in
> tpm2_get_random(), the function returns directly after destroying the
> buffer, without ending the auth session via tpm2_end_auth_session().
>
> This leaks the TPM auth session resource. All other error paths within
> the loop correctly reach the 'out' label which calls both
> tpm_buf_destroy() and tpm2_end_auth_session().
>
> Fix this by replacing the early return with a goto to the existing 'out'
> label, which already handles both cleanup operations. The redundant
> tpm_buf_destroy() call is removed since 'out' takes care of it.
>
> Fixes: 6e9722e9a7bf ("tpm2-sessions: Fix out of range indexing in name_size")
> Signed-off-by: Gunnar Kudrjavets <gunnarku@amazon.com>
> Reviewed-by: Justinien Bouron <jbouron@amazon.com>
> ---
> drivers/char/tpm/tpm2-cmd.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index e00f668f8c84..b11e6fa8b740 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -295,10 +295,8 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
> }
> tpm_buf_append_u16(&buf, num_bytes);
> err = tpm_buf_fill_hmac_session(chip, &buf);
> - if (err) {
> - tpm_buf_destroy(&buf);
> - return err;
> - }
> + if (err)
> + goto out;
>
> err = tpm_transmit_cmd(chip, &buf,
> offsetof(struct tpm2_get_random_out,
>
> base-commit: 7f2a32c0e87814f0e7852b17fa9f10321f882c36
> --
> 2.47.3
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
BR, Jarkko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-09 15:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-02 7:48 [PATCH] tpm: Fix auth session leak in tpm2_get_random() error path Jiangshan Yi
2026-09-09 15:57 ` Jarkko Sakkinen
-- strict thread matches above, loose matches on Subject: below --
2026-04-02 18:11 Gunnar Kudrjavets
2026-04-08 9:00 ` Jarkko Sakkinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®