* [PATCH] tpm: ibmvtpm: check the response size against the buffer size
@ 2026-11-06 1:49 Guo Zihao
2026-11-06 15:23 ` Jarkko Sakkinen
0 siblings, 1 reply; 2+ messages in thread
From: Guo Zihao @ 2026-11-06 1:49 UTC (permalink / raw)
To: Peter Huewe, Jarkko Sakkinen
Cc: Jason Gunthorpe, Ashley Lai, Kent Yoder, linuxppc-dev,
linux-integrity, linux-kernel, stable
The send path validates the transfer size against the size of the
RTCE buffer:
if (count > ibmvtpm->rtce_size) {
dev_err(ibmvtpm->dev,
"Invalid size in send: count=%zd, rtce_size=%d\n",
count, ibmvtpm->rtce_size);
return -EIO;
}
The receive path has no such check: the response length is whatever
the hypervisor reported in the completion CRQ, and it is only
compared against the size the caller asked for before being used to
copy and clear the RTCE buffer:
len = ibmvtpm->res_len;
if (count < len) {
...
return -EIO;
}
spin_lock(&ibmvtpm->rtce_lock);
memcpy((void *)buf, (void *)ibmvtpm->rtce_buf, len);
memset(ibmvtpm->rtce_buf, 0, len);
A response length larger than the RTCE buffer makes the memcpy read
past the buffer and the memset clear past it.
Reject a response that does not fit in the RTCE buffer, mirroring
the check the send path already performs.
Fixes: 132f76294744 ("drivers/char/tpm: Add new device driver to support IBM vTPM")
Cc: stable@vger.kernel.org
Signed-off-by: Guo Zihao <guozh23@xiaopeng.com>
---
drivers/char/tpm/tpm_ibmvtpm.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
index 6fb4d30eb..bfef4bc14 100644
--- a/drivers/char/tpm/tpm_ibmvtpm.c
+++ b/drivers/char/tpm/tpm_ibmvtpm.c
@@ -121,6 +121,13 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
return -EIO;
}
+ if (len > ibmvtpm->rtce_size) {
+ dev_err(ibmvtpm->dev,
+ "Invalid size in recv: res_len=%d, rtce_size=%d\n",
+ len, ibmvtpm->rtce_size);
+ return -EIO;
+ }
+
spin_lock(&ibmvtpm->rtce_lock);
memcpy((void *)buf, (void *)ibmvtpm->rtce_buf, len);
memset(ibmvtpm->rtce_buf, 0, len);
--
2.50.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] tpm: ibmvtpm: check the response size against the buffer size
2026-11-06 1:49 [PATCH] tpm: ibmvtpm: check the response size against the buffer size Guo Zihao
@ 2026-11-06 15:23 ` Jarkko Sakkinen
0 siblings, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2026-11-06 15:23 UTC (permalink / raw)
To: Guo Zihao
Cc: Peter Huewe, Jason Gunthorpe, Ashley Lai, Kent Yoder,
linuxppc-dev, linux-integrity, linux-kernel, stable
On Fri, Nov 06, 2026 at 09:49:46AM +0800, Guo Zihao wrote:
> The send path validates the transfer size against the size of the
> RTCE buffer:
>
> if (count > ibmvtpm->rtce_size) {
> dev_err(ibmvtpm->dev,
> "Invalid size in send: count=%zd, rtce_size=%d\n",
> count, ibmvtpm->rtce_size);
> return -EIO;
> }
>
> The receive path has no such check: the response length is whatever
> the hypervisor reported in the completion CRQ, and it is only
> compared against the size the caller asked for before being used to
> copy and clear the RTCE buffer:
>
> len = ibmvtpm->res_len;
>
> if (count < len) {
> ...
> return -EIO;
> }
>
> spin_lock(&ibmvtpm->rtce_lock);
> memcpy((void *)buf, (void *)ibmvtpm->rtce_buf, len);
> memset(ibmvtpm->rtce_buf, 0, len);
>
> A response length larger than the RTCE buffer makes the memcpy read
> past the buffer and the memset clear past it.
>
> Reject a response that does not fit in the RTCE buffer, mirroring
> the check the send path already performs.
>
> Fixes: 132f76294744 ("drivers/char/tpm: Add new device driver to support IBM vTPM")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guo Zihao <guozh23@xiaopeng.com>
> ---
Ditto. I.e, I'm not sure if this is a bug fix or just better validation
for failing components.
Br, Jarkko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-06 15:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06 1:49 [PATCH] tpm: ibmvtpm: check the response size against the buffer size Guo Zihao
2026-11-06 15:23 ` 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®