• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Microsoft Reference Implementation for TPM 2.0
2  *
3  *  The copyright in this software is being made available under the BSD License,
4  *  included below. This software may be subject to other third party and
5  *  contributor rights, including patent rights, and no such rights are granted
6  *  under this license.
7  *
8  *  Copyright (c) Microsoft Corporation
9  *
10  *  All rights reserved.
11  *
12  *  BSD License
13  *
14  *  Redistribution and use in source and binary forms, with or without modification,
15  *  are permitted provided that the following conditions are met:
16  *
17  *  Redistributions of source code must retain the above copyright notice, this list
18  *  of conditions and the following disclaimer.
19  *
20  *  Redistributions in binary form must reproduce the above copyright notice, this
21  *  list of conditions and the following disclaimer in the documentation and/or
22  *  other materials provided with the distribution.
23  *
24  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
25  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28  *  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31  *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 #include "Tpm.h"
36 #include "EvictControl_fp.h"
37 
38 #if CC_EvictControl  // Conditional expansion of this file
39 
40 /*(See part 3 specification)
41 // Make a transient object persistent or evict a persistent object
42 */
43 //  Return Type: TPM_RC
44 //      TPM_RC_ATTRIBUTES   an object with 'temporary', 'stClear' or 'publicOnly'
45 //                          attribute SET cannot be made persistent
46 //      TPM_RC_HIERARCHY    'auth' cannot authorize the operation in the hierarchy
47 //                          of 'evictObject'
48 //      TPM_RC_HANDLE       'evictHandle' of the persistent object to be evicted is
49 //                          not the same as the 'persistentHandle' argument
50 //      TPM_RC_NV_HANDLE    'persistentHandle' is unavailable
51 //      TPM_RC_NV_SPACE     no space in NV to make 'evictHandle' persistent
52 //      TPM_RC_RANGE        'persistentHandle' is not in the range corresponding to
53 //                          the hierarchy of 'evictObject'
54 TPM_RC
TPM2_EvictControl(EvictControl_In * in)55 TPM2_EvictControl(
56     EvictControl_In     *in             // IN: input parameter list
57     )
58 {
59     TPM_RC      result;
60     OBJECT      *evictObject;
61 
62 // Input Validation
63 
64     // Get internal object pointer
65     evictObject = HandleToObject(in->objectHandle);
66 
67     // Temporary, stClear or public only objects can not be made persistent
68     if(evictObject->attributes.temporary == SET
69        || evictObject->attributes.stClear == SET
70        || evictObject->attributes.publicOnly == SET)
71         return TPM_RCS_ATTRIBUTES + RC_EvictControl_objectHandle;
72 
73     // If objectHandle refers to a persistent object, it should be the same as
74     // input persistentHandle
75     if(evictObject->attributes.evict == SET
76        && evictObject->evictHandle != in->persistentHandle)
77         return TPM_RCS_HANDLE + RC_EvictControl_objectHandle;
78 
79     // Additional authorization validation
80     if(in->auth == TPM_RH_PLATFORM)
81     {
82         // To make persistent
83         if(evictObject->attributes.evict == CLEAR)
84         {
85             // PlatformAuth can not set evict object in storage or endorsement
86             // hierarchy
87             if(evictObject->attributes.ppsHierarchy == CLEAR)
88                 return TPM_RCS_HIERARCHY + RC_EvictControl_objectHandle;
89             // Platform cannot use a handle outside of platform persistent range.
90             if(!NvIsPlatformPersistentHandle(in->persistentHandle))
91                 return TPM_RCS_RANGE + RC_EvictControl_persistentHandle;
92         }
93         // PlatformAuth can delete any persistent object
94     }
95     else if(in->auth == TPM_RH_OWNER)
96     {
97         // OwnerAuth can not set or clear evict object in platform hierarchy
98         if(evictObject->attributes.ppsHierarchy == SET)
99             return TPM_RCS_HIERARCHY + RC_EvictControl_objectHandle;
100 
101         // Owner cannot use a handle outside of owner persistent range.
102         if(evictObject->attributes.evict == CLEAR
103            && !NvIsOwnerPersistentHandle(in->persistentHandle))
104             return TPM_RCS_RANGE + RC_EvictControl_persistentHandle;
105     }
106     else
107     {
108         // Other authorization is not allowed in this command and should have been
109         // filtered out in unmarshal process
110         FAIL(FATAL_ERROR_INTERNAL);
111     }
112 // Internal Data Update
113     // Change evict state
114     if(evictObject->attributes.evict == CLEAR)
115     {
116         // Make object persistent
117         if(NvFindHandle(in->persistentHandle) != 0)
118             return TPM_RC_NV_DEFINED;
119         // A TPM_RC_NV_HANDLE or TPM_RC_NV_SPACE error may be returned at this
120         // point
121         result = NvAddEvictObject(in->persistentHandle, evictObject);
122     }
123     else
124     {
125         // Delete the persistent object in NV
126         result = NvDeleteEvict(evictObject->evictHandle);
127     }
128     return result;
129 }
130 
131 #endif // CC_EvictControl