blob: 5af923600d37d8d6b77e8d57c396164767b2b81b [file] [log] [blame]
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -07001/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -07002 *
Martin Roth842253b2018-07-05 18:42:45 -06003 * 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 Nojiriefb5cde2014-07-02 08:37:23 -070031 * Functions for querying, manipulating and locking rollback indices
32 * stored in the TPM NVRAM.
33 */
34
Daisuke Nojiri57990972014-07-15 19:47:32 -070035#ifndef ANTIROLLBACK_H_
36#define ANTIROLLBACK_H_
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070037
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +010038#include <types.h>
39#include <security/tpm/tspi.h>
Joel Kitching2eb89c82019-04-25 17:45:12 +080040#include <vb2_sha.h>
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070041
Randall Spangler144c2282014-12-03 17:35:53 -080042struct vb2_context;
Julius Werner76e33032015-01-30 18:45:27 -080043enum vb2_pcr_digest;
Randall Spangler144c2282014-12-03 17:35:53 -080044
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070045/* TPM NVRAM location indices. */
46#define FIRMWARE_NV_INDEX 0x1007
Daisuke Nojiri97ea9c02014-09-29 13:02:29 -070047#define KERNEL_NV_INDEX 0x1008
Daisuke Nojiri03bf3012016-10-07 13:59:36 -070048/* 0x1009 used to be used as a backup space. Think of conflicts if you
49 * want to use 0x1009 for something else. */
Furquan Shaikh4b2fed52016-11-07 23:50:12 -080050#define BACKUP_NV_INDEX 0x1009
51#define FWMP_NV_INDEX 0x100a
Furquan Shaikhb038f412016-11-07 23:47:11 -080052#define REC_HASH_NV_INDEX 0x100b
53#define REC_HASH_NV_SIZE VB2_SHA256_DIGEST_SIZE
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070054
55/* Structure definitions for TPM spaces */
56
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070057/* Flags for firmware space */
Daisuke Nojiri57990972014-07-15 19:47:32 -070058
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070059/*
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 Nojiriefb5cde2014-07-02 08:37:23 -070064
65/* All functions return TPM_SUCCESS (zero) if successful, non-zero if error */
66
Daisuke Nojiri57990972014-07-15 19:47:32 -070067uint32_t antirollback_read_space_firmware(struct vb2_context *ctx);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070068
69/**
70 * Write may be called if the versions change.
71 */
Daisuke Nojiri57990972014-07-15 19:47:32 -070072uint32_t antirollback_write_space_firmware(struct vb2_context *ctx);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070073
74/**
75 * Lock must be called.
76 */
Daisuke Nojiri57990972014-07-15 19:47:32 -070077uint32_t antirollback_lock_space_firmware(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070078
Furquan Shaikhb038f412016-11-07 23:47:11 -080079/* Read recovery hash data from TPM. */
80uint32_t antirollback_read_space_rec_hash(uint8_t *data, uint32_t size);
81/* Write new hash data to recovery space in TPM. */
82uint32_t antirollback_write_space_rec_hash(const uint8_t *data, uint32_t size);
83/* Lock down recovery hash space in TPM. */
84uint32_t antirollback_lock_space_rec_hash(void);
85
Daisuke Nojiri57990972014-07-15 19:47:32 -070086#endif /* ANTIROLLBACK_H_ */