static ssize_t tpm_show_ppi_request(struct device *dev, struct device_attribute *attr, char *buf) { ssize_t size = -EINVAL; union acpi_object *obj; struct tpm_chip *chip = to_tpm_chip(dev); obj = tpm_eval_dsm(chip->acpi_dev_handle, TPM_PPI_FN_GETREQ, ACPI_TYPE_PACKAGE, NULL); if (!obj) return -ENXIO; /* * output.pointer should be of package type, including two integers. * The first is function return code, 0 means success and 1 means * error. The second is pending TPM operation requested by the OS, 0 * means none and >0 means operation value. */ if (obj->package.count == 2 && obj->package.elements[0].type == ACPI_TYPE_INTEGER && obj->package.elements[1].type == ACPI_TYPE_INTEGER) { if (obj->package.elements[0].integer.value) size = -EFAULT; else size = scnprintf(buf, PAGE_SIZE, "%llu\n", obj->package.elements[1].integer.value); } ACPI_FREE(obj); return size; }
static ssize_t pubek_show(struct device *dev, struct device_attribute *attr, char *buf) { struct tpm_buf tpm_buf; struct tpm_readpubek_out *out; ssize_t rc; int i; char *str = buf; struct tpm_chip *chip = to_tpm_chip(dev); char anti_replay[20]; memset(&anti_replay, 0, sizeof(anti_replay)); rc = tpm_buf_init(&tpm_buf, TPM_TAG_RQU_COMMAND, TPM_ORD_READPUBEK); if (rc) return rc; tpm_buf_append(&tpm_buf, anti_replay, sizeof(anti_replay)); rc = tpm_transmit_cmd(chip, NULL, tpm_buf.data, PAGE_SIZE, READ_PUBEK_RESULT_MIN_BODY_SIZE, 0, "attempting to read the PUBEK"); if (rc) { tpm_buf_destroy(&tpm_buf); return 0; } out = (struct tpm_readpubek_out *)&tpm_buf.data[10]; str += sprintf(str, "Algorithm: %02X %02X %02X %02X\n" "Encscheme: %02X %02X\n" "Sigscheme: %02X %02X\n" "Parameters: %02X %02X %02X %02X " "%02X %02X %02X %02X " "%02X %02X %02X %02X\n" "Modulus length: %d\n" "Modulus:\n", out->algorithm[0], out->algorithm[1], out->algorithm[2], out->algorithm[3], out->encscheme[0], out->encscheme[1], out->sigscheme[0], out->sigscheme[1], out->parameters[0], out->parameters[1], out->parameters[2], out->parameters[3], out->parameters[4], out->parameters[5], out->parameters[6], out->parameters[7], out->parameters[8], out->parameters[9], out->parameters[10], out->parameters[11], be32_to_cpu(out->keysize)); for (i = 0; i < 256; i++) { str += sprintf(str, "%02X ", out->modulus[i]); if ((i + 1) % 16 == 0) str += sprintf(str, "\n"); } rc = str - buf; tpm_buf_destroy(&tpm_buf); return rc; }
static ssize_t tpm_show_ppi_version(struct device *dev, struct device_attribute *attr, char *buf) { struct tpm_chip *chip = to_tpm_chip(dev); return scnprintf(buf, PAGE_SIZE, "%s\n", chip->ppi_version); }
static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr, char *buf) { cap_t cap; u8 digest[TPM_DIGEST_SIZE]; ssize_t rc; u32 i, j, num_pcrs; char *str = buf; struct tpm_chip *chip = to_tpm_chip(dev); rc = tpm1_getcap(chip, TPM_CAP_PROP_PCR, &cap, "attempting to determine the number of PCRS", sizeof(cap.num_pcrs)); if (rc) return 0; num_pcrs = be32_to_cpu(cap.num_pcrs); for (i = 0; i < num_pcrs; i++) { rc = tpm1_pcr_read(chip, i, digest); if (rc) break; str += sprintf(str, "PCR-%02d: ", i); for (j = 0; j < TPM_DIGEST_SIZE; j++) str += sprintf(str, "%02X ", digest[j]); str += sprintf(str, "\n"); } return str - buf; }
static ssize_t tpm_show_ppi_tcg_operations(struct device *dev, struct device_attribute *attr, char *buf) { struct tpm_chip *chip = to_tpm_chip(dev); return show_ppi_operations(chip->acpi_dev_handle, buf, 0, PPI_TPM_REQ_MAX); }
static ssize_t tpm_show_ppi_vs_operations(struct device *dev, struct device_attribute *attr, char *buf) { struct tpm_chip *chip = to_tpm_chip(dev); return show_ppi_operations(chip->acpi_dev_handle, buf, PPI_VS_REQ_START, PPI_VS_REQ_END); }
static ssize_t cancel_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct tpm_chip *chip = to_tpm_chip(dev); if (chip == NULL) return 0; chip->ops->cancel(chip); return count; }
static ssize_t pubek_show(struct device *dev, struct device_attribute *attr, char *buf) { u8 *data; struct tpm_cmd_t tpm_cmd; ssize_t err; int i, rc; char *str = buf; struct tpm_chip *chip = to_tpm_chip(dev); tpm_cmd.header.in = tpm_readpubek_header; err = tpm_transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE, 0, "attempting to read the PUBEK"); if (err) goto out; /* ignore header 10 bytes algorithm 32 bits (1 == RSA ) encscheme 16 bits sigscheme 16 bits parameters (RSA 12->bytes: keybit, #primes, expbit) keylenbytes 32 bits 256 byte modulus ignore checksum 20 bytes */ data = tpm_cmd.params.readpubek_out_buffer; str += sprintf(str, "Algorithm: %02X %02X %02X %02X\n" "Encscheme: %02X %02X\n" "Sigscheme: %02X %02X\n" "Parameters: %02X %02X %02X %02X " "%02X %02X %02X %02X " "%02X %02X %02X %02X\n" "Modulus length: %d\n" "Modulus:\n", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[12], data[13], data[14], data[15], data[16], data[17], data[18], data[19], data[20], data[21], data[22], data[23], be32_to_cpu(*((__be32 *) (data + 24)))); for (i = 0; i < 256; i++) { str += sprintf(str, "%02X ", data[i + 28]); if ((i + 1) % 16 == 0) str += sprintf(str, "\n"); } out: rc = str - buf; return rc; }
static ssize_t tpm_store_ppi_request(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { u32 req; u64 ret; int func = TPM_PPI_FN_SUBREQ; union acpi_object *obj, tmp; union acpi_object argv4 = ACPI_INIT_DSM_ARGV4(1, &tmp); struct tpm_chip *chip = to_tpm_chip(dev); /* * the function to submit TPM operation request to pre-os environment * is updated with function index from SUBREQ to SUBREQ2 since PPI * version 1.1 */ if (acpi_check_dsm(chip->acpi_dev_handle, tpm_ppi_uuid, TPM_PPI_REVISION_ID, 1 << TPM_PPI_FN_SUBREQ2)) func = TPM_PPI_FN_SUBREQ2; /* * PPI spec defines params[3].type as ACPI_TYPE_PACKAGE. Some BIOS * accept buffer/string/integer type, but some BIOS accept buffer/ * string/package type. For PPI version 1.0 and 1.1, use buffer type * for compatibility, and use package type since 1.2 according to spec. */ if (strcmp(chip->ppi_version, "1.2") < 0) { if (sscanf(buf, "%d", &req) != 1) return -EINVAL; argv4.type = ACPI_TYPE_BUFFER; argv4.buffer.length = sizeof(req); argv4.buffer.pointer = (u8 *)&req; } else { tmp.type = ACPI_TYPE_INTEGER; if (sscanf(buf, "%llu", &tmp.integer.value) != 1) return -EINVAL; } obj = tpm_eval_dsm(chip->acpi_dev_handle, func, ACPI_TYPE_INTEGER, &argv4); if (!obj) { return -ENXIO; } else { ret = obj->integer.value; ACPI_FREE(obj); } if (ret == 0) return (acpi_status)count; return (ret == 1) ? -EPERM : -EFAULT; }
static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr, char *buf) { struct tpm_chip *chip = to_tpm_chip(dev); return sprintf(buf, "%d %d %d %d [%s]\n", jiffies_to_usecs(chip->timeout_a), jiffies_to_usecs(chip->timeout_b), jiffies_to_usecs(chip->timeout_c), jiffies_to_usecs(chip->timeout_d), chip->timeout_adjusted ? "adjusted" : "original"); }
static ssize_t owned_show(struct device *dev, struct device_attribute *attr, char *buf) { cap_t cap; ssize_t rc; rc = tpm_getcap(to_tpm_chip(dev), TPM_CAP_PROP_OWNER, &cap, "attempting to determine the owner state"); if (rc) return 0; rc = sprintf(buf, "%d\n", cap.owned); return rc; }
static ssize_t active_show(struct device *dev, struct device_attribute *attr, char *buf) { cap_t cap; ssize_t rc; rc = tpm_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_PERM, &cap, "attempting to determine the permanent active state"); if (rc) return 0; rc = sprintf(buf, "%d\n", !cap.perm_flags.deactivated); return rc; }
static ssize_t temp_deactivated_show(struct device *dev, struct device_attribute *attr, char *buf) { cap_t cap; ssize_t rc; rc = tpm_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_VOL, &cap, "attempting to determine the temporary state"); if (rc) return 0; rc = sprintf(buf, "%d\n", cap.stclear_flags.deactivated); return rc; }
static ssize_t enabled_show(struct device *dev, struct device_attribute *attr, char *buf) { cap_t cap; ssize_t rc; rc = tpm1_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_PERM, &cap, "attempting to determine the permanent enabled state", sizeof(cap.perm_flags)); if (rc) return 0; rc = sprintf(buf, "%d\n", !cap.perm_flags.disable); return rc; }
static ssize_t durations_show(struct device *dev, struct device_attribute *attr, char *buf) { struct tpm_chip *chip = to_tpm_chip(dev); if (chip->duration[TPM_LONG] == 0) return 0; return sprintf(buf, "%d %d %d [%s]\n", jiffies_to_usecs(chip->duration[TPM_SHORT]), jiffies_to_usecs(chip->duration[TPM_MEDIUM]), jiffies_to_usecs(chip->duration[TPM_LONG]), chip->duration_adjusted ? "adjusted" : "original"); }
static ssize_t caps_show(struct device *dev, struct device_attribute *attr, char *buf) { struct tpm_chip *chip = to_tpm_chip(dev); cap_t cap; ssize_t rc; char *str = buf; rc = tpm1_getcap(chip, TPM_CAP_PROP_MANUFACTURER, &cap, "attempting to determine the manufacturer", sizeof(cap.manufacturer_id)); if (rc) return 0; str += sprintf(str, "Manufacturer: 0x%x\n", be32_to_cpu(cap.manufacturer_id)); /* Try to get a TPM version 1.2 TPM_CAP_VERSION_INFO */ rc = tpm1_getcap(chip, TPM_CAP_VERSION_1_2, &cap, "attempting to determine the 1.2 version", sizeof(cap.tpm_version_1_2)); if (!rc) { str += sprintf(str, "TCG version: %d.%d\nFirmware version: %d.%d\n", cap.tpm_version_1_2.Major, cap.tpm_version_1_2.Minor, cap.tpm_version_1_2.revMajor, cap.tpm_version_1_2.revMinor); } else { /* Otherwise just use TPM_STRUCT_VER */ rc = tpm1_getcap(chip, TPM_CAP_VERSION_1_1, &cap, "attempting to determine the 1.1 version", sizeof(cap.tpm_version)); if (rc) return 0; str += sprintf(str, "TCG version: %d.%d\nFirmware version: %d.%d\n", cap.tpm_version.Major, cap.tpm_version.Minor, cap.tpm_version.revMajor, cap.tpm_version.revMinor); } return str - buf; }
static ssize_t tpm_show_ppi_transition_action(struct device *dev, struct device_attribute *attr, char *buf) { u32 ret; acpi_status status; union acpi_object *obj = NULL; union acpi_object tmp = { .buffer.type = ACPI_TYPE_BUFFER, .buffer.length = 0, .buffer.pointer = NULL }; struct tpm_chip *chip = to_tpm_chip(dev); static char *info[] = { "None", "Shutdown", "Reboot", "OS Vendor-specific", "Error", }; /* * PPI spec defines params[3].type as empty package, but some platforms * (e.g. Capella with PPI 1.0) need integer/string/buffer type, so for * compatibility, define params[3].type as buffer, if PPI version < 1.2 */ if (strcmp(chip->ppi_version, "1.2") < 0) obj = &tmp; obj = tpm_eval_dsm(chip->acpi_dev_handle, TPM_PPI_FN_GETACT, ACPI_TYPE_INTEGER, obj); if (!obj) { return -ENXIO; } else { ret = obj->integer.value; ACPI_FREE(obj); } if (ret < ARRAY_SIZE(info) - 1) status = scnprintf(buf, PAGE_SIZE, "%d: %s\n", ret, info[ret]); else status = scnprintf(buf, PAGE_SIZE, "%d: %s\n", ret, info[ARRAY_SIZE(info)-1]); return status; } static ssize_t tpm_show_ppi_response(struct device *dev, struct device_attribute *attr, char *buf) { acpi_status status = -EINVAL; union acpi_object *obj, *ret_obj; u64 req, res; struct tpm_chip *chip = to_tpm_chip(dev); obj = tpm_eval_dsm(chip->acpi_dev_handle, TPM_PPI_FN_GETRSP, ACPI_TYPE_PACKAGE, NULL); if (!obj) return -ENXIO; /* * parameter output.pointer should be of package type, including * 3 integers. The first means function return code, the second means * most recent TPM operation request, and the last means response to * the most recent TPM operation request. Only if the first is 0, and * the second integer is not 0, the response makes sense. */ ret_obj = obj->package.elements; if (obj->package.count < 3 || ret_obj[0].type != ACPI_TYPE_INTEGER || ret_obj[1].type != ACPI_TYPE_INTEGER || ret_obj[2].type != ACPI_TYPE_INTEGER) goto cleanup; if (ret_obj[0].integer.value) { status = -EFAULT; goto cleanup; } req = ret_obj[1].integer.value; res = ret_obj[2].integer.value; if (req) { if (res == 0) status = scnprintf(buf, PAGE_SIZE, "%llu %s\n", req, "0: Success"); else if (res == 0xFFFFFFF0) status = scnprintf(buf, PAGE_SIZE, "%llu %s\n", req, "0xFFFFFFF0: User Abort"); else if (res == 0xFFFFFFF1) status = scnprintf(buf, PAGE_SIZE, "%llu %s\n", req, "0xFFFFFFF1: BIOS Failure"); else if (res >= 1 && res <= 0x00000FFF) status = scnprintf(buf, PAGE_SIZE, "%llu %llu: %s\n", req, res, "Corresponding TPM error"); else status = scnprintf(buf, PAGE_SIZE, "%llu %llu: %s\n", req, res, "Error"); } else { status = scnprintf(buf, PAGE_SIZE, "%llu: %s\n", req, "No Recent Request"); } cleanup: ACPI_FREE(obj); return status; }