Received: by 10.223.185.111 with SMTP id b44csp920538wrg; Fri, 9 Mar 2018 16:54:34 -0800 (PST) X-Google-Smtp-Source: AG47ELsKttzggnaWtjNb9aqCFfHYdsA9FRjslxuLZ1FZF1G/nNztttVjmim4gPXRnf6I+BdkAMeF X-Received: by 10.99.116.28 with SMTP id p28mr335134pgc.306.1520643274600; Fri, 09 Mar 2018 16:54:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520643274; cv=none; d=google.com; s=arc-20160816; b=TlSVXiiZ56z98hVCSytqQZfRwhFaQXMWggmxzQKYuh/m5foE0kgl3Y0zp7UAmJueL3 kevwGdGsa7aDx+F7Cn/8lS7GhYjPB4KhZL0TbU9SBQ4Cs9/aSmIaZr6w0Y12sCaIcnLe D5t2251Jko9XjQWSfhNjocAWoHjUEPo+uVyFeNg6aevrukbGepaHX8jNgcb7npR4zxzC x1xAuwfa7Vx1Q6E7sPpN1K1EAco0MQDgy+58+jq8a3wjQTK04L/AE7gtwM5MrWsH2u9D dj89KlHI0Z6D/LPnbGmg8EVtgEgsSQTxK63Wwu4L+mDnZClliOp6TuQWT1da875u3OuV fP0w== 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=VxFTtUp+CRN7U9x0c6GMkQPa7CufQXJoTB/8uLOnDW0=; b=1AX2I1v0bTj3WTQH53cCYIxEGYlZDVFCxWql9HVS8ekHvQRr34XwMdyakv3XD2W6tk I+53pU/7iMk34AGFfbr5F/oBbDV8f3CED46JhnywHewer4LGcjqqvKUOlY21aH/Sbocs refW1/XNz8MOX7mNbrhdqEUi2YFQLhv7vnB2vaYEjy0kQ1yLBFAZ/0F8KlThkYi52arI bHuaej5XeZdpvm5aYB3fePJnPDx2urR6CmtHmH8V0v8JYGO0NKLt8ND0meZ0tU6bkJwH wo13b/ibCqGrpriED2ZWC6BrARDeSbjFahTVzJzYOSvGO7zmjVkWovHkOvfLwk/Ly+Mi kVhA== 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 i70si1551400pgc.86.2018.03.09.16.54.20; Fri, 09 Mar 2018 16:54:34 -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 S932835AbeCJAS7 (ORCPT + 99 others); Fri, 9 Mar 2018 19:18:59 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:38428 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751325AbeCJAS5 (ORCPT ); Fri, 9 Mar 2018 19:18:57 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B18CBE6A; Sat, 10 Mar 2018 00:18:56 +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 3.18 02/21] tpm_i2c_nuvoton: fix potential buffer overruns caused by bit glitches on the bus Date: Fri, 9 Mar 2018 16:18:24 -0800 Message-Id: <20180310001801.206082552@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001801.045114869@linuxfoundation.org> References: <20180310001801.045114869@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 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jeremy Boone commit f9d4d9b5a5ef2f017bc344fb65a58a902517173b 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_nuvoton.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/drivers/char/tpm/tpm_i2c_nuvoton.c +++ b/drivers/char/tpm/tpm_i2c_nuvoton.c @@ -267,7 +267,11 @@ static int i2c_nuvoton_recv(struct tpm_c struct device *dev = chip->dev; struct i2c_client *client = to_i2c_client(dev); s32 rc; - int expected, status, burst_count, retries, size = 0; + int status; + int burst_count; + int retries; + int size = 0; + u32 expected; if (count < TPM_HEADER_SIZE) { i2c_nuvoton_ready(chip); /* return to idle */ @@ -309,7 +313,7 @@ static int i2c_nuvoton_recv(struct tpm_c * to machine native */ expected = be32_to_cpu(*(__be32 *) (buf + 2)); - if (expected > count) { + if (expected > count || expected < size) { dev_err(dev, "%s() expected > count\n", __func__); size = -EIO; continue;