From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 349CA4EB855; Fri, 9 Oct 2026 14:44:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791557097; cv=none; b=UXQ/DGpx4mHgAsKNnkFd+GFD59kjyGoAW0aiN6BZKWjrDRSeCZ0ocrQs1MuF0AV9Z08ecHEIB0piXffq76HDl9EMH5pNBbBrOIZkp7oGhLsnI/8pAn5ggtcUKZRQFSNeiGAOQxjJW1bjKdBUSu9iLl85Hw2EtO3tLZBrYYH9pLY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791557097; c=relaxed/simple; bh=21lQSlldcqx3mUZbaRc2qhCBlTWQ21gSafTVprRQ8qM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t39QOvjB7zOQLllwEyl1h5OtzKHY8gHlnex9L7ser7JURN8e89dDgPxOxL4RN0gLsm5dSjhhofJIPLq/6l3JC4swvdDGQ97cgwYH3g6BNYzPtX8z3KTzRPtDI8yqiZNJArVj8LfouULEhZVx2lFTRfI6tof+d9zcd2eE93TGBT4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Rwv+nnYI; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Rwv+nnYI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BBD41F000FF; Fri, 9 Oct 2026 14:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1791557095; bh=aIHRi81EfD2+dg4vxg1We2LSLJVCrn6I0F//kI7tHRQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Rwv+nnYIUYbFDLmMxN9VRn8YRvnEbkGP8LpIVfPjHXwrYsvhkTggHMB7CtVhDv/cv FLwJeNjD2th+HCJigZ/9etbLM70+Ebrce0mePqKZCYxAsE1oPph+dvFIS0enjCPXhJ 69Z2yvPOoZ4A8U/PszAF5C+0hh27OI1G+mf0DitU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Jiangshan Yi , Jarkko Sakkinen , Sasha Levin Subject: [PATCH 7.2 295/428] tpm: fix off-by-four bounds check in tpm2_get_random() Date: Fri, 9 Oct 2026 16:10:32 +0200 Message-ID: <20261009140952.589656831@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261009140946.008206689@linuxfoundation.org> References: <20261009140946.008206689@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiangshan Yi [ Upstream commit 9b522400bf5c082feb9a0037a053ea822a2c7e4d ] 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. Cc: stable@vger.kernel.org # v6.12+ Fixes: 1b6d7f9eb150 ("tpm: add session encryption protection to tpm2_get_random()") Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260902074839.417419-1-yijiangshan%40kylinos.cn Signed-off-by: Jiangshan Yi Reviewed-by: Jarkko Sakkinen Link: https://lore.kernel.org/r/20260903035837.219284-1-yijiangshan@kylinos.cn Signed-off-by: Jarkko Sakkinen Signed-off-by: Sasha Levin --- 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 52ee350da8671..e12e245faeb1e 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -318,7 +318,7 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max) out = (struct tpm2_get_random_out *)&buf.data[offset]; recd = 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) { err = -EFAULT; -- 2.53.0