FAILED: patch "[PATCH] tpm: fix off-by-four bounds check in tpm2_get_random()" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 9b522400bf5c082feb9a0037a053ea822a2c7e4d
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026100308-drew-squeamish-a28c@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 9b522400bf5c082feb9a0037a053ea822a2c7e4d Mon Sep 17 00:00:00 2001
From: Jiangshan Yi <[email protected]>
Date: Thu, 3 Sep 2026 11:58:37 +0800
Subject: [PATCH] tpm: fix off-by-four bounds check in tpm2_get_random()
When the response carries the TPM2_ST_SESSIONS tag, tpm2_get_random() skips the 4-byte parameter size field before locating the random data, but the bounds check still validates the response length against TPM_HEADER_SIZE. A truncated response can pass the check and make memcpy() read up to 4 bytes past the response end, so stale buffer contents end up in the caller's random bytes.
Fix this by checking the response length against 'offset', which already includes the skipped parameter size field.
drivers/char/tpm/tpm2-cmd.c +1 -1
@@ -307,7 +307,7 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max) out = (struct tpm2_get_random_out *)&buf->data[offset]; recd =min_t (u32,be16_to_cpu (out->size), num_bytes);if (tpm_buf_length (buf) < -TPM_HEADER_SIZE + + offset + offsetof(struct tpm2_get_random_out , buffer) + recd) {tpm2_end_auth_session (chip);
Sasha Levin
maintainerPATCH 1/1 tpm: fix off-by-four bounds check in tpm2_get_random()
From: Jiangshan Yi <[email protected]>
[ Upstream commit 9b522400bf5c082feb9a0037a053ea822a2c7e4d ]
When the response carries the TPM2_ST_SESSIONS tag, tpm2_get_random() skips the 4-byte parameter size field before locating the random data, but the bounds check still validates the response length against TPM_HEADER_SIZE. A truncated response can pass the check and make memcpy() read up to 4 bytes past the response end, so stale buffer contents end up in the caller's random bytes.
Fix this by checking the response length against 'offset', which already includes the skipped parameter size field.
--- drivers/char/tpm/tpm2-cmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm2-cmd.c +1 -1
@@ -361,7 +361,7 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max) out = (struct tpm2_get_random_out *)&buf.data[offset]; recd =min_t (u32,be16_to_cpu (out->size), num_bytes);if (tpm_buf_length (&buf) < -TPM_HEADER_SIZE + + offset + offsetof(struct tpm2_get_random_out , buffer) + recd) { err = -EFAULT ;
Signature · 1 line
2.53.0
Jarkko Sakkinen
maintainerPATCH 1/1 tpm: fix off-by-four bounds check in tpm2_get_random()
In reply to [email protected]From: Jiangshan Yi <[email protected]>
[ Upstream commit 9b522400bf5c082feb9a0037a053ea822a2c7e4d ]
When the response carries the TPM2_ST_SESSIONS tag, tpm2_get_random() skips the 4-byte parameter size field before locating the random data, but the bounds check still validates the response length against TPM_HEADER_SIZE. A truncated response can pass the check and make memcpy() read up to 4 bytes past the response end, so stale buffer contents end up in the caller's random bytes.
Fix this by checking the response length against 'offset', which already includes the skipped parameter size field.
--- drivers/char/tpm/tpm2-cmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm2-cmd.c +1 -1
@@ -361,7 +361,7 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max) out = (struct tpm2_get_random_out *)&buf.data[offset]; recd =min_t (u32,be16_to_cpu (out->size), num_bytes);if (tpm_buf_length (&buf) < -TPM_HEADER_SIZE + + offset + offsetof(struct tpm2_get_random_out , buffer) + recd) { err = -EFAULT ;
Signature · 1 line
2.47.3
Re: [PATCH 6.12.y] tpm: fix off-by-four bounds check in tpm2_get_random()
Quoted 2 lines
Fix this by checking the response length against 'offset', which already includes the skipped parameter size field.
Queued for 6.12, thanks.
Signature · 2 lines
Thanks, Sasha
Jarkko Sakkinen
maintainerRe: [PATCH 6.12.y] tpm: fix off-by-four bounds check in tpm2_get_random()
Quoted 8 lines · Sasha Levin
Quoted 2 lines
Fix this by checking the response length against 'offset', which already includes the skipped parameter size field.
Queued for 6.12, thanks.
Signature · 2 lines
Thanks, Sasha
Phew, good to hear, thank you!
There might be for some time more than usual merge conflicts in TPM driver given making tpm_buf memory layout flat for the sake of being able to use __free for of its allocations, and thus completely prevent any possible memory leaks from transient buffers.
Right, and also merge conflicts could happen also in trusted keys.
They are cheap to fix and I'll monitor this situation proactively, and try to react fast.
Br, Jarkko