Received: by 10.223.185.116 with SMTP id b49csp5502193wrg; Wed, 7 Mar 2018 12:56:07 -0800 (PST) X-Google-Smtp-Source: AG47ELtpGeMDYA6K1ZkbtOCrN14EJiu8f0YcI0WGSjUhrvfFQh78FeYNIQ4O8OdgRrWKcg5VB2Ng X-Received: by 10.98.19.146 with SMTP id 18mr24041154pft.3.1520456167708; Wed, 07 Mar 2018 12:56:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520456167; cv=none; d=google.com; s=arc-20160816; b=RuHisZ1kAPQn3snWCDBKI5YlCyIbLGLlAzyz6pRQdH7OJJpyrIWqSWiDfThRzSxme/ ZF1/LZ9LMkNCVtfSfEoDMgHRG4KcWUAq0ZxuMZ1iKRjIwIbA3UhVnp84KpRZe5RF4iKH QzvBpxCTWWsdn68l3wrPtGpbKpylwT4C/vjFaJPzh5s1P6GA5CqNB9FJ9qX+YC+8kkx3 KU7Uw0TLkowrIRhnplrZJQ+Vni/PP2QWZ+fU7np0Lr7vAX8O3wIElzzFQHrB1PPWaIJL 0E1L7Ah0RYGbzpZ9sUqq3fGuP1vywikiDK7LDJmFWy2vTAyVNmhESvvLIFHyQXJgDoWH dLLg== 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=ShfvcTMy72EHezh7Hs3sOTNHUYQP7nypYbz/tCGgCtc=; b=ysVFXADJkuStR3nyHNB1k8SUmqjXZd1aI0+klqUMvq0M8DQZCDpGOga1L8xwCtMprU vhPfszua8SqymT/8XuneRlourDgbcLytAmMKODVVDxo1GJmecK8rEV8xRsV9tCR0/BB4 jOtocuvy+0DgWLGJ7y88tnGzV1S9Y95wZsKEheHPWjFgQX6CeC5biDNdZ0YKcni1GJnq W2qijuJikMC9Noeq5JzzoVwXK48yBj1fV4dFqDJJfdp0Jy+cmNyQaCk+CSdmB8jnzNle AXXu8/w7cKuc/PMj4VlJJKa1R3ht9S+DwY6BTT2quHQvjYdeu6xvhCCgT1+g1N2/PF8H UqzQ== 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 c16si11821895pgv.729.2018.03.07.12.55.53; Wed, 07 Mar 2018 12:56:07 -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 S934089AbeCGTjt (ORCPT + 99 others); Wed, 7 Mar 2018 14:39:49 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40324 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933935AbeCGTjp (ORCPT ); Wed, 7 Mar 2018 14:39:45 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BFD25F10; Wed, 7 Mar 2018 19:39:44 +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 011/122] tpm_i2c_nuvoton: fix potential buffer overruns caused by bit glitches on the bus Date: Wed, 7 Mar 2018 11:37:03 -0800 Message-Id: <20180307191730.829757514@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 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 @@ -281,7 +281,11 @@ static int i2c_nuvoton_recv(struct tpm_c struct device *dev = chip->dev.parent; 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 */ @@ -323,7 +327,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;