1*4882a593Smuzhiyun================================= 2*4882a593SmuzhiyunIMA Template Management Mechanism 3*4882a593Smuzhiyun================================= 4*4882a593Smuzhiyun 5*4882a593Smuzhiyun 6*4882a593SmuzhiyunIntroduction 7*4882a593Smuzhiyun============ 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunThe original ``ima`` template is fixed length, containing the filedata hash 10*4882a593Smuzhiyunand pathname. The filedata hash is limited to 20 bytes (md5/sha1). 11*4882a593SmuzhiyunThe pathname is a null terminated string, limited to 255 characters. 12*4882a593SmuzhiyunTo overcome these limitations and to add additional file metadata, it is 13*4882a593Smuzhiyunnecessary to extend the current version of IMA by defining additional 14*4882a593Smuzhiyuntemplates. For example, information that could be possibly reported are 15*4882a593Smuzhiyunthe inode UID/GID or the LSM labels either of the inode and of the process 16*4882a593Smuzhiyunthat is accessing it. 17*4882a593Smuzhiyun 18*4882a593SmuzhiyunHowever, the main problem to introduce this feature is that, each time 19*4882a593Smuzhiyuna new template is defined, the functions that generate and display 20*4882a593Smuzhiyunthe measurements list would include the code for handling a new format 21*4882a593Smuzhiyunand, thus, would significantly grow over the time. 22*4882a593Smuzhiyun 23*4882a593SmuzhiyunThe proposed solution solves this problem by separating the template 24*4882a593Smuzhiyunmanagement from the remaining IMA code. The core of this solution is the 25*4882a593Smuzhiyundefinition of two new data structures: a template descriptor, to determine 26*4882a593Smuzhiyunwhich information should be included in the measurement list; a template 27*4882a593Smuzhiyunfield, to generate and display data of a given type. 28*4882a593Smuzhiyun 29*4882a593SmuzhiyunManaging templates with these structures is very simple. To support 30*4882a593Smuzhiyuna new data type, developers define the field identifier and implement 31*4882a593Smuzhiyuntwo functions, init() and show(), respectively to generate and display 32*4882a593Smuzhiyunmeasurement entries. Defining a new template descriptor requires 33*4882a593Smuzhiyunspecifying the template format (a string of field identifiers separated 34*4882a593Smuzhiyunby the ``|`` character) through the ``ima_template_fmt`` kernel command line 35*4882a593Smuzhiyunparameter. At boot time, IMA initializes the chosen template descriptor 36*4882a593Smuzhiyunby translating the format into an array of template fields structures taken 37*4882a593Smuzhiyunfrom the set of the supported ones. 38*4882a593Smuzhiyun 39*4882a593SmuzhiyunAfter the initialization step, IMA will call ``ima_alloc_init_template()`` 40*4882a593Smuzhiyun(new function defined within the patches for the new template management 41*4882a593Smuzhiyunmechanism) to generate a new measurement entry by using the template 42*4882a593Smuzhiyundescriptor chosen through the kernel configuration or through the newly 43*4882a593Smuzhiyunintroduced ``ima_template`` and ``ima_template_fmt`` kernel command line parameters. 44*4882a593SmuzhiyunIt is during this phase that the advantages of the new architecture are 45*4882a593Smuzhiyunclearly shown: the latter function will not contain specific code to handle 46*4882a593Smuzhiyuna given template but, instead, it simply calls the ``init()`` method of the template 47*4882a593Smuzhiyunfields associated to the chosen template descriptor and store the result 48*4882a593Smuzhiyun(pointer to allocated data and data length) in the measurement entry structure. 49*4882a593Smuzhiyun 50*4882a593SmuzhiyunThe same mechanism is employed to display measurements entries. 51*4882a593SmuzhiyunThe functions ``ima[_ascii]_measurements_show()`` retrieve, for each entry, 52*4882a593Smuzhiyunthe template descriptor used to produce that entry and call the show() 53*4882a593Smuzhiyunmethod for each item of the array of template fields structures. 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun 57*4882a593SmuzhiyunSupported Template Fields and Descriptors 58*4882a593Smuzhiyun========================================= 59*4882a593Smuzhiyun 60*4882a593SmuzhiyunIn the following, there is the list of supported template fields 61*4882a593Smuzhiyun``('<identifier>': description)``, that can be used to define new template 62*4882a593Smuzhiyundescriptors by adding their identifier to the format string 63*4882a593Smuzhiyun(support for more data types will be added later): 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun - 'd': the digest of the event (i.e. the digest of a measured file), 66*4882a593Smuzhiyun calculated with the SHA1 or MD5 hash algorithm; 67*4882a593Smuzhiyun - 'n': the name of the event (i.e. the file name), with size up to 255 bytes; 68*4882a593Smuzhiyun - 'd-ng': the digest of the event, calculated with an arbitrary hash 69*4882a593Smuzhiyun algorithm (field format: [<hash algo>:]digest, where the digest 70*4882a593Smuzhiyun prefix is shown only if the hash algorithm is not SHA1 or MD5); 71*4882a593Smuzhiyun - 'd-modsig': the digest of the event without the appended modsig; 72*4882a593Smuzhiyun - 'n-ng': the name of the event, without size limitations; 73*4882a593Smuzhiyun - 'sig': the file signature; 74*4882a593Smuzhiyun - 'modsig' the appended file signature; 75*4882a593Smuzhiyun - 'buf': the buffer data that was used to generate the hash without size limitations; 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun 78*4882a593SmuzhiyunBelow, there is the list of defined template descriptors: 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun - "ima": its format is ``d|n``; 81*4882a593Smuzhiyun - "ima-ng" (default): its format is ``d-ng|n-ng``; 82*4882a593Smuzhiyun - "ima-sig": its format is ``d-ng|n-ng|sig``; 83*4882a593Smuzhiyun - "ima-buf": its format is ``d-ng|n-ng|buf``; 84*4882a593Smuzhiyun - "ima-modsig": its format is ``d-ng|n-ng|sig|d-modsig|modsig``; 85*4882a593Smuzhiyun 86*4882a593Smuzhiyun 87*4882a593SmuzhiyunUse 88*4882a593Smuzhiyun=== 89*4882a593Smuzhiyun 90*4882a593SmuzhiyunTo specify the template descriptor to be used to generate measurement entries, 91*4882a593Smuzhiyuncurrently the following methods are supported: 92*4882a593Smuzhiyun 93*4882a593Smuzhiyun - select a template descriptor among those supported in the kernel 94*4882a593Smuzhiyun configuration (``ima-ng`` is the default choice); 95*4882a593Smuzhiyun - specify a template descriptor name from the kernel command line through 96*4882a593Smuzhiyun the ``ima_template=`` parameter; 97*4882a593Smuzhiyun - register a new template descriptor with custom format through the kernel 98*4882a593Smuzhiyun command line parameter ``ima_template_fmt=``. 99