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 697b05b116SKees Cook algorithm (field format: [<hash algo>:]digest, where the digest 707b05b116SKees Cook prefix is shown only if the hash algorithm is not SHA1 or MD5); 71*3878d505SThiago Jung Bauermann - 'd-modsig': the digest of the event without the appended modsig; 727b05b116SKees Cook - 'n-ng': the name of the event, without size limitations; 7386b4da8cSPrakhar Srivastava - 'sig': the file signature; 74*3878d505SThiago Jung Bauermann - 'modsig' the appended file signature; 7586b4da8cSPrakhar Srivastava - 'buf': the buffer data that was used to generate the hash without size limitations; 767b05b116SKees Cook 777b05b116SKees Cook 787b05b116SKees CookBelow, there is the list of defined template descriptors: 797b05b116SKees Cook 807b05b116SKees Cook - "ima": its format is ``d|n``; 817b05b116SKees Cook - "ima-ng" (default): its format is ``d-ng|n-ng``; 8286b4da8cSPrakhar Srivastava - "ima-sig": its format is ``d-ng|n-ng|sig``; 8386b4da8cSPrakhar Srivastava - "ima-buf": its format is ``d-ng|n-ng|buf``; 84*3878d505SThiago Jung Bauermann - "ima-modsig": its format is ``d-ng|n-ng|sig|d-modsig|modsig``; 857b05b116SKees Cook 867b05b116SKees Cook 877b05b116SKees CookUse 887b05b116SKees Cook=== 897b05b116SKees Cook 907b05b116SKees CookTo specify the template descriptor to be used to generate measurement entries, 917b05b116SKees Cookcurrently the following methods are supported: 927b05b116SKees Cook 937b05b116SKees Cook - select a template descriptor among those supported in the kernel 947b05b116SKees Cook configuration (``ima-ng`` is the default choice); 957b05b116SKees Cook - specify a template descriptor name from the kernel command line through 967b05b116SKees Cook the ``ima_template=`` parameter; 977b05b116SKees Cook - register a new template descriptor with custom format through the kernel 987b05b116SKees Cook command line parameter ``ima_template_fmt=``. 99