Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 916BBC433F5 for ; Wed, 24 Nov 2021 12:32:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244224AbhKXMfG (ORCPT ); Wed, 24 Nov 2021 07:35:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:44396 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244131AbhKXM1t (ORCPT ); Wed, 24 Nov 2021 07:27:49 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2810F6112D; Wed, 24 Nov 2021 12:17:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1637756222; bh=G9rknTV9T8mnK85PqcPhJA8piYfQwTzEAj81uz40q5A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qx0yNNYjnRY+Y3pTJ2P1Kt5k5EAVms82dS9ezviGCpfbEOJHHob/hZyM6dUKJZnE0 Wxk4fdTf9+E8LoUal/8GlnDO3hdHSuNKmYZb7rFKFZWmB+0JlJykU9TPFCoWEEVfZj FQjB9wFmIEKQU3k66OFKgUW4RiiP3dqJRlU5xb8k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Jarkko Sakkinen Subject: [PATCH 4.14 010/251] tpm: Check for integer overflow in tpm2_map_response_body() Date: Wed, 24 Nov 2021 12:54:12 +0100 Message-Id: <20211124115710.574741560@linuxfoundation.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211124115710.214900256@linuxfoundation.org> References: <20211124115710.214900256@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter commit a0bcce2b2a169e10eb265c8f0ebdd5ae4c875670 upstream. The "4 * be32_to_cpu(data->count)" multiplication can potentially overflow which would lead to memory corruption. Add a check for that. Cc: stable@vger.kernel.org Fixes: 745b361e989a ("tpm: infrastructure for TPM spaces") Signed-off-by: Dan Carpenter Reviewed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: Greg Kroah-Hartman --- drivers/char/tpm/tpm2-space.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/char/tpm/tpm2-space.c +++ b/drivers/char/tpm/tpm2-space.c @@ -422,6 +422,9 @@ static int tpm2_map_response_body(struct if (be32_to_cpu(data->capability) != TPM2_CAP_HANDLES) return 0; + if (be32_to_cpu(data->count) > (UINT_MAX - TPM_HEADER_SIZE - 9) / 4) + return -EFAULT; + if (len != TPM_HEADER_SIZE + 9 + 4 * be32_to_cpu(data->count)) return -EFAULT;