Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755538AbdCKIsa (ORCPT ); Sat, 11 Mar 2017 03:48:30 -0500 Received: from mga07.intel.com ([134.134.136.100]:30732 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751993AbdCKIsW (ORCPT ); Sat, 11 Mar 2017 03:48:22 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,145,1486454400"; d="scan'208";a="58938860" Date: Sat, 11 Mar 2017 10:48:06 +0200 From: Jarkko Sakkinen To: Jerry Snitselaar Cc: tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Jason Gunthorpe Subject: Re: [PATCH] tpm_crb: check for bad response size Message-ID: <20170311084806.dkl6w3gjuwawlau4@intel.com> References: <20170311004604.4442-1-jsnitsel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170311004604.4442-1-jsnitsel@redhat.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.6.2-neo (2016-08-21) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1089 Lines: 33 On Fri, Mar 10, 2017 at 05:46:04PM -0700, Jerry Snitselaar wrote: > Make sure size of response buffer is at least 6 bytes, or > we will underflow and pass large size_t to memcpy_fromio(). > This was encountered while testing earlier version of > locality patchset. > > Fixes: 30fc8d138e912 ("tpm: TPM 2.0 CRB Interface") > Signed-off-by: Jerry Snitselaar Reviewed-by: Jarkko Sakkinen /Jarkko > --- > drivers/char/tpm/tpm_crb.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c > index 89dc8a176ff1..cda4f312d1c9 100644 > --- a/drivers/char/tpm/tpm_crb.c > +++ b/drivers/char/tpm/tpm_crb.c > @@ -236,7 +236,7 @@ static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count) > > memcpy_fromio(buf, priv->rsp, 6); > expected = be32_to_cpup((__be32 *) &buf[2]); > - if (expected > count) > + if (expected > count || expected < 6) > return -EIO; > > memcpy_fromio(&buf[6], &priv->rsp[6], expected - 6); > -- > 2.11.0.258.ge05806da9 >