Linux cryptographic layer development
 help / color / mirror / Atom feed
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>, "Lee Jones" <lee@kernel.org>,
	"Huacai Chen" <chenhuacai@kernel.org>,
	"Yinggang Gu" <guyinggang@loongson.cn>,
	linux-crypto@vger.kernel.org, "Lin Qiaojie" <linqj@xiaopeng.com>
Subject: Re: [PATCH v4] tpm: loongson: bound the response by the DMA window
Date: Fri, 04 Dec 2026 16:10:00 +0000	[thread overview]
Message-ID: <sashiko-outbox-250162@kernel.org> (raw)
In-Reply-To: <20261204155246.60786-1-fangxy@xiaopeng.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] tpm: loongson: untested firmware ABI change in
  tpm_loongson_probe()
--

commit 4578f644ae7983bb4262bd7e41b5d35fe9618363
Author: Fang Xieyan <fangxy@xiaopeng.com>

tpm: loongson: bound the response by the DMA window

This commit bounds the response length read by tpm_loongson_recv() against
the engine's DMA buffer size using READ_ONCE(), and writes buffer_size into
the first reserved word of struct tpm_loongson_cmd during
tpm_loongson_probe().

> diff --git a/drivers/char/tpm/tpm_loongson.c b/drivers/char/tpm/tpm_loongson.c
> index 9e50250763d16..59f3947bec5d5 100644
> --- a/drivers/char/tpm/tpm_loongson.c
> +++ b/drivers/char/tpm/tpm_loongson.c
> @@ -12,20 +12,22 @@ struct tpm_loongson_cmd {
>  	u32 cmd_id;
>  	u32 data_off;
>  	u32 data_len;
> -	u32 pad[5];
> +	u32 buffer_size;
> +	u32 pad[4];
>  };

[ ... ]

> @@ -61,6 +63,7 @@ static int tpm_loongson_probe(struct platform_device *pdev)
>  	cmd = tpm_engine->command;
>  	cmd->cmd_id = SE_CMD_TPM;
>  	cmd->data_off = tpm_engine->buffer_off;
> +	cmd->buffer_size = tpm_engine->buffer_size;

[Severity: Medium]
Can writing a non-zero value to cmd->buffer_size break deployed Security
Engine firmware that expects reserved words in struct tpm_loongson_cmd to
be zero?

loongson_se_probe() allocates the shared DMA region with
dmam_alloc_coherent(), so this word was previously always zero and no
firmware version check guards it.  If existing firmware rejects non-zero
reserved fields, TPM command execution will break on existing platforms.

Because tpm_loongson_recv() already prevents the out-of-bounds read on the
host side without cmd->buffer_size, and this patch targets stable without
hardware testing, splitting the cmd->buffer_size change into a separate
patch tested against deployed firmware would avoid that regression risk.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204155246.60786-1-fangxy@xiaopeng.com?part=1

      reply	other threads:[~2026-12-04 16:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 15:52 [PATCH v4] tpm: loongson: bound the response by the DMA window Fang Xieyan
2026-12-04 16:10 ` 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-250162@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=fangxy@xiaopeng.com \
    --cc=guyinggang@loongson.cn \
    --cc=jarkko@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=lee@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox