Received: by 10.223.185.116 with SMTP id b49csp5503478wrg; Wed, 7 Mar 2018 12:57:51 -0800 (PST) X-Google-Smtp-Source: AG47ELt+YJHFG6f1Z8otyVjHwxixyRT0kpjeX2qucezqEyP3jjiam/2WGI1UGmcXSr0tCgFsEvQ7 X-Received: by 2002:a17:902:8b82:: with SMTP id ay2-v6mr21441052plb.12.1520456271492; Wed, 07 Mar 2018 12:57:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520456271; cv=none; d=google.com; s=arc-20160816; b=SZIr2LjNQyM0nobhZlzSh5luX94fyQ6FlxTSzu/lvpQYl3iVa4mrBvhRoJxEcSy1e+ artWflvZs+PWC+jMTbTX6pkeXJHxA47lRGJ9z/PH4QUtcAdrPVPq5EqEKnQmAxZSKvkB wbvd9CVUZkT/0dG8LrGvuns9Xuv9XK2ef97NTl5nUjh/ZmQIev30AvgsuHlXJLUwUiVA 95xrXGbu6LJMqCW8Tr4EFtqRfd/xUFLa6Q3hpsc8xAY3YmN4l+3+IQheGQrtClA/XW6/ A9SBQBmNCYY+Sgd0zogE6OVVpX3l1N/Xj/IXvYinVGcr/vP6cCAabTB08iBA8SyJJTX1 cdaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ss7HwkzFBZwxrHkJJCuDkBA7rxobGKmCUi1u7y0w2U0=; b=d2RM7HTpANp/2o5/yA9MgraZhAgcuTGQoBwzcP1WKJWXY22sXE76O2zv8bNRQ62MTd OpwPJ5BWoZCpZp7r1E7/vlPoo7NhHRgA7s7y0eGtWA3JycDtwu2rbWLaiViUTHl6Lwnp 6aoR8SIbWTsXclsN99biBe1gGsa0MgQl7FZJ2OMWoGuy3MeiGAsfW+pz11BCCv4qWMT0 UG+OpAUsGwNuAwjUfdUdSSTAdeqpO1i9FHMCg2KY4MkOD1pB8cb+O8W8WuogMXzGdzIA S8E4XF+Lolsrypxncxqd4zqiMIuPXf2E/fDciR4ZtnyVV7bF61chuKVU3tMTaZUBa8Ui 9V+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z6si11750718pgn.46.2018.03.07.12.57.37; Wed, 07 Mar 2018 12:57:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933902AbeCGTjp (ORCPT + 99 others); Wed, 7 Mar 2018 14:39:45 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40298 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933677AbeCGTjm (ORCPT ); Wed, 7 Mar 2018 14:39:42 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 08ECDF05; Wed, 7 Mar 2018 19:39:41 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeremy Boone , James Bottomley , Jarkko Sakkinen , James Morris Subject: [PATCH 4.15 010/122] tpm_i2c_infineon: fix potential buffer overruns caused by bit glitches on the bus Date: Wed, 7 Mar 2018 11:37:02 -0800 Message-Id: <20180307191730.714925568@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191729.190879024@linuxfoundation.org> References: <20180307191729.190879024@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jeremy Boone commit 9b8cb28d7c62568a5916bdd7ea1c9176d7f8f2ed upstream. Discrete TPMs are often connected over slow serial buses which, on some platforms, can have glitches causing bit flips. In all the driver _recv() functions, we need to use a u32 to unmarshal the response size, otherwise a bit flip of the 31st bit would cause the expected variable to go negative, which would then try to read a huge amount of data. Also sanity check that the expected amount of data is large enough for the TPM header. Signed-off-by: Jeremy Boone Cc: stable@vger.kernel.org Signed-off-by: James Bottomley Reviewed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: James Morris Signed-off-by: Greg Kroah-Hartman --- drivers/char/tpm/tpm_i2c_infineon.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/char/tpm/tpm_i2c_infineon.c +++ b/drivers/char/tpm/tpm_i2c_infineon.c @@ -473,7 +473,8 @@ static int recv_data(struct tpm_chip *ch static int tpm_tis_i2c_recv(struct tpm_chip *chip, u8 *buf, size_t count) { int size = 0; - int expected, status; + int status; + u32 expected; if (count < TPM_HEADER_SIZE) { size = -EIO; @@ -488,7 +489,7 @@ static int tpm_tis_i2c_recv(struct tpm_c } expected = be32_to_cpu(*(__be32 *)(buf + 2)); - if ((size_t) expected > count) { + if (((size_t) expected > count) || (expected < TPM_HEADER_SIZE)) { size = -EIO; goto out; }