From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755792AbcIKMvs (ORCPT ); Sun, 11 Sep 2016 08:51:48 -0400 Received: from mga14.intel.com ([192.55.52.115]:28189 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755007AbcIKMvr (ORCPT ); Sun, 11 Sep 2016 08:51:47 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,317,1470726000"; d="scan'208";a="877530583" Date: Sun, 11 Sep 2016 15:51:42 +0300 From: Jarkko Sakkinen To: Peter Huewe Cc: Marcel Selhorst , Jason Gunthorpe , "moderated list:TPM DEVICE DRIVER" , open list Subject: Re: [PATCH] tpm: fix buffer overflow in /dev/tpm0 Message-ID: <20160911125142.GA20191@intel.com> References: <1473596340-11376-1-git-send-email-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1473596340-11376-1-git-send-email-jarkko.sakkinen@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 11, 2016 at 03:19:00PM +0300, Jarkko Sakkinen wrote: > tpm_write() does not check whether the buffer has at least enough space > for the header before passing it to tpm_transmit() so an overflow can > happen. > > Signed-off-by: Jarkko Sakkinen This is usable neither as read nor write primitive for an exploit. Still it makes sense to validate the input here. /Jarkko > --- > drivers/char/tpm/tpm-interface.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c > index fd863ff..6a67f7f 100644 > --- a/drivers/char/tpm/tpm-interface.c > +++ b/drivers/char/tpm/tpm-interface.c > @@ -337,6 +337,9 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz, > u32 count, ordinal; > unsigned long stop; > > + if (bufsiz < TPM_HEADER_SIZE) > + return -EINVAL; > + > if (bufsiz > TPM_BUFSIZE) > bufsiz = TPM_BUFSIZE; > > -- > 2.7.4 >