From nobody Sat Sep 26 08:39:16 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 408F6351C04; Thu, 3 Sep 2026 03:58:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788407929; cv=none; b=ofXI5x4gJuKqnaYRltS9KyNvsgAJ52zD9MUMwWGJW40Tv1wLrxWyjAoGUNBaz8ucZH/JS/V6p+MQ4BnvUPNEoZmoBJWVhCWTndfNJGIAKvatTdtvhVAMQHErV0PSEQPtHxLEm7Lk40y3Bcgl58oYiTTUGj24wGoE+y/8IAbjPIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788407929; c=relaxed/simple; bh=Og1Iw0roLZA/csEIQPZmStLSzUTB+tbGQqFWQzD/4tI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Jm1IO7ese2Ulbay+oyHNoRW+Jc7SjWURmwyf7oXIjLmoF0Xkh5x/H56mOg4AXtdVuge8++EKFUwZErCbanJQbtwrJF2yrvDx8uLg9gRoIVc8vmK6N+BYEUbJJH3f8bLd03VwE/XnOVs/VmAhKXkDpOQXhYZNPEDsN7DP43o5H78= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: c044e322a74b11f19a56ed5b684f684d-20260903 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:169575db-8284-4043-8f65-60f49d873fe5,IP:0,U RL:25,TC:0,Content:-25,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:25 X-CID-META: VersionHash:7db8b62,CLOUDID:76f79b66bd9105c7f99d59bf1986ee0c,BulkI D:nil,BulkQuantity:0,SF:102|850|865|898,TC:nil,Content:0|15|50,EDM:5,IP:ni l,URL:11|93|82|1,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0 ,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: c044e322a74b11f19a56ed5b684f684d-20260903 X-User: yijiangshan@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 303310129; Thu, 03 Sep 2026 11:58:41 +0800 From: Jiangshan Yi To: peterhuewe@gmx.de, jarkko@kernel.org Cc: jgg@ziepe.ca, James.Bottomley@HansenPartnership.com, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, 13667453960@163.com, Jiangshan Yi , Sashiko , stable@vger.kernel.org Subject: [PATCH] tpm: fix off-by-four bounds check in tpm2_get_random() Date: Thu, 3 Sep 2026 11:58:37 +0800 Message-Id: <20260903035837.219284-1-yijiangshan@kylinos.cn> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When the response carries the TPM2_ST_SESSIONS tag, tpm2_get_random() skips the 4-byte parameter size field before locating the random data, but the bounds check still validates the response length against TPM_HEADER_SIZE. A truncated response can pass the check and make memcpy() read up to 4 bytes past the response end, so stale buffer contents end up in the caller's random bytes. Fix this by checking the response length against 'offset', which already includes the skipped parameter size field. Fixes: 1b6d7f9eb150 ("tpm: add session encryption protection to tpm2_get_ra= ndom()") Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260902074839.417419-1-yijiangshan%= 40kylinos.cn Cc: stable@vger.kernel.org Signed-off-by: Jiangshan Yi Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm2-cmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index 48cec39995fe..d74df7808a3f 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -305,7 +305,7 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, si= ze_t max) out =3D (struct tpm2_get_random_out *)&buf->data[offset]; recd =3D min_t(u32, be16_to_cpu(out->size), num_bytes); if (tpm_buf_length(buf) < - TPM_HEADER_SIZE + + offset + offsetof(struct tpm2_get_random_out, buffer) + recd) { tpm2_end_auth_session(chip); --=20 2.25.1