tpm_eventlog_efi.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (C) 2017 Google
  3. *
  4. * Authors:
  5. * Thiebaud Weksteen <tweek@google.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. *
  12. */
  13. #include <linux/efi.h>
  14. #include <linux/tpm_eventlog.h>
  15. #include "tpm.h"
  16. /* read binary bios log from EFI configuration table */
  17. int tpm_read_log_efi(struct tpm_chip *chip)
  18. {
  19. struct linux_efi_tpm_eventlog *log_tbl;
  20. struct tpm_bios_log *log;
  21. u32 log_size;
  22. u8 tpm_log_version;
  23. if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
  24. return -ENODEV;
  25. if (efi.tpm_log == EFI_INVALID_TABLE_ADDR)
  26. return -ENODEV;
  27. log = &chip->log;
  28. log_tbl = memremap(efi.tpm_log, sizeof(*log_tbl), MEMREMAP_WB);
  29. if (!log_tbl) {
  30. pr_err("Could not map UEFI TPM log table !\n");
  31. return -ENOMEM;
  32. }
  33. log_size = log_tbl->size;
  34. memunmap(log_tbl);
  35. log_tbl = memremap(efi.tpm_log, sizeof(*log_tbl) + log_size,
  36. MEMREMAP_WB);
  37. if (!log_tbl) {
  38. pr_err("Could not map UEFI TPM log table payload!\n");
  39. return -ENOMEM;
  40. }
  41. /* malloc EventLog space */
  42. log->bios_event_log = kmalloc(log_size, GFP_KERNEL);
  43. if (!log->bios_event_log)
  44. goto err_memunmap;
  45. memcpy(log->bios_event_log, log_tbl->log, log_size);
  46. log->bios_event_log_end = log->bios_event_log + log_size;
  47. tpm_log_version = log_tbl->version;
  48. memunmap(log_tbl);
  49. return tpm_log_version;
  50. err_memunmap:
  51. memunmap(log_tbl);
  52. return -ENOMEM;
  53. }