| 1 | |
| 2 |
|
| 3 | ==================================
|
| 4 | IMA Measurements Export and Delete
|
| 5 | ==================================
|
| 6 |
|
| 7 |
|
| 8 | Introduction
|
| 9 | ============
|
| 10 |
|
| 11 | The IMA measurements list is currently stored in the kernel memory. Memory
|
| 12 | occupation grows linearly with the number of records, and can become a
|
| 13 | problem especially in environments with reduced resources.
|
| 14 |
|
| 15 | While there is an advantage in keeping the IMA measurements list in kernel
|
| 16 | memory, so that it is always available for reading from the securityfs
|
| 17 | interfaces, storing it elsewhere would make it possible to free precious
|
| 18 | memory for other kernel usage.
|
| 19 |
|
| 20 | The IMA measurements list needs to be retained and safely stored for new
|
| 21 | attestation servers to validate it. Assuming the IMA measurements list is
|
| 22 | properly saved, storing it outside the kernel does not introduce security
|
| 23 | issues, since its integrity is anyway protected by the TPM.
|
| 24 |
|
| 25 | Hence, the new IMA staging mechanism is introduced to export IMA
|
| 26 | measurements to user space and delete them from kernel space.
|
| 27 |
|
| 28 | Staging consists in atomically moving the current measurements list to a
|
| 29 | temporary list, so that measurements can be deleted afterwards. The staging
|
| 30 | operation locks the hot path (racing with addition of new measurements) for
|
| 31 | a very short time, only for swapping the list pointers. Deletion of the
|
| 32 | measurements instead is done locklessly, away from the hot path.
|
| 33 |
|
| 34 | There are two flavors of the staging mechanism. In the staging with prompt,
|
| 35 | all current measurements are staged, read and deleted upon confirmation. In
|
| 36 | the staging and deleting flavor, N measurements are staged from the
|
| 37 | beginning of the current measurements list and immediately deleted without
|
| 38 | confirmation.
|
| 39 |
|
| 40 |
|
| 41 | Management of Staged Measurements
|
| 42 | =================================
|
| 43 |
|
| 44 | Since with the staging mechanism measurement records are removed from the
|
| 45 | kernel, the staged measurements need to be saved in a storage and
|
| 46 | concatenated together, so that they can be presented during remote
|
| 47 | attestation as if staging was never done. This task can be accomplished by
|
| 48 | a remote attestation agent modified to support staging, or a system
|
| 49 | service.
|
| 50 |
|
| 51 | Coordination is necessary in the case where there are multiple actors
|
| 52 | requesting measurements to be staged.
|
| 53 |
|
| 54 | In the staging with prompt case, the measurement interfaces can be accessed
|
| 55 | only by one actor (writer) at a time, so the others will get an error until
|
| 56 | the former closes it. Since the actors don't care about N, when they gain
|
| 57 | access to the interface, they will get all the staged measurements at the
|
| 58 | time of their request.
|
| 59 |
|
| 60 | In the case of staging and deleting, coordination is more important, since
|
| 61 | there is the risk that two actors unaware of each other compute the value N
|
| 62 | on the current measurements list and request IMA to stage N twice.
|
| 63 |
|
| 64 |
|
| 65 | Remote Attestation Agent Workflow
|
| 66 | =================================
|
| 67 |
|
| 68 | Remote attestation agents can be configured to always present all the
|
| 69 | measurements to the remote verifiers or, alternatively, to only provide the
|
| 70 | measurements that have not been verified yet by the remote verifiers.
|
| 71 |
|
| 72 | In the latter case, determining which measurements need to be sent and
|
| 73 | verified must solely depend on the remote verifier. The remote attestation
|
| 74 | agent can proactively send partial measurements, at the condition that they
|
| 75 | are the ones that the remote verifier needs.
|
| 76 |
|
| 77 | An agent can rely on one of the supported staging methods to proactively
|
| 78 | send to a remote verifier the measurements since the previous request up
|
| 79 | to the ones that verify the TPM quote obtained in the current request.
|
| 80 | The workflow with each staging method is the following.
|
| 81 |
|
| 82 | With staging with prompt, the agent stages the current measurements list,
|
| 83 | reads and stores the measurements in a storage and immediately requests
|
| 84 | IMA to delete the staged measurements from kernel memory. Afterwards, it
|
| 85 | calculates N by replaying the PCR extend on the stored measurements until
|
| 86 | the calculated PCRs match the quoted PCRs. It then keeps the measurements
|
| 87 | in excess for the next attestation request.
|
| 88 |
|
| 89 | At the next attestation request, the agent performs the same steps above,
|
| 90 | and concatenates the new measurements to the ones in excess from the
|
| 91 | previous request. Also in this case, the agent replays the PCR extend until
|
| 92 | it matches the currently quoted PCRs, keeps the measurements in excess and
|
| 93 | presents the new N measurement records to the remote attestation server.
|
| 94 |
|
| 95 | With the staging and deleting method, the agent reads the current
|
| 96 | measurements list, calculates N and requests IMA to delete only those. The
|
| 97 | measurements in excess are kept in the IMA measurements list and can be
|
| 98 | retrieved at the next remote attestation request.
|
| 99 |
|
| 100 | While keeping only the excess measurements in the storage could be
|
| 101 | sufficient to serve the requests of a remote verifier, it is advised to
|
| 102 | keep all the obtained measurements locally, as they might be needed for the
|
| 103 | attestation with a different remote verifier.
|
| 104 |
|
| 105 |
|
| 106 | Usage
|
| 107 | =====
|
| 108 |
|
| 109 | The IMA staging mechanism can be enabled from the kernel configuration with
|
| 110 | the CONFIG_IMA_STAGING option. This option prevents inadvertently removing
|
| 111 | the IMA measurement list on systems which do not properly save it.
|
| 112 |
|
| 113 | If the option is enabled, IMA duplicates the current securityfs
|
| 114 | measurements interfaces (both binary and ASCII), by adding the ``_staged``
|
| 115 | file suffix. Both the original and the staging interfaces gain the write
|
| 116 | permission for the root user and group, but require the process to have
|
| 117 | CAP_SYS_ADMIN set.
|
| 118 |
|
| 119 | The staging mechanism supports two flavors.
|
| 120 |
|
| 121 |
|
| 122 | Staging with prompt
|
| 123 | ~~~~~~~~~~~~~~~~~~~
|
| 124 |
|
| 125 | The current measurements list is moved to a temporary staging area,
|
| 126 | allowing it to be saved to external storage, before being deleted upon
|
| 127 | confirmation.
|
| 128 |
|
| 129 | This staging process is achieved with the following steps.
|
| 130 |
|
| 131 | 1. ``echo A > <_staged interface>``: the user requests IMA to stage the
|
| 132 | entire measurements list;
|
| 133 | 2. ``cat <_staged interface>``: the user reads the staged measurements;
|
| 134 | 3. ``echo D > <_staged interface>``: the user requests IMA to delete
|
| 135 | staged measurements.
|
| 136 |
|
| 137 |
|
| 138 | Staging and deleting
|
| 139 | ~~~~~~~~~~~~~~~~~~~~
|
| 140 |
|
| 141 | N measurements are staged to a temporary staging area, and immediately
|
| 142 | deleted without further confirmation.
|
| 143 |
|
| 144 | This staging process is achieved with the following steps.
|
| 145 |
|
| 146 | 1. ``cat <original interface>``: the user reads the current measurements
|
| 147 | list and determines what the value N for staging should be;
|
| 148 | 2. ``echo N > <original interface>``: the user requests IMA to delete N
|
| 149 | measurements from the current measurements list.
|
| 150 |
|
| 151 |
|
| 152 | Interface Access
|
| 153 | ================
|
| 154 |
|
| 155 | In order to avoid the IMA measurements list being suddenly truncated by the
|
| 156 | staging mechanism during a read, or having multiple concurrent staging, a
|
| 157 | semaphore-like locking scheme has been implemented on all the measurements
|
| 158 | list interfaces.
|
| 159 |
|
| 160 | Multiple readers can access concurrently the original and staged
|
| 161 | interfaces, and they can be in mutual exclusion with one writer. In order
|
| 162 | to see the same state across all the measurement interfaces, the same
|
| 163 | writer is allowed to open multiple interfaces for write or read/write.
|
| 164 |
|
| 165 | If an illegal access occurs, the open to the measurements list interface is
|
| 166 | denied.
|
| 167 |
|
| 168 |
|
| 169 | Kexec
|
| 170 | =====
|
| 171 |
|
| 172 | In the event a kexec() system call occurs between staging and deleting, the
|
| 173 | staged measurement records are marshalled before the current measurements
|
| 174 | list, so that they are both available when the secondary kernel starts.
|
| 175 |
|
| 176 | If measurement is suspended before requesting to delete staged or current
|
| 177 | measurements, IMA returns an error to user space to let it know that
|
| 178 | marshalling is already in progress, so that it does not save the
|
| 179 | measurements twice.
|
| 180 |
|
| 181 | IMA also disallows staging when suspending measurement, to avoid the
|
| 182 | situation where neither measurements are carried over to the secondary
|
| 183 | kernel, nor they are saved by user space to the storage.
|
| 184 |
|
| 185 |
|
| 186 | Hash table
|
| 187 | ==========
|
| 188 |
|
| 189 | By default, the template digest of staged measurement records are kept in
|
| 190 | kernel memory (only template data are freed), to be able to detect
|
| 191 | duplicate records independently of staging.
|
| 192 |
|
| 193 | The new kernel option ``ima_flush_htable`` has been introduced to
|
| 194 | explicitly request a complete deletion of the staged measurements, for
|
| 195 | maximum kernel memory saving. If the option has been specified, duplicate
|
| 196 | records are still avoided on records of the current measurements list,
|
| 197 | but there can be duplicates between different groups of staged
|
| 198 | measurements.
|
| 199 |
|
| 200 | Flushing the hash table is supported only for the staging with prompt
|
| 201 | flavor. For the staging and deleting flavor, it would have been necessary
|
| 202 | to lock the hot path adding new measurements for the time needed to remove
|
| 203 | each selected measurement individually.
|