From patchwork Tue Feb 20 11:41:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 10229811 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 DBB15602DC for ; Tue, 20 Feb 2018 11:41:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAE29285D8 for ; Tue, 20 Feb 2018 11:41:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF866285F2; Tue, 20 Feb 2018 11:41:44 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38C1D285D8 for ; Tue, 20 Feb 2018 11:41:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751402AbeBTLln (ORCPT ); Tue, 20 Feb 2018 06:41:43 -0500 Received: from mga06.intel.com ([134.134.136.31]:35043 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750710AbeBTLln (ORCPT ); Tue, 20 Feb 2018 06:41:43 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Feb 2018 03:41:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,539,1511856000"; d="scan'208";a="18923306" Received: from pavlovix-mobl.ger.corp.intel.com (HELO localhost) ([10.249.254.79]) by fmsmga007.fm.intel.com with ESMTP; 20 Feb 2018 03:41:39 -0800 From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: Nayna Jain , Thiebaud Weksteen , Jarkko Sakkinen , Peter Huewe , Jason Gunthorpe , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2] tpm: use kmemdup() to copy the event log Date: Tue, 20 Feb 2018 13:41:29 +0200 Message-Id: <20180220114129.9300-1-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.14.1 Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replaced kmalloc() + memcpy() in tpm_eventlog_efi.c and tpm_eventlog_of.c. Signed-off-by: Jarkko Sakkinen Reviewed-by: Javier Martinez Canillas --- v2: update also tpm_eventlog_of.c drivers/char/tpm/tpm_eventlog_efi.c | 3 +-- drivers/char/tpm/tpm_eventlog_of.c | 5 +---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/char/tpm/tpm_eventlog_efi.c b/drivers/char/tpm/tpm_eventlog_efi.c index e3f9ffd341d2..57c8b3cc46be 100644 --- a/drivers/char/tpm/tpm_eventlog_efi.c +++ b/drivers/char/tpm/tpm_eventlog_efi.c @@ -50,10 +50,9 @@ int tpm_read_log_efi(struct tpm_chip *chip) } /* malloc EventLog space */ - log->bios_event_log = kmalloc(log_size, GFP_KERNEL); + log->bios_event_log = kmemdup(log_tbl->log, log_size, GFP_KERNEL); if (!log->bios_event_log) goto err_memunmap; - memcpy(log->bios_event_log, log_tbl->log, log_size); log->bios_event_log_end = log->bios_event_log + log_size; tpm_log_version = log_tbl->version; diff --git a/drivers/char/tpm/tpm_eventlog_of.c b/drivers/char/tpm/tpm_eventlog_of.c index 96fd5646f866..c4b1d3049060 100644 --- a/drivers/char/tpm/tpm_eventlog_of.c +++ b/drivers/char/tpm/tpm_eventlog_of.c @@ -68,14 +68,11 @@ int tpm_read_log_of(struct tpm_chip *chip) return -EIO; } - log->bios_event_log = kmalloc(size, GFP_KERNEL); + log->bios_event_log = kmemdup(__va(base), size, GFP_KERNEL); if (!log->bios_event_log) return -ENOMEM; - log->bios_event_log_end = log->bios_event_log + size; - memcpy(log->bios_event_log, __va(base), size); - if (chip->flags & TPM_CHIP_FLAG_TPM2) return EFI_TCG2_EVENT_LOG_FORMAT_TCG_2; return EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;