From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796041686; b=4yGETNm+tSziZ3JT2OUF4+GqsCrfQPX4WN0jDz7E90ZScfA/39l9Z1zUyytVOx+ZOK0a wHm3IwIXZGhdxiactZ4reOUJoXSh8YRskeS9YTdRiLS7Hk4mfr1g6C5l0POZUfcAFR4Yz 9wxNNd8rjq5xi94MT3hZEPOOYTd3OxpMXC1FN65ixQlLO4nYV51KZ9n5nRiKx2ByVA6Aw P1lzucyU4bS4qRSi1RRR1Hw9tA0r39d1mueREy67mg8nGv77PnqE5nyagAC89XKxFTQ1o NHA/QZxLXFib37lMysefGzc6Pl7NRpBlYEOWhhFsxSynJwfJE4SZ4W7V31z25eDiPLg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796041686; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=iWdUBiNE4JKnoErxV5rD2z/Rccx424PjORMddsElBnA=; b=MnH05U6QEc3234ua5yIBYK4XKDz0hIxEgcxnemDt3rNgmuT0yskaoCo0eq+8nMCS5Jqb yiyfvT49HdPxRz27bO/+hUHX5xjz7KmF9UO4vA6BoIQdxK+7lR0GDQPNPSt/hEkDrAlyi QhGtUdgSybYNy8b8BfxtofC6sGNZfEQwCZPzPMQ2wlzOXWjsS8g9kJ01vLPbL8FccF0kB DZrKxbh45CMnW+/KGBNJQLsi4murceQs4/ncsxBqh85MSPCq8cGttIF19Edu0iPtr87t1 yai1mZxRUM72tz8mZmN+CGLZNIo5gx2wLqRTTZlUZ6nbNOOJGr1P7EInM0uhYYfKblw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=a0L3OVYp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB065606A31C for ; Mon, 30 Nov 2026 12:28:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=a0L3OVYp Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAF451F00896; Mon, 30 Nov 2026 12:28:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796041686; bh=iWdUBiNE4JKnoErxV5rD2z/Rccx424PjORMddsElBnA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=a0L3OVYp6Zrk0My+hMUD8US72b2f4H0Si5YYPyrQ1mFdYpv9ZeeLhHtlXiG7gBCYx aH1wynXUYfx1N6FlmVG9LoZw+TipwaxcyylaoiWdaFW3FsuFFlmCrr3wNjZdvfr45M GJ/GRYdNatE3PLSsHUPNasO36cUtQkgc9tRcXSnjh9/drhY+7dBNaCqx3XzKL2TIRt YsjdVByeflvDx+cvHibz88UoVEsvD8GWCOVMJe+NBR9k3ZHLM7IIermg9DXCviJMC3 DI1sK8Po4UFoOP7OmLpg7wRTUCs7PzLF2BkoHZoGwzfn0Klntj8H4hkQ68unmKubOY f4cYIUG7Q844w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] tpm: loongson: bound the response by the shared buffer size Reply-To: sashiko-reviews@lists.linux.dev To: "Fang Xieyan" , "Qunqin Zhao" , "Peter Huewe" , "Jarkko Sakkinen" Cc: "Jason Gunthorpe" , linux-crypto@vger.kernel.org, "Lin Qiaojie" In-Reply-To: <20261130122041.59360-1-fangxy@xiaopeng.com> References: <20261130122041.59360-1-fangxy@xiaopeng.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 12:28:05 +0000 X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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_loong= son.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; > =20 > + if (cmd_ret->data_len > tpm_engine->buffer_size) > + return -EIO; > + > memcpy(buf, tpm_engine->data_buffer, cmd_ret->data_len); > =20 > 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130122041.5936= 0-1-fangxy@xiaopeng.com?part=3D1