From patchwork Tue Jun 20 09:38:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 9799059 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BACA360329 for ; Tue, 20 Jun 2017 09:38:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AED8426B41 for ; Tue, 20 Jun 2017 09:38:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3C15283A6; Tue, 20 Jun 2017 09:38:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3616626B41 for ; Tue, 20 Jun 2017 09:38:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dNFcF-0005Qr-Jz; Tue, 20 Jun 2017 09:38:31 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1dNFcB-0005Qf-SJ for tpmdd-devel@lists.sourceforge.net; Tue, 20 Jun 2017 09:38:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=yQGpJPe8GKc24jWldORdMKtWXOSO5jIzYMtbCUxhFL4=; b=UbW8TPCN2gm9lNIeleZsME6TcYlaQXnY67hHOvYSfiQEbvLq5TaEnmqEpwkZxX9UPdqtnlvqj5RUShgS1SomuxsVt2eNCiUWqS/iXqVoWD/YhnIADFHsc7iD+Aov6s4Ya6/aXHlapP6NcHmBRnGpIlP0VsEm71eHan88h8Xg8Vw=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=yQGpJPe8GKc24jWldORdMKtWXOSO5jIzYMtbCUxhFL4=; b=FHMMJlrZWTKRI0C/pMP0XclXtUklo6UVxssTqCVX7ERF6u6epu3pEgQjzej0IEFTLVAuwhjzW/CVX5I94tla47aaxrtGbN+rDNHJmvSuAGXGEVlNSejD7TrMCCTsYoKvrTnFS9sqBJGcRqjDvV3jAlBrGFTjuhH6g/W65ScsLMY=; X-ACL-Warn: Received: from mga02.intel.com ([134.134.136.20]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1dNFc9-0002uv-SH for tpmdd-devel@lists.sourceforge.net; Tue, 20 Jun 2017 09:38:27 +0000 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Jun 2017 02:38:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,364,1493708400"; d="scan'208";a="116535941" Received: from yargotti-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.1.138]) by fmsmga005.fm.intel.com with ESMTP; 20 Jun 2017 02:38:16 -0700 From: Jarkko Sakkinen To: tpmdd-devel@lists.sourceforge.net Date: Tue, 20 Jun 2017 11:38:02 +0200 Message-Id: <20170620093804.23803-2-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170620093804.23803-1-jarkko.sakkinen@linux.intel.com> References: <20170620093804.23803-1-jarkko.sakkinen@linux.intel.com> X-Headers-End: 1dNFc9-0002uv-SH Subject: [tpmdd-devel] [PATCH 1/2] tpm: fix a kernel memory leak in tpm-sysfs.c X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: srajiv@linux.vnet.ibm.com, open list , stable@vger.kernel.org, linux-security-module@vger.kernel.org MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP While cleaning up sysfs callback that prints EK we discovered a kernel memory leak. This commit fixes the issue by zeroing the buffer used for TPM command/response. The leak happen when we use either tpm_vtpm_proxy, tpm_ibmvtpm or xen-tpmfront. Cc: stable@vger.kernel.org Fixes: 0883743825e3 ("TPM: sysfs functions consolidation") Reported-by: Jason Gunthorpe Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm-sysfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c index 4bd0997cfa2d..eedb8e47bde2 100644 --- a/drivers/char/tpm/tpm-sysfs.c +++ b/drivers/char/tpm/tpm-sysfs.c @@ -36,9 +36,10 @@ static ssize_t pubek_show(struct device *dev, struct device_attribute *attr, ssize_t err; int i, rc; char *str = buf; - struct tpm_chip *chip = to_tpm_chip(dev); + memset(&tpm_cmd, 0, sizeof(tpm_cmd)); + tpm_cmd.header.in = tpm_readpubek_header; err = tpm_transmit_cmd(chip, NULL, &tpm_cmd, READ_PUBEK_RESULT_SIZE, READ_PUBEK_RESULT_MIN_BODY_SIZE, 0,