Received: by 10.213.65.68 with SMTP id h4csp222148imn; Fri, 23 Mar 2018 03:14:18 -0700 (PDT) X-Google-Smtp-Source: AG47ELujrTVqtGrcKGrjO1aV/7OdGHAaFA2xuUFRU+k4p2AZZw31OCYmHeHGIZHnw0pXUDkmNp3s X-Received: by 10.99.2.202 with SMTP id 193mr11241829pgc.117.1521800058576; Fri, 23 Mar 2018 03:14:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521800058; cv=none; d=google.com; s=arc-20160816; b=atR8XD2fTcIEiMnMOyoCpIBRaLgXCqsGWDVYeEqmJNb+EeTr7Ony+1i4s31KOQ39Mf i1egEUxaTefZi3oaUQKtulkshzpl8edof95QWT6aV6MbgRG+JzvYVPZp0TtIoV0xpHrj eJX6Rn6H18xsL2CZiPTNhiEWjGAg6HxnuNlG+NjiqIRAwgDkl6AfGabYltHyAPZiRIVx 5g+Tjd2B/wv2EsCRzjflK7+DjpRGj028QX2UPX0QREF/1dXTqEd/+EInDwFgEtKv10GX dUVrI02flyXFfAC1M1V5d1U6y5Amnpp5eH59azP+zs58gn2TVza/T81Y6TOE3adoyQ2Q 7+mA== 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=cZMVUCn0AfbNwtCJcM16ZjVQYJrjcGecBrgMS3KtoEY=; b=JoGfr7OhAs/Dnl+rOkcnAzM6TLIYnfFLZUzsttBVc4nqgjBwn0Awu+answcZRyd+GJ GHAN4lh4NcKT4uoZv0GdSY/pA5qG+tbGy8/OI/yl2nWBVZ2gAbHqGSxOO4Dcr7bP9L7Q vI8w/Hd+xqsB23PKFRYPEvZFJf6UAtb1pAhfLB310AQxt83lk/t7aTlVC1YSkR9xZKmI UJfGsQ+rPJaCOlkdd4YI9vdLwuY9vPRMkphF4/IAciHjURA05Y9lD9nnKRZ874QeBe+H iWV/QpshoyR9ZwIVyPVCLMOpGEKWo04xv4c42DMX8vzGBEG4oFNHeq7/zVn1I7Q0XKdC 2HzA== 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 w6si2285312pfw.400.2018.03.23.03.14.04; Fri, 23 Mar 2018 03:14:18 -0700 (PDT) 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 S1755766AbeCWKNG (ORCPT + 99 others); Fri, 23 Mar 2018 06:13:06 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44542 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752413AbeCWKM7 (ORCPT ); Fri, 23 Mar 2018 06:12:59 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 39CB711BF; Fri, 23 Mar 2018 10:12:58 +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.4 01/97] tpm: fix potential buffer overruns caused by bit glitches on the bus Date: Fri, 23 Mar 2018 10:53:48 +0100 Message-Id: <20180323094157.619109611@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094157.535925724@linuxfoundation.org> References: <20180323094157.535925724@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.4-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 | 5 +++++ drivers/char/tpm/tpm2-cmd.c | 6 ++++++ 2 files changed, 11 insertions(+) --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -1040,6 +1040,11 @@ 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; + } + memcpy(dest, tpm_cmd.params.getrandom_out.rng_data, recd); dest += recd; --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -622,6 +622,11 @@ 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; + } + data = &buf.data[TPM_HEADER_SIZE + 6]; memcpy(payload->key, data, data_len - 1); @@ -629,6 +634,7 @@ static int tpm2_unseal_cmd(struct tpm_ch payload->migratable = data[data_len - 1]; } +out: tpm_buf_destroy(&buf); return rc; }