• Roberto Sassu's avatar
    ima: introduce ima_parse_buf() · b17fd9ec
    Roberto Sassu authored
    ima_parse_buf() takes as input the buffer start and end pointers, and
    stores the result in a static array of ima_field_data structures,
    where the len field contains the length parsed from the buffer, and
    the data field contains the address of the buffer just after the length.
    Optionally, the function returns the current value of the buffer pointer
    and the number of array elements written.
    
    A bitmap has been added as parameter of ima_parse_buf() to handle
    the cases where the length is not prepended to data. Each bit corresponds
    to an element of the ima_field_data array. If a bit is set, the length
    is not parsed from the buffer, but is read from the corresponding element
    of the array (the length must be set before calling the function).
    
    ima_parse_buf() can perform three checks upon request by callers,
    depending on the enforce mask passed to it:
    
    - ENFORCE_FIELDS: matching of number of fields (length-data combination)
      - there must be enough data in the buffer to parse the number of fields
        requested (output: current value of buffer pointer)
    - ENFORCE_BUFEND: matching of buffer end
      - the ima_field_data array must be large enough to contain lengths and
        data pointers for the amount of data requested (output: number
        of fields written)
    - ENFORCE_FIELDS | ENFORCE_BUFEND: matching of both
    
    Use cases
    
    - measurement entry header: ENFORCE_FIELDS | ENFORCE_BUFEND
      - four fields must be parsed: pcr, digest, template name, template data
      - ENFORCE_BUFEND is enforced only for the last measurement entry
    - template digest (Crypto Agile): ENFORCE_BUFEND
      - since only the total template digest length is known, the function
        parses length-data combinations until the buffer end is reached
    - template data: ENFORCE_FIELDS | ENFORCE_BUFEND
      - since the number of fields and the total template data length
        are known, the function can perform both checks
    Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
    Signed-off-by: default avatarMimi Zohar <zohar@linux.vnet.ibm.com>
    b17fd9ec
ima_template_lib.c 10.4 KB