Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp694300ybt; Fri, 26 Jun 2020 09:17:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9nNeXeBximZxqPzGuV1t7bXEUqV3Fml2NYTaZSLiXYXdoRfhpU0rlJXShupFil1nmP+sK X-Received: by 2002:a50:f7c2:: with SMTP id i2mr4020530edn.19.1593188229356; Fri, 26 Jun 2020 09:17:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593188229; cv=none; d=google.com; s=arc-20160816; b=bLTc7DIDMspBDT1LhjAp990o3lpJ7iXEWWofxbL5D5Z5k+xdM4wa98FdOs0GGQ20XV sQlXr+pbXmoXuvyWHK+6/9CWjI8k2XY9jzpsKEAIqwxEeANXrgUrbR6RV+FpHS+sdAgT qc8qtBfnAZHzSMuDrJHlojwX/CZyB6coRKoRrwHYLgy+Rjev+EWrQLLPDtttgHEBJzpW mU5xcz435ynx0In0wknGPYrjfK99RH9QiHL8OpXm/HAkVbhaAFxc2dgby5AG8tXaROOC poG+iliSfzVV3f2BcnugHS2IcO0Jf0pw+7wlwq4B5x5NoRxdtg1rwiJg327/yGjDXFrg l83Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=szG0/eegs/uNx6l/xILpDjB4eix48PNt9qbBjWbObl4=; b=jz2CVXKfqPdGxPOdvAfEBBs3gbTtJ82BE5f7GIdgXWV4Ywjh+NFVLCWodeo41HhzQa i3fK+hPANINWZGYE3R3ym3Ud4pTWyrS4F0yZNNxYJ0q4qJ1g0PrWhXaEQKLNEaeud32k mvbW9onxxTziOuVLEXcgon8+2HSocZtE2zsE9/8nK9xp/Nsmqv36l5wgHvPN9xcHUokr v9a7cK2bdqfjevycITwT2on5ZKSKsiFKwSCNEkcE21mR8oLK+5UXiz0+Hgh76CAIaK6B ZsiWZJuMrR3m32GTEpt9Uc+95gO/8W+L7U/zAptdpOiVFjGoTT1AeCmp75E9t4OtlIW2 8eMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c5si12437234edf.7.2020.06.26.09.16.46; Fri, 26 Jun 2020 09:17:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729122AbgFZOeo (ORCPT + 99 others); Fri, 26 Jun 2020 10:34:44 -0400 Received: from mga17.intel.com ([192.55.52.151]:45202 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726393AbgFZOeo (ORCPT ); Fri, 26 Jun 2020 10:34:44 -0400 IronPort-SDR: G3DGm09CveZ+FRfIXAQHdLZZ3pE/R1QmJgfjFX440THoGOA01xv2bYBbbbGI3NRwWLy67gkNQf O0b5qUnX20/g== X-IronPort-AV: E=McAfee;i="6000,8403,9663"; a="125543201" X-IronPort-AV: E=Sophos;i="5.75,284,1589266800"; d="scan'208";a="125543201" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jun 2020 07:34:43 -0700 IronPort-SDR: hvr2GwvSgu67UN13TX3i1cx6xPeuqscnnbTFJUQtLl8I/4XRPZUo8yycMk+bABaIixayDn61GU np7qqGSSD24w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,284,1589266800"; d="scan'208";a="265639847" Received: from cgheban-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.199]) by fmsmga008.fm.intel.com with ESMTP; 26 Jun 2020 07:34:38 -0700 From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: Jarkko Sakkinen , Stefan Berger , stable@vger.kernel.org, Peter Huewe , Jason Gunthorpe , Arnd Bergmann , Greg Kroah-Hartman , James Bottomley , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] tpm: Define TPM2_SPACE_BUFFER_SIZE to replace the use of PAGE_SIZE Date: Fri, 26 Jun 2020 17:34:35 +0300 Message-Id: <20200626143436.396889-1-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The size of the buffers for storing context's and sessions can vary from arch to arch as PAGE_SIZE can be anything between 4 kB and 256 kB (the maximum for PPC64). Define a fixed buffer size set to 16 kB. This should be enough for most use with three handles (that is how many we allow at the moment). Reported-by: Stefan Berger Cc: stable@vger.kernel.org Fixes: 745b361e989a ("tpm: infrastructure for TPM spaces") Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm2-space.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c index 982d341d8837..9bef646093d1 100644 --- a/drivers/char/tpm/tpm2-space.c +++ b/drivers/char/tpm/tpm2-space.c @@ -15,6 +15,8 @@ #include #include "tpm.h" +#define TPM2_SPACE_BUFFER_SIZE 16384 /* 16 kB */ + enum tpm2_handle_types { TPM2_HT_HMAC_SESSION = 0x02000000, TPM2_HT_POLICY_SESSION = 0x03000000, @@ -40,11 +42,11 @@ static void tpm2_flush_sessions(struct tpm_chip *chip, struct tpm_space *space) int tpm2_init_space(struct tpm_space *space) { - space->context_buf = kzalloc(PAGE_SIZE, GFP_KERNEL); + space->context_buf = kzalloc(TPM2_SPACE_BUFFER_SIZE, GFP_KERNEL); if (!space->context_buf) return -ENOMEM; - space->session_buf = kzalloc(PAGE_SIZE, GFP_KERNEL); + space->session_buf = kzalloc(TPM2_SPACE_BUFFER_SIZE, GFP_KERNEL); if (space->session_buf == NULL) { kfree(space->context_buf); return -ENOMEM; @@ -311,8 +313,10 @@ int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u8 *cmd, sizeof(space->context_tbl)); memcpy(&chip->work_space.session_tbl, &space->session_tbl, sizeof(space->session_tbl)); - memcpy(chip->work_space.context_buf, space->context_buf, PAGE_SIZE); - memcpy(chip->work_space.session_buf, space->session_buf, PAGE_SIZE); + memcpy(chip->work_space.context_buf, space->context_buf, + TPM2_SPACE_BUFFER_SIZE); + memcpy(chip->work_space.session_buf, space->session_buf, + TPM2_SPACE_BUFFER_SIZE); rc = tpm2_load_space(chip); if (rc) { @@ -492,8 +496,8 @@ static int tpm2_save_space(struct tpm_chip *chip) continue; rc = tpm2_save_context(chip, space->context_tbl[i], - space->context_buf, PAGE_SIZE, - &offset); + space->context_buf, + TPM2_SPACE_BUFFER_SIZE, &offset); if (rc == -ENOENT) { space->context_tbl[i] = 0; continue; @@ -509,9 +513,8 @@ static int tpm2_save_space(struct tpm_chip *chip) continue; rc = tpm2_save_context(chip, space->session_tbl[i], - space->session_buf, PAGE_SIZE, - &offset); - + space->session_buf, + TPM2_SPACE_BUFFER_SIZE, &offset); if (rc == -ENOENT) { /* handle error saving session, just forget it */ space->session_tbl[i] = 0; @@ -557,8 +560,10 @@ int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space, sizeof(space->context_tbl)); memcpy(&space->session_tbl, &chip->work_space.session_tbl, sizeof(space->session_tbl)); - memcpy(space->context_buf, chip->work_space.context_buf, PAGE_SIZE); - memcpy(space->session_buf, chip->work_space.session_buf, PAGE_SIZE); + memcpy(space->context_buf, chip->work_space.context_buf, + TPM2_SPACE_BUFFER_SIZE); + memcpy(space->session_buf, chip->work_space.session_buf, + TPM2_SPACE_BUFFER_SIZE); return 0; out: -- 2.25.1