linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Garrett <matthewgarrett@google.com>
To: linux-integrity@vger.kernel.org
Cc: peterhuewe@gmx.de, jarkko.sakkinen@linux.intel.com, jgg@ziepe.ca,
	roberto.sassu@huawei.com, linux-efi@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org, tweek@google.com,
	Matthew Garrett <matthewgarrett@google.com>,
	Matthew Garrett <mjg59@google.com>
Subject: [PATCH 2/2] tpm: Fix builds on platforms that lack early_memremap()
Date: Tue,  2 Apr 2019 14:55:56 -0700	[thread overview]
Message-ID: <20190402215556.257406-3-matthewgarrett@google.com> (raw)
In-Reply-To: <20190402215556.257406-1-matthewgarrett@google.com>

On EFI systems, __calc_tpm2_event_size() needs to be able to map tables
at early boot time in order to extract information from them.
Unfortunately this interacts badly with other architectures that don't
provide the early_memremap() interface but which may still have other
mechanisms for obtaining crypto-agile logs. Abstract this away so we
can avoid the need for two implementations while still avoiding breakage
on architectures that don't require remapping of the table.

Signed-off-by: Matthew Garrett <mjg59@google.com>
---
 drivers/firmware/efi/tpm.c   |  3 +++
 include/linux/tpm_eventlog.h | 32 ++++++++++++++++++++------------
 2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
index f2a13cbb8688..fe48150f06d1 100644
--- a/drivers/firmware/efi/tpm.c
+++ b/drivers/firmware/efi/tpm.c
@@ -4,6 +4,9 @@
  *     Thiebaud Weksteen <tweek@google.com>
  */
 
+#define TPM_MEMREMAP(start, size) early_memremap(start, size)
+#define TPM_MEMUNMAP(start, size) early_memunmap(start, size)
+
 #include <linux/efi.h>
 #include <linux/init.h>
 #include <linux/memblock.h>
diff --git a/include/linux/tpm_eventlog.h b/include/linux/tpm_eventlog.h
index d889e12047d9..0ca27bc053af 100644
--- a/include/linux/tpm_eventlog.h
+++ b/include/linux/tpm_eventlog.h
@@ -128,6 +128,14 @@ struct tcg_algorithm_info {
 	struct tcg_algorithm_size digest_sizes[];
 };
 
+#ifndef TPM_MEMREMAP
+#define TPM_MEMREMAP(start, size) NULL
+#endif
+
+#ifndef TPM_MEMUNMAP
+#define TPM_MEMUNMAP(start, size) do{} while(0)
+#endif
+
 /**
  * __calc_tpm2_event_size - calculate the size of a TPM2 event log entry
  * @event:        Pointer to the event whose size should be calculated
@@ -171,8 +179,8 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
 	/* Map the event header */
 	if (do_mapping) {
 		mapping_size = marker - marker_start;
-		mapping = early_memremap((unsigned long)marker_start,
-					 mapping_size);
+		mapping = TPM_MEMREMAP((unsigned long)marker_start,
+				       mapping_size);
 		if (!mapping) {
 			size = 0;
 			goto out;
@@ -192,10 +200,10 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
 
 		/* Map the digest's algorithm identifier */
 		if (do_mapping) {
-			early_memunmap(mapping, mapping_size);
+			TPM_MEMUNMAP(mapping, mapping_size);
 			mapping_size = marker - marker_start + halg_size;
-			mapping = early_memremap((unsigned long)marker_start,
-						 mapping_size);
+			mapping = TPM_MEMREMAP((unsigned long)marker_start,
+					       mapping_size);
 			if (!mapping) {
 				size = 0;
 				goto out;
@@ -212,10 +220,10 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
 
 				/* Map the digest content itself */
 				if (do_mapping) {
-					early_memunmap(mapping, mapping_size);
+					TPM_MEMUNMAP(mapping, mapping_size);
 					mapping_size = marker - marker_start;
-					mapping = early_memremap((unsigned long)marker_start,
-						      mapping_size);
+					mapping = TPM_MEMREMAP((unsigned long)marker_start,
+							       mapping_size);
 					if (!mapping) {
 						size = 0;
 						goto out;
@@ -238,10 +246,10 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
 	 * we don't need to map it
 	 */
 	if (do_mapping) {
-		early_memunmap(marker_start, mapping_size);
+		TPM_MEMUNMAP(marker_start, mapping_size);
 		mapping_size += sizeof(event_field->event_size);
-		mapping = early_memremap((unsigned long)marker_start,
-					 mapping_size);
+		mapping = TPM_MEMREMAP((unsigned long)marker_start,
+				       mapping_size);
 		if (!mapping) {
 			size = 0;
 			goto out;
@@ -256,7 +264,7 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
 		size = 0;
 out:
 	if (do_mapping)
-		early_memunmap(mapping, mapping_size);
+		TPM_MEMUNMAP(mapping, mapping_size);
 	return size;
 }
 
-- 
2.21.0.392.gf8f6787159e-goog


  parent reply	other threads:[~2019-04-02 21:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-02 21:55 [PATCH] TCG2 log support build fixes for non-x86_64 Matthew Garrett
2019-04-02 21:55 ` [PATCH 1/2] efi: Fix cast to pointer from integer of different size in TPM log code Matthew Garrett
2019-04-03 13:42   ` David Laight
2019-04-03 16:51     ` Matthew Garrett
2019-04-04 12:39   ` Jarkko Sakkinen
2019-04-04 12:54   ` Ard Biesheuvel
2019-04-04 17:23     ` Matthew Garrett
2019-04-02 21:55 ` Matthew Garrett [this message]
2019-04-04 12:40   ` [PATCH 2/2] tpm: Fix builds on platforms that lack early_memremap() Jarkko Sakkinen
2019-04-04 12:40 ` [PATCH] TCG2 log support build fixes for non-x86_64 Jarkko Sakkinen
2019-04-04 17:24   ` Matthew Garrett
2019-04-15  8:47 ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190402215556.257406-3-matthewgarrett@google.com \
    --to=matthewgarrett@google.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mjg59@google.com \
    --cc=peterhuewe@gmx.de \
    --cc=roberto.sassu@huawei.com \
    --cc=tweek@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).