Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 2 | * |
Martin Roth | 842253b | 2018-07-05 18:42:45 -0600 | [diff] [blame] | 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following disclaimer |
| 11 | * in the documentation and/or other materials provided with the |
| 12 | * distribution. |
| 13 | * * Neither the name of Google Inc. nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived from |
| 15 | * this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | /* |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 31 | * Functions for querying, manipulating and locking rollback indices |
| 32 | * stored in the TPM NVRAM. |
| 33 | */ |
| 34 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 35 | #ifndef ANTIROLLBACK_H_ |
| 36 | #define ANTIROLLBACK_H_ |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 37 | |
Philipp Deppenwiese | c07f8fb | 2018-02-27 19:40:52 +0100 | [diff] [blame] | 38 | #include <types.h> |
| 39 | #include <security/tpm/tspi.h> |
Joel Kitching | 2eb89c8 | 2019-04-25 17:45:12 +0800 | [diff] [blame] | 40 | #include <vb2_sha.h> |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 41 | |
Randall Spangler | 144c228 | 2014-12-03 17:35:53 -0800 | [diff] [blame] | 42 | struct vb2_context; |
Julius Werner | 76e3303 | 2015-01-30 18:45:27 -0800 | [diff] [blame] | 43 | enum vb2_pcr_digest; |
Randall Spangler | 144c228 | 2014-12-03 17:35:53 -0800 | [diff] [blame] | 44 | |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 45 | /* TPM NVRAM location indices. */ |
| 46 | #define FIRMWARE_NV_INDEX 0x1007 |
Daisuke Nojiri | 97ea9c0 | 2014-09-29 13:02:29 -0700 | [diff] [blame] | 47 | #define KERNEL_NV_INDEX 0x1008 |
Daisuke Nojiri | 03bf301 | 2016-10-07 13:59:36 -0700 | [diff] [blame] | 48 | /* 0x1009 used to be used as a backup space. Think of conflicts if you |
| 49 | * want to use 0x1009 for something else. */ |
Furquan Shaikh | 4b2fed5 | 2016-11-07 23:50:12 -0800 | [diff] [blame] | 50 | #define BACKUP_NV_INDEX 0x1009 |
| 51 | #define FWMP_NV_INDEX 0x100a |
Furquan Shaikh | b038f41 | 2016-11-07 23:47:11 -0800 | [diff] [blame] | 52 | #define REC_HASH_NV_INDEX 0x100b |
| 53 | #define REC_HASH_NV_SIZE VB2_SHA256_DIGEST_SIZE |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 54 | |
| 55 | /* Structure definitions for TPM spaces */ |
| 56 | |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 57 | /* Flags for firmware space */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 58 | |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 59 | /* |
| 60 | * Last boot was developer mode. TPM ownership is cleared when transitioning |
| 61 | * to/from developer mode. |
| 62 | */ |
| 63 | #define FLAG_LAST_BOOT_DEVELOPER 0x01 |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 64 | |
| 65 | /* All functions return TPM_SUCCESS (zero) if successful, non-zero if error */ |
| 66 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 67 | uint32_t antirollback_read_space_firmware(struct vb2_context *ctx); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Write may be called if the versions change. |
| 71 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 72 | uint32_t antirollback_write_space_firmware(struct vb2_context *ctx); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Lock must be called. |
| 76 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 77 | uint32_t antirollback_lock_space_firmware(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 78 | |
Furquan Shaikh | b038f41 | 2016-11-07 23:47:11 -0800 | [diff] [blame] | 79 | /* Read recovery hash data from TPM. */ |
| 80 | uint32_t antirollback_read_space_rec_hash(uint8_t *data, uint32_t size); |
| 81 | /* Write new hash data to recovery space in TPM. */ |
| 82 | uint32_t antirollback_write_space_rec_hash(const uint8_t *data, uint32_t size); |
| 83 | /* Lock down recovery hash space in TPM. */ |
| 84 | uint32_t antirollback_lock_space_rec_hash(void); |
| 85 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 86 | #endif /* ANTIROLLBACK_H_ */ |