From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756747AbcILHvG (ORCPT ); Mon, 12 Sep 2016 03:51:06 -0400 Received: from mga06.intel.com ([134.134.136.31]:25910 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755992AbcILHvE (ORCPT ); Mon, 12 Sep 2016 03:51:04 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,321,1470726000"; d="scan'208";a="7736732" Date: Mon, 12 Sep 2016 10:50:57 +0300 From: Jarkko Sakkinen To: Jason Gunthorpe Cc: Peter Huewe , Marcel Selhorst , "moderated list:TPM DEVICE DRIVER" , open list Subject: Re: [PATCH] tpm: fix buffer overflow in /dev/tpm0 Message-ID: <20160912075057.GA5094@intel.com> References: <1473596340-11376-1-git-send-email-jarkko.sakkinen@linux.intel.com> <20160912040546.GA14625@obsidianresearch.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160912040546.GA14625@obsidianresearch.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 10:05:46PM -0600, Jason Gunthorpe wrote: > 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. > > Eh? > > tpm_write uses a hard wired buffer size of TPM_BUFSIZE when working > with tpm_transmit. > > in_size is never used except for the copy. We should probably fix that > to sanity check the header length vs in_size. > > That doesn't seem to be a security issue however because the header > length is propery limited to TPM_BUFSIZE and the data buffer is > allocated specifically for that process using kzalloc. I was working on something else when I bumped into this. The commit message is not the best possible but still the issue is valid although it does not cause any imaginable harm because there is always TPM_BUFSIZE of room in the buffer passed by tpm_write. I'll update the commit message not to speak about tpm_write. "tpm_transmit() does not check whether the bufsiz can contain the TPM header. Add check for this and return -EINVAL if it the buffer is too small." The check should be in tpm_transmit() and also the commit message should be only about that. > Jason /Jarkko