From: Qunqin Zhao <zhaoqunqin@loongson.cn>
To: Fang Xieyan <fangxy@xiaopeng.com>,
Peter Huewe <peterhuewe@gmx.de>,
Jarkko Sakkinen <jarkko@kernel.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>,
linux-crypto@vger.kernel.org, linux-integrity@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Lin Qiaojie <linqj@xiaopeng.com>
Subject: Re: [PATCH v2] tpm: loongson: bound the response by the shared buffer size
Date: Wed, 2 Dec 2026 11:07:25 +0800 [thread overview]
Message-ID: <b83386e4-907c-4cc9-83ca-bca7dcdacf4f@loongson.cn> (raw)
In-Reply-To: <20261202011913.65166-1-fangxy@xiaopeng.com>
在 2026/12/2 09:19, Fang Xieyan 写道:
> @@ -19,13 +19,17 @@ static int tpm_loongson_recv(struct tpm_chip *chip, u8 *buf, size_t count)
> {
> struct loongson_se_engine *tpm_engine = dev_get_drvdata(&chip->dev);
> struct tpm_loongson_cmd *cmd_ret = tpm_engine->command_ret;
> + u32 data_len = READ_ONCE(cmd_ret->data_len);
>
> - if (cmd_ret->data_len > count)
> + if (data_len > count)
> return -EIO;
>
> - memcpy(buf, tpm_engine->data_buffer, cmd_ret->data_len);
> + if (data_len > tpm_engine->buffer_size)
> + return -EIO;
The hardware returns correct data and the transfer itself succeeds.
The issue is that the DMA buffer allocated by the kernel is too small,
hence -EIO should not be returned here. I guess we can do it like this:
@@ -20,9 +20,12 @@ static int tpm_loongson_recv(struct tpm_chip *chip, u8 *buf, size_t count)
struct loongson_se_engine *tpm_engine = dev_get_drvdata(&chip->dev);
struct tpm_loongson_cmd *cmd_ret = tpm_engine->command_ret;
- if (cmd_ret->data_len > count)
+ if (data_len > TPM_BUFFSIZE)
return -EIO;
+ if (count < data_len)
+ return -EINVAL;
+
memcpy(buf, tpm_engine->data_buffer, cmd_ret->data_len);
return cmd_ret->data_len;
@@ -58,6 +61,10 @@ static int tpm_loongson_probe(struct platform_device *pdev)
tpm_engine = loongson_se_init_engine(dev->parent, SE_ENGINE_TPM);
if (!tpm_engine)
return -ENODEV;
+
+ if (tpm_engine->buffer_size < TPM_BUFSIZE)
+ return -ENOMEM;
+
cmd = tpm_engine->command;
cmd->cmd_id = SE_CMD_TPM;
cmd->data_off = tpm_engine->buffer_off;
Qunqin,
Thanks.
prev parent reply other threads:[~2026-12-02 3:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 1:19 Fang Xieyan
2026-12-02 3:07 ` Qunqin Zhao [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=b83386e4-907c-4cc9-83ca-bca7dcdacf4f@loongson.cn \
--to=zhaoqunqin@loongson.cn \
--cc=fangxy@xiaopeng.com \
--cc=jarkko@kernel.org \
--cc=jgg@ziepe.ca \
--cc=linqj@xiaopeng.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterhuewe@gmx.de \
--cc=stable@vger.kernel.org \
/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 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®