From: sashiko-bot@kernel.org
To: "Fang Xieyan" <fangxy@xiaopeng.com>,
"Qunqin Zhao" <zhaoqunqin@loongson.cn>,
"Peter Huewe" <peterhuewe@gmx.de>,
"Jarkko Sakkinen" <jarkko@kernel.org>
Cc: "Jason Gunthorpe" <jgg@ziepe.ca>,
linux-crypto@vger.kernel.org, "Lin Qiaojie" <linqj@xiaopeng.com>
Subject: Re: [PATCH] tpm: loongson: bound the response by the shared buffer size
Date: Mon, 30 Nov 2026 12:28:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-241054@kernel.org> (raw)
In-Reply-To: <20261130122041.59360-1-fangxy@xiaopeng.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] tpm: loongson: double-fetch of cmd_ret->data_len in
tpm_loongson_recv()
--
commit 320be338222fef4657828ffd0cbc0aa310c881af
Author: Fang Xieyan <fangxy@xiaopeng.com>
tpm: loongson: bound the response by the shared buffer size
This commit bounds cmd_ret->data_len against tpm_engine->buffer_size in
tpm_loongson_recv() to prevent reading past the TPM engine's shared DMA
buffer when a faulty or compromised Security Engine reports an out-of-bounds
response length.
> diff --git a/drivers/char/tpm/tpm_loongson.c b/drivers/char/tpm/tpm_loongson.c
> index 9e50250763d16..c58cf04115d94 100644
> --- a/drivers/char/tpm/tpm_loongson.c
> +++ b/drivers/char/tpm/tpm_loongson.c
> @@ -23,6 +23,9 @@ static int tpm_loongson_recv(struct tpm_chip *chip, u8 *buf, size_t count)
> if (cmd_ret->data_len > count)
> return -EIO;
>
> + if (cmd_ret->data_len > tpm_engine->buffer_size)
> + return -EIO;
> +
> memcpy(buf, tpm_engine->data_buffer, cmd_ret->data_len);
>
> return cmd_ret->data_len;
[Severity: Medium]
Can the Security Engine bypass these bounds checks by modifying
cmd_ret->data_len in shared DMA memory between the checks, memcpy(), and the
return statement?
tpm_engine->command_ret points into DMA-coherent memory shared with the
engine (se->dmam_base in loongson_se_init_engine()), and cmd_ret->data_len
is read four separate times without READ_ONCE(). Reading cmd_ret->data_len
once into a local variable with READ_ONCE() and using that variable for both
checks, memcpy(), and the return value would avoid a double-fetch.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130122041.59360-1-fangxy@xiaopeng.com?part=1
prev parent reply other threads:[~2026-11-30 12:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 12:20 [PATCH] tpm: loongson: bound the response by the shared buffer size Fang Xieyan
2026-11-30 12:28 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-241054@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=fangxy@xiaopeng.com \
--cc=jarkko@kernel.org \
--cc=jgg@ziepe.ca \
--cc=linqj@xiaopeng.com \
--cc=linux-crypto@vger.kernel.org \
--cc=peterhuewe@gmx.de \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zhaoqunqin@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.