Something went wrong. Try again.
(I'm so sorry!) Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Something went wrong. Try again.
8.7 kB · 203 lines
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204.. SPDX-License-Identifier: GPL-2.0
==================================IMA Measurements Export and Delete==================================
Introduction============
The IMA measurements list is currently stored in the kernel memory. Memoryoccupation grows linearly with the number of records, and can become aproblem especially in environments with reduced resources.
While there is an advantage in keeping the IMA measurements list in kernelmemory, so that it is always available for reading from the securityfsinterfaces, storing it elsewhere would make it possible to free preciousmemory for other kernel usage.
The IMA measurements list needs to be retained and safely stored for newattestation servers to validate it. Assuming the IMA measurements list isproperly saved, storing it outside the kernel does not introduce securityissues, since its integrity is anyway protected by the TPM.
Hence, the new IMA staging mechanism is introduced to export IMAmeasurements to user space and delete them from kernel space.
Staging consists in atomically moving the current measurements list to atemporary list, so that measurements can be deleted afterwards. The stagingoperation locks the hot path (racing with addition of new measurements) fora very short time, only for swapping the list pointers. Deletion of themeasurements instead is done locklessly, away from the hot path.
There are two flavors of the staging mechanism. In the staging with prompt,all current measurements are staged, read and deleted upon confirmation. Inthe staging and deleting flavor, N measurements are staged from thebeginning of the current measurements list and immediately deleted withoutconfirmation.
Management of Staged Measurements=================================
Since with the staging mechanism measurement records are removed from thekernel, the staged measurements need to be saved in a storage andconcatenated together, so that they can be presented during remoteattestation as if staging was never done. This task can be accomplished bya remote attestation agent modified to support staging, or a systemservice.
Coordination is necessary in the case where there are multiple actorsrequesting measurements to be staged.
In the staging with prompt case, the measurement interfaces can be accessedonly by one actor (writer) at a time, so the others will get an error untilthe former closes it. Since the actors don't care about N, when they gainaccess to the interface, they will get all the staged measurements at thetime of their request.
In the case of staging and deleting, coordination is more important, sincethere is the risk that two actors unaware of each other compute the value Non the current measurements list and request IMA to stage N twice.
Remote Attestation Agent Workflow=================================
Remote attestation agents can be configured to always present all themeasurements to the remote verifiers or, alternatively, to only provide themeasurements that have not been verified yet by the remote verifiers.
In the latter case, determining which measurements need to be sent andverified must solely depend on the remote verifier. The remote attestationagent can proactively send partial measurements, at the condition that theyare the ones that the remote verifier needs.
An agent can rely on one of the supported staging methods to proactivelysend to a remote verifier the measurements since the previous request upto the ones that verify the TPM quote obtained in the current request.The workflow with each staging method is the following.
With staging with prompt, the agent stages the current measurements list,reads and stores the measurements in a storage and immediately requestsIMA to delete the staged measurements from kernel memory. Afterwards, itcalculates N by replaying the PCR extend on the stored measurements untilthe calculated PCRs match the quoted PCRs. It then keeps the measurementsin excess for the next attestation request.
At the next attestation request, the agent performs the same steps above,and concatenates the new measurements to the ones in excess from theprevious request. Also in this case, the agent replays the PCR extend untilit matches the currently quoted PCRs, keeps the measurements in excess andpresents the new N measurement records to the remote attestation server.
With the staging and deleting method, the agent reads the currentmeasurements list, calculates N and requests IMA to delete only those. Themeasurements in excess are kept in the IMA measurements list and can beretrieved at the next remote attestation request.
While keeping only the excess measurements in the storage could besufficient to serve the requests of a remote verifier, it is advised tokeep all the obtained measurements locally, as they might be needed for theattestation with a different remote verifier.
Usage=====
The IMA staging mechanism can be enabled from the kernel configuration withthe CONFIG_IMA_STAGING option. This option prevents inadvertently removingthe IMA measurement list on systems which do not properly save it.
If the option is enabled, IMA duplicates the current securityfsmeasurements interfaces (both binary and ASCII), by adding the ``_staged``file suffix. Both the original and the staging interfaces gain the writepermission for the root user and group, but require the process to haveCAP_SYS_ADMIN set.
The staging mechanism supports two flavors.
Staging with prompt~~~~~~~~~~~~~~~~~~~
The current measurements list is moved to a temporary staging area,allowing it to be saved to external storage, before being deleted uponconfirmation.
This staging process is achieved with the following steps.
1. ``echo A > <_staged interface>``: the user requests IMA to stage the entire measurements list; 2. ``cat <_staged interface>``: the user reads the staged measurements; 3. ``echo D > <_staged interface>``: the user requests IMA to delete staged measurements.
Staging and deleting~~~~~~~~~~~~~~~~~~~~
N measurements are staged to a temporary staging area, and immediatelydeleted without further confirmation.
This staging process is achieved with the following steps.
1. ``cat <original interface>``: the user reads the current measurements list and determines what the value N for staging should be; 2. ``echo N > <original interface>``: the user requests IMA to delete N measurements from the current measurements list.
Interface Access================
In order to avoid the IMA measurements list being suddenly truncated by thestaging mechanism during a read, or having multiple concurrent staging, asemaphore-like locking scheme has been implemented on all the measurementslist interfaces.
Multiple readers can access concurrently the original and stagedinterfaces, and they can be in mutual exclusion with one writer. In orderto see the same state across all the measurement interfaces, the samewriter is allowed to open multiple interfaces for write or read/write.
If an illegal access occurs, the open to the measurements list interface isdenied.
Kexec=====
In the event a kexec() system call occurs between staging and deleting, thestaged measurement records are marshalled before the current measurementslist, so that they are both available when the secondary kernel starts.
If measurement is suspended before requesting to delete staged or currentmeasurements, IMA returns an error to user space to let it know thatmarshalling is already in progress, so that it does not save themeasurements twice.
IMA also disallows staging when suspending measurement, to avoid thesituation where neither measurements are carried over to the secondarykernel, nor they are saved by user space to the storage.
Hash table==========
By default, the template digest of staged measurement records are kept inkernel memory (only template data are freed), to be able to detectduplicate records independently of staging.
The new kernel option ``ima_flush_htable`` has been introduced toexplicitly request a complete deletion of the staged measurements, formaximum kernel memory saving. If the option has been specified, duplicaterecords are still avoided on records of the current measurements list,but there can be duplicates between different groups of stagedmeasurements.
Flushing the hash table is supported only for the staging with promptflavor. For the staging and deleting flavor, it would have been necessaryto lock the hot path adding new measurements for the time needed to removeeach selected measurement individually.