From patchwork Sun Sep 11 12:19:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 668432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sX93T2NtPz9s9x for ; Sun, 11 Sep 2016 22:19:17 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bj3j7-000802-O0; Sun, 11 Sep 2016 12:19:13 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bj3j6-0007zx-Pp for tpmdd-devel@lists.sourceforge.net; Sun, 11 Sep 2016 12:19:12 +0000 X-ACL-Warn: Received: from mga07.intel.com ([134.134.136.100]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1bj3j5-0000sq-R0 for tpmdd-devel@lists.sourceforge.net; Sun, 11 Sep 2016 12:19:12 +0000 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP; 11 Sep 2016 05:19:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,316,1470726000"; d="scan'208";a="7233717" Received: from solender-mobl.ger.corp.intel.com (HELO localhost) ([10.252.10.160]) by orsmga005.jf.intel.com with ESMTP; 11 Sep 2016 05:19:03 -0700 From: Jarkko Sakkinen To: Peter Huewe Date: Sun, 11 Sep 2016 15:19:00 +0300 Message-Id: <1473596340-11376-1-git-send-email-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.7.4 X-Spam-Score: -1.7 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -2.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 0.5 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1bj3j5-0000sq-R0 Cc: "moderated list:TPM DEVICE DRIVER" , open list Subject: [tpmdd-devel] [PATCH] tpm: fix buffer overflow in /dev/tpm0 X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net 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 --- 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;