17b05b116SKees Cook================================= 27b05b116SKees CookIMA Template Management Mechanism 37b05b116SKees Cook================================= 47b05b116SKees Cook 57b05b116SKees Cook 67b05b116SKees CookIntroduction 77b05b116SKees Cook============ 87b05b116SKees Cook 97b05b116SKees CookThe original ``ima`` template is fixed length, containing the filedata hash 107b05b116SKees Cookand pathname. The filedata hash is limited to 20 bytes (md5/sha1). 117b05b116SKees CookThe pathname is a null terminated string, limited to 255 characters. 127b05b116SKees CookTo overcome these limitations and to add additional file metadata, it is 137b05b116SKees Cooknecessary to extend the current version of IMA by defining additional 147b05b116SKees Cooktemplates. For example, information that could be possibly reported are 157b05b116SKees Cookthe inode UID/GID or the LSM labels either of the inode and of the process 167b05b116SKees Cookthat is accessing it. 177b05b116SKees Cook 187b05b116SKees CookHowever, the main problem to introduce this feature is that, each time 197b05b116SKees Cooka new template is defined, the functions that generate and display 207b05b116SKees Cookthe measurements list would include the code for handling a new format 217b05b116SKees Cookand, thus, would significantly grow over the time. 227b05b116SKees Cook 237b05b116SKees CookThe proposed solution solves this problem by separating the template 247b05b116SKees Cookmanagement from the remaining IMA code. The core of this solution is the 257b05b116SKees Cookdefinition of two new data structures: a template descriptor, to determine 267b05b116SKees Cookwhich information should be included in the measurement list; a template 277b05b116SKees Cookfield, to generate and display data of a given type. 287b05b116SKees Cook 297b05b116SKees CookManaging templates with these structures is very simple. To support 307b05b116SKees Cooka new data type, developers define the field identifier and implement 317b05b116SKees Cooktwo functions, init() and show(), respectively to generate and display 327b05b116SKees Cookmeasurement entries. Defining a new template descriptor requires 337b05b116SKees Cookspecifying the template format (a string of field identifiers separated 347b05b116SKees Cookby the ``|`` character) through the ``ima_template_fmt`` kernel command line 357b05b116SKees Cookparameter. At boot time, IMA initializes the chosen template descriptor 367b05b116SKees Cookby translating the format into an array of template fields structures taken 377b05b116SKees Cookfrom the set of the supported ones. 387b05b116SKees Cook 397b05b116SKees CookAfter the initialization step, IMA will call ``ima_alloc_init_template()`` 407b05b116SKees Cook(new function defined within the patches for the new template management 417b05b116SKees Cookmechanism) to generate a new measurement entry by using the template 427b05b116SKees Cookdescriptor chosen through the kernel configuration or through the newly 437b05b116SKees Cookintroduced ``ima_template`` and ``ima_template_fmt`` kernel command line parameters. 447b05b116SKees CookIt is during this phase that the advantages of the new architecture are 457b05b116SKees Cookclearly shown: the latter function will not contain specific code to handle 467b05b116SKees Cooka given template but, instead, it simply calls the ``init()`` method of the template 477b05b116SKees Cookfields associated to the chosen template descriptor and store the result 487b05b116SKees Cook(pointer to allocated data and data length) in the measurement entry structure. 497b05b116SKees Cook 507b05b116SKees CookThe same mechanism is employed to display measurements entries. 517b05b116SKees CookThe functions ``ima[_ascii]_measurements_show()`` retrieve, for each entry, 527b05b116SKees Cookthe template descriptor used to produce that entry and call the show() 537b05b116SKees Cookmethod for each item of the array of template fields structures. 547b05b116SKees Cook 557b05b116SKees Cook 567b05b116SKees Cook 577b05b116SKees CookSupported Template Fields and Descriptors 587b05b116SKees Cook========================================= 597b05b116SKees Cook 607b05b116SKees CookIn the following, there is the list of supported template fields 617b05b116SKees Cook``('<identifier>': description)``, that can be used to define new template 627b05b116SKees Cookdescriptors by adding their identifier to the format string 637b05b116SKees Cook(support for more data types will be added later): 647b05b116SKees Cook 657b05b116SKees Cook - 'd': the digest of the event (i.e. the digest of a measured file), 667b05b116SKees Cook calculated with the SHA1 or MD5 hash algorithm; 677b05b116SKees Cook - 'n': the name of the event (i.e. the file name), with size up to 255 bytes; 687b05b116SKees Cook - 'd-ng': the digest of the event, calculated with an arbitrary hash 6964466462SMimi Zohar algorithm (field format: <hash algo>:digest); 7054f03916SMimi Zohar - 'd-ngv2': same as d-ng, but prefixed with the "ima" or "verity" digest type 71989dc725SMimi Zohar (field format: <digest type>:<hash algo>:digest); 723878d505SThiago Jung Bauermann - 'd-modsig': the digest of the event without the appended modsig; 737b05b116SKees Cook - 'n-ng': the name of the event, without size limitations; 74*398c42e2SMimi Zohar - 'sig': the file signature, based on either the file's/fsverity's digest[1], 75*398c42e2SMimi Zohar or the EVM portable signature, if 'security.ima' contains a file hash. 763878d505SThiago Jung Bauermann - 'modsig' the appended file signature; 7786b4da8cSPrakhar Srivastava - 'buf': the buffer data that was used to generate the hash without size limitations; 78026d7fc9SRoberto Sassu - 'evmsig': the EVM portable signature; 797dcfeaccSRoberto Sassu - 'iuid': the inode UID; 807dcfeaccSRoberto Sassu - 'igid': the inode GID; 81f8216f6bSRoberto Sassu - 'imode': the inode mode; 8222a558f5SRoberto Sassu - 'xattrnames': a list of xattr names (separated by ``|``), only if the xattr is 838314b673SRoberto Sassu present; 848314b673SRoberto Sassu - 'xattrlengths': a list of xattr lengths (u32), only if the xattr is present; 858314b673SRoberto Sassu - 'xattrvalues': a list of xattr values; 867b05b116SKees Cook 877b05b116SKees Cook 887b05b116SKees CookBelow, there is the list of defined template descriptors: 897b05b116SKees Cook 907b05b116SKees Cook - "ima": its format is ``d|n``; 917b05b116SKees Cook - "ima-ng" (default): its format is ``d-ng|n-ng``; 92989dc725SMimi Zohar - "ima-ngv2": its format is ``d-ngv2|n-ng``; 9386b4da8cSPrakhar Srivastava - "ima-sig": its format is ``d-ng|n-ng|sig``; 94989dc725SMimi Zohar - "ima-sigv2": its format is ``d-ngv2|n-ng|sig``; 9586b4da8cSPrakhar Srivastava - "ima-buf": its format is ``d-ng|n-ng|buf``; 963878d505SThiago Jung Bauermann - "ima-modsig": its format is ``d-ng|n-ng|sig|d-modsig|modsig``; 9788016de3SRoberto Sassu - "evm-sig": its format is ``d-ng|n-ng|evmsig|xattrnames|xattrlengths|xattrvalues|iuid|igid|imode``; 987b05b116SKees Cook 997b05b116SKees Cook 1007b05b116SKees CookUse 1017b05b116SKees Cook=== 1027b05b116SKees Cook 1037b05b116SKees CookTo specify the template descriptor to be used to generate measurement entries, 1047b05b116SKees Cookcurrently the following methods are supported: 1057b05b116SKees Cook 1067b05b116SKees Cook - select a template descriptor among those supported in the kernel 1077b05b116SKees Cook configuration (``ima-ng`` is the default choice); 1087b05b116SKees Cook - specify a template descriptor name from the kernel command line through 1097b05b116SKees Cook the ``ima_template=`` parameter; 1107b05b116SKees Cook - register a new template descriptor with custom format through the kernel 1117b05b116SKees Cook command line parameter ``ima_template_fmt=``. 112