[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAGxU2F6m2=+07sUoy4PKVs1vMR6Yr--pgkOG3SEGg8gi=HRf+g@mail.gmail.com>
Date: Wed, 7 May 2025 11:32:10 +0200
From: Stefano Garzarella <sgarzare@...hat.com>
To: Qunqin Zhao <zhaoqunqin@...ngson.cn>
Cc: lee@...nel.org, herbert@...dor.apana.org.au, davem@...emloft.net,
peterhuewe@....de, jarkko@...nel.org, linux-kernel@...r.kernel.org,
loongarch@...ts.linux.dev, linux-crypto@...r.kernel.org, jgg@...pe.ca,
linux-integrity@...r.kernel.org, pmenzel@...gen.mpg.de, Yinggang Gu <guyinggang@...ngson.cn>,
Huacai Chen <chenhuacai@...ngson.cn>
Subject: Re: [PATCH v9 4/5] tpm: Add a driver for Loongson TPM device
On Wed, 7 May 2025 at 03:35, Qunqin Zhao <zhaoqunqin@...ngson.cn> wrote:
>
>
> 在 2025/5/6 下午10:13, Stefano Garzarella 写道:
> > On Tue, May 06, 2025 at 11:19:46AM +0800, Qunqin Zhao wrote:
> >> Loongson Security Engine supports random number generation, hash,
> >> symmetric encryption and asymmetric encryption. Based on these
> >> encryption functions, TPM2 have been implemented in the Loongson
> >> Security Engine firmware. This driver is responsible for copying data
> >> into the memory visible to the firmware and receiving data from the
> >> firmware.
> >>
> >> Co-developed-by: Yinggang Gu <guyinggang@...ngson.cn>
> >> Signed-off-by: Yinggang Gu <guyinggang@...ngson.cn>
> >> Signed-off-by: Qunqin Zhao <zhaoqunqin@...ngson.cn>
> >> Reviewed-by: Huacai Chen <chenhuacai@...ngson.cn>
> >> Reviewed-by: Jarkko Sakkinen <jarkko@...nel.org>
> >> ---
> >> v9: "tpm_loongson_driver" --> "tpm_loongson"
> >> "depends on CRYPTO_DEV_LOONGSON_SE" --> "depends on MFD_LOONGSON_SE"
> >>
> ...
> >> +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;
> >> +
> >> + memcpy(buf, tpm_engine->data_buffer, cmd_ret->data_len);
> >
> > Should we limit the memcpy to `count`?
> >
> > I mean, can happen that `count` is less than `cmd_ret->data_len`?
>
> Hi, Stefan, thanks for your comment.
>
> Firmware ensures "cmd_ret->data_len" will be less than TPM_BUFSIZE, so
> this would never happen.
I see, but I meant the opposite, if `count` (size of `buf`) is less than
`cmd_ret->data_len`.
I mean, should we add something like this:
if (count < cmd_ret->data_len) {
return -EIO;
}
I see we do this in other drivers as well (e.g. crb, ftpm), so I'm
trying to understand why here is not the case.
Thanks,
Stefano
Powered by blists - more mailing lists