Received: by 10.223.185.111 with SMTP id b44csp912092wrg; Fri, 9 Mar 2018 16:40:36 -0800 (PST) X-Google-Smtp-Source: AG47ELtCyLngbOPux6n4FOXa56vXKJTIhtqN7DfNSC3hRYWUh8A/5YgBx+Bfl+BMNR/FPPW5ULqS X-Received: by 10.99.126.24 with SMTP id z24mr286371pgc.343.1520642436489; Fri, 09 Mar 2018 16:40:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520642436; cv=none; d=google.com; s=arc-20160816; b=KI+oEqRsmR6MPg30p7gkOM/6HMx26IkkpNRDoefDG7pHQRX1xWJnG2XOkevMtTQzsa Rk0sFS7NkeEYWUdVLn7Kh6Z0+P8TZqYn8rWnbAcxS2B7f2J3j0Mw+hOp++G4cwbmRYPC ADAizUvNeVyMH8QrvU6Qxznt+YXHs2AD7LRIEHjVdQ3pGxle9CY1zQvbvoPmUjRIi3nC pzfW9bsKtza1QIL3LUpF+pAvGTRn9whzKm2uiM3bE/XiXb4xEiLFO+hhf0FHqqlZA/Gu 6D8MGh0u41XRGYyylQWoZF/ki0yAbT+CNhxBtmEhkEFcTuHaohna4EevqWuPT4K2FESE EIhA== 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=Q+Z2vL2u/NaAW7kobK2oeLXFawnJWU2iBXWyjQPQUt8=; b=oOZYwEs4NunVjiw5x+zYcmA37WKrLJQJvFqlMuP/2/cc3IZsbSuMKaQO4cPExf+ZqN Re2O8OKSrpxTeiW0SZpdmeYt6hrC+cV+IZVg5WwtUsGSwwub55XPnPNFuNYSdhoW613r S1BmG8GDsYKmWAI58Rt1fy4VkaBLjMrrtXD/sz3rczg4I3Ff55Yi+R/MgMeZv7KwT0TB lg5lsaPh/4ZSsWno6Z9aEdk+hc7bEplVS38B+a6Z0jN0NeutdvVjerdpeBV1y8DksJKi f+wIHhRy0FB4jAPB/3r7dSzJT+O9EgPTo92HXFWpcdi8WsY0v0ATGsRMBkqO1DEfqISh M/uw== 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 37-v6si1767701ple.599.2018.03.09.16.40.22; Fri, 09 Mar 2018 16:40:36 -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 S933729AbeCJAjb (ORCPT + 99 others); Fri, 9 Mar 2018 19:39:31 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:39594 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933690AbeCJAV3 (ORCPT ); Fri, 9 Mar 2018 19:21:29 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C723310C3; Sat, 10 Mar 2018 00:21:28 +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.9 04/65] tpm_tis: fix potential buffer overruns caused by bit glitches on the bus Date: Fri, 9 Mar 2018 16:18:04 -0800 Message-Id: <20180310001825.268027029@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001824.927996722@linuxfoundation.org> References: <20180310001824.927996722@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jeremy Boone commit 6bb320ca4a4a7b5b3db8c8d7250cc40002046878 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 Tested-by: Jarkko Sakkinen Reviewed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: James Morris Signed-off-by: Greg Kroah-Hartman --- drivers/char/tpm/tpm_tis_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -208,7 +208,8 @@ static int tpm_tis_recv(struct tpm_chip { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); int size = 0; - int expected, status; + int status; + u32 expected; if (count < TPM_HEADER_SIZE) { size = -EIO; @@ -223,7 +224,7 @@ static int tpm_tis_recv(struct tpm_chip } expected = be32_to_cpu(*(__be32 *) (buf + 2)); - if (expected > count) { + if (expected > count || expected < TPM_HEADER_SIZE) { size = -EIO; goto out; }