Received: by 10.223.185.116 with SMTP id b49csp5469347wrg; Wed, 7 Mar 2018 12:17:52 -0800 (PST) X-Google-Smtp-Source: AG47ELt/WVYmK8a9q1ITg6wQRirLf/G9BeQwMsypEchen1Omeri3wK649BgeAsJW/fFKSJgl3uIv X-Received: by 2002:a17:902:467:: with SMTP id 94-v6mr21251966ple.57.1520453872169; Wed, 07 Mar 2018 12:17:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520453872; cv=none; d=google.com; s=arc-20160816; b=bA6qnrIBKsigMA3RMQf0F1yZEZ5w2o3AALu01js2G+Zu7+UFBzHblNcQo2kXPoPyR2 3D2vkwMtMfM9VKiA+tPYz8k1RcHUyA4jW3ukbGFwJuhARk24z+gaysgPxdAg01nQizHP mNjc4KZxcf3LglDa8w88eFqQByJKUJKKGyOKENc/I1l9/jzhEv2XqbaaxE9L+95M3j01 4g193RlmTSqxgF6j2FKbdCzOJM/IQn0KNVkIq/XnX86nhaXdQua8UZNIo6+JWBK3gHOI kkStRf/YphP0La0wqN/vjc6NCTdtfcmg8zZ55yA2jTusvArFowu3Kf7Qu1d9SaNsl1UD 7slA== 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=p/QXb8NcE9HUzzbAKxS9aJds3gWcLERFV4Rbj7cXD4c=; b=ibwSJlOVF1jNVsmreyTy/mfwMHTqmOy4aGWelCswQItZzNBmXdPBQgxF+uz1gBstSo /LMqilUMId0eJ3AZz7wcEyT4n7rD/laW3Kv9Tzp13bxoXtDqEnrvuR/y/Im/qv1TLYsI Lnq54yTrCiS59xpqynlThsoG9XWnATJIYd+rDlfoUoTOLhM2rlLnPHs7P5sLxbIiMrYO G76ZIdt5GvNoKMybhabxz+FFM+q/lTS+zdGFI8h7lL67R+vI7SlxlHS45LSc3H8IWZ9c YssstoWChyFv62AddkGE14CIwiQ/jHQeX1PXL7vDy+7RKLtcRJ54A8Smv/4syRybK4xp tchw== 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 o6-v6si13381414plh.287.2018.03.07.12.17.37; Wed, 07 Mar 2018 12:17:52 -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 S965222AbeCGUQ2 (ORCPT + 99 others); Wed, 7 Mar 2018 15:16:28 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:43856 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965111AbeCGToj (ORCPT ); Wed, 7 Mar 2018 14:44:39 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1D4CBEF7; Wed, 7 Mar 2018 19:44:39 +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.14 004/110] tpm: fix potential buffer overruns caused by bit glitches on the bus Date: Wed, 7 Mar 2018 11:37:47 -0800 Message-Id: <20180307191040.380529457@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191039.748351103@linuxfoundation.org> References: <20180307191039.748351103@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jeremy Boone commit 3be23274755ee85771270a23af7691dc9b3a95db upstream. Discrete TPMs are often connected over slow serial buses which, on some platforms, can have glitches causing bit flips. If a bit does flip it could cause an overrun if it's in one of the size parameters, so sanity check that we're not overrunning the provided buffer when doing a memcpy(). Signed-off-by: Jeremy Boone Cc: stable@vger.kernel.org Signed-off-by: James Bottomley Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: James Morris Signed-off-by: Greg Kroah-Hartman --- drivers/char/tpm/tpm-interface.c | 4 ++++ drivers/char/tpm/tpm2-cmd.c | 4 ++++ 2 files changed, 8 insertions(+) --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -1228,6 +1228,10 @@ int tpm_get_random(u32 chip_num, u8 *out break; recd = be32_to_cpu(tpm_cmd.params.getrandom_out.rng_data_len); + if (recd > num_bytes) { + total = -EFAULT; + break; + } rlength = be32_to_cpu(tpm_cmd.header.out.length); if (rlength < offsetof(struct tpm_getrandom_out, rng_data) + --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -683,6 +683,10 @@ static int tpm2_unseal_cmd(struct tpm_ch if (!rc) { data_len = be16_to_cpup( (__be16 *) &buf.data[TPM_HEADER_SIZE + 4]); + if (data_len < MIN_KEY_SIZE || data_len > MAX_KEY_SIZE + 1) { + rc = -EFAULT; + goto out; + } rlength = be32_to_cpu(((struct tpm2_cmd *)&buf) ->header.out.length);