Received: by 10.223.185.111 with SMTP id b44csp900015wrg; Fri, 9 Mar 2018 16:22:12 -0800 (PST) X-Google-Smtp-Source: AG47ELuw9So4pPiCCiavOnL0xCqajpzKxa2HxreVUFN6fdAX+W0uaGCHRWrxRs2caP9erL9rNUco X-Received: by 2002:a17:902:7294:: with SMTP id d20-v6mr321288pll.43.1520641332454; Fri, 09 Mar 2018 16:22:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520641332; cv=none; d=google.com; s=arc-20160816; b=u4h/3lZX6sarHRleOGXl1Fcb9LRMI6Ef92atutqfoIDyo3jAwCW3aJQ2e1aBhQ7UHh 5xIzlvhtXRbWry9xRxgXe4cwRKyi0hO6ihZZ8jlB60XdL2yHUPvVcuWNuG3MStCLWpuE A6L78eo99M2/eE8UhhGX3QDqh0QAplYwga6vLo6Ut01ILJFFT/PNAtNa1104dCMYswMo gb55Uy3Rk4gFDy5BlNqim81ex++Ea/xj6VKL+4teM8voFLm2B1Qyj4YSHxCP1ts1sV+G ITdE+r9S7HA6u2mgltLrtSK24CXpGUU8uhdAPytyV7h0c2W3F6xwCtXOk3bfldjbGcnX 659Q== 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=Va09WJsaxsQQkmW8/BoYpbmGhQCopeXEQQdeG17U9jU=; b=lFEMkYVO9RGyCobdD0zFBUJdhuYj/9n9z7QHbMGM4KP6eTlngKyoqmZUQRQzOpq8K5 SC1cTcC8E6p4J8jBkyujE3b2T/TL27ORQ1RpNZKX89oFdX8yhzeoIa5Xa/Us0ttUSoVp HaNQxLTYfgpyn4bM4YkoO55DjeDm+67gMxeefFcKGQ3laLl0NvmcYE+kWNdWn9P15dYO I4SugUH/sAS36fzd+3n71phsX8kMXbc3x/582nfOhVPCec9xvto+L44ygpBc1S9tGmfc Ga1mBzx1auk295v/WTRT+h9/p0+53jlVee58cLVsBTOAUfX/hYCO53y9bQzlZZTgvc/O Jssw== 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 u1si1477796pgp.498.2018.03.09.16.21.57; Fri, 09 Mar 2018 16:22:12 -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 S933578AbeCJAU7 (ORCPT + 99 others); Fri, 9 Mar 2018 19:20:59 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:39350 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933544AbeCJAU4 (ORCPT ); Fri, 9 Mar 2018 19:20:56 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 17A50FC3; Sat, 10 Mar 2018 00:20:55 +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 01/65] tpm: st33zp24: fix potential buffer overruns caused by bit glitches on the bus Date: Fri, 9 Mar 2018 16:18:01 -0800 Message-Id: <20180310001825.054746800@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 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 6d24cd186d9fead3722108dec1b1c993354645ff 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/st33zp24/st33zp24.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/char/tpm/st33zp24/st33zp24.c +++ b/drivers/char/tpm/st33zp24/st33zp24.c @@ -458,7 +458,7 @@ static int st33zp24_recv(struct tpm_chip size_t count) { int size = 0; - int expected; + u32 expected; if (!chip) return -EBUSY; @@ -475,7 +475,7 @@ static int st33zp24_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; }