Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tpm: vtpm_proxy: Implement request_locality function.

Implement the request_locality function. To set the locality on the
backend we define vendor-specific TPM 1.2 and TPM 2 ordinals and send
a command to the backend to set the locality for the next commands.

To avoid recursing into requesting the locality, we set the
TPM_TRANSMIT_RAW flag when calling tpm_transmit_cmd. To avoid recursing
into TPM 2 space related commands, we set the space parameter to NULL.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

authored by

Stefan Berger and committed by
Jarkko Sakkinen
be4c9acf 85ab3bf3

+41
+1
drivers/char/tpm/tpm-interface.c
··· 538 538 539 539 return 0; 540 540 } 541 + EXPORT_SYMBOL_GPL(tpm_transmit_cmd); 541 542 542 543 #define TPM_DIGEST_SIZE 20 543 544 #define TPM_RET_CODE_IDX 6
+36
drivers/char/tpm/tpm_vtpm_proxy.c
··· 371 371 return ret; 372 372 } 373 373 374 + static int vtpm_proxy_request_locality(struct tpm_chip *chip, int locality) 375 + { 376 + struct tpm_buf buf; 377 + int rc; 378 + const struct tpm_output_header *header; 379 + 380 + if (chip->flags & TPM_CHIP_FLAG_TPM2) 381 + rc = tpm_buf_init(&buf, TPM2_ST_SESSIONS, 382 + TPM2_CC_SET_LOCALITY); 383 + else 384 + rc = tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, 385 + TPM_ORD_SET_LOCALITY); 386 + if (rc) 387 + return rc; 388 + tpm_buf_append_u8(&buf, locality); 389 + 390 + rc = tpm_transmit_cmd(chip, NULL, buf.data, tpm_buf_length(&buf), 0, 391 + TPM_TRANSMIT_UNLOCKED | TPM_TRANSMIT_RAW, 392 + "attempting to set locality"); 393 + if (rc < 0) { 394 + locality = rc; 395 + goto out; 396 + } 397 + 398 + header = (const struct tpm_output_header *)buf.data; 399 + rc = be32_to_cpu(header->return_code); 400 + if (rc) 401 + locality = -1; 402 + 403 + out: 404 + tpm_buf_destroy(&buf); 405 + 406 + return locality; 407 + } 408 + 374 409 static const struct tpm_class_ops vtpm_proxy_tpm_ops = { 375 410 .flags = TPM_OPS_AUTO_STARTUP, 376 411 .recv = vtpm_proxy_tpm_op_recv, ··· 415 380 .req_complete_mask = VTPM_PROXY_REQ_COMPLETE_FLAG, 416 381 .req_complete_val = VTPM_PROXY_REQ_COMPLETE_FLAG, 417 382 .req_canceled = vtpm_proxy_tpm_req_canceled, 383 + .request_locality = vtpm_proxy_request_locality, 418 384 }; 419 385 420 386 /*
+4
include/uapi/linux/vtpm_proxy.h
··· 46 46 47 47 #define VTPM_PROXY_IOC_NEW_DEV _IOWR(0xa1, 0x00, struct vtpm_proxy_new_dev) 48 48 49 + /* vendor specific commands to set locality */ 50 + #define TPM2_CC_SET_LOCALITY 0x20001000 51 + #define TPM_ORD_SET_LOCALITY 0x20001000 52 + 49 53 #endif /* _UAPI_LINUX_VTPM_PROXY_H */