···13301330 Formats: { "ima" | "ima-ng" }13311331 Default: "ima-ng"1332133213331333+ ima_template_fmt=13341334+ [IMA] Define a custom template format.13351335+ Format: { "field1|...|fieldN" }13361336+13331337 ima.ahash_minsize= [IMA] Minimum file size for asynchronous hash usage13341338 Format: <min_file_size>13351339 Set the minimal file size for using asynchronous hash.
+14-15
Documentation/security/IMA-templates.txt
···2727a new data type, developers define the field identifier and implement2828two functions, init() and show(), respectively to generate and display2929measurement entries. Defining a new template descriptor requires3030-specifying the template format, a string of field identifiers separated3131-by the '|' character. While in the current implementation it is possible3232-to define new template descriptors only by adding their definition in the3333-template specific code (ima_template.c), in a future version it will be3434-possible to register a new template on a running kernel by supplying to IMA3535-the desired format string. In this version, IMA initializes at boot time3636-all defined template descriptors by translating the format into an array3737-of template fields structures taken from the set of the supported ones.3030+specifying the template format (a string of field identifiers separated3131+by the '|' character) through the 'ima_template_fmt' kernel command line3232+parameter. At boot time, IMA initializes the chosen template descriptor3333+by translating the format into an array of template fields structures taken3434+from the set of the supported ones.38353936After the initialization step, IMA will call ima_alloc_init_template()4037(new function defined within the patches for the new template management4138mechanism) to generate a new measurement entry by using the template4239descriptor chosen through the kernel configuration or through the newly4343-introduced 'ima_template=' kernel command line parameter. It is during this4444-phase that the advantages of the new architecture are clearly shown:4545-the latter function will not contain specific code to handle a given template4646-but, instead, it simply calls the init() method of the template fields4747-associated to the chosen template descriptor and store the result (pointer4848-to allocated data and data length) in the measurement entry structure.4040+introduced 'ima_template' and 'ima_template_fmt' kernel command line parameters.4141+It is during this phase that the advantages of the new architecture are4242+clearly shown: the latter function will not contain specific code to handle4343+a given template but, instead, it simply calls the init() method of the template4444+fields associated to the chosen template descriptor and store the result4545+(pointer to allocated data and data length) in the measurement entry structure.49465047The same mechanism is employed to display measurements entries.5148The functions ima[_ascii]_measurements_show() retrieve, for each entry,···8386 - select a template descriptor among those supported in the kernel8487 configuration ('ima-ng' is the default choice);8588 - specify a template descriptor name from the kernel command line through8686- the 'ima_template=' parameter.8989+ the 'ima_template=' parameter;9090+ - register a new template descriptor with custom format through the kernel9191+ command line parameter 'ima_template_fmt='.
+18-6
fs/read_write.c
···412412413413EXPORT_SYMBOL(new_sync_read);414414415415+ssize_t __vfs_read(struct file *file, char __user *buf, size_t count,416416+ loff_t *pos)417417+{418418+ ssize_t ret;419419+420420+ if (file->f_op->read)421421+ ret = file->f_op->read(file, buf, count, pos);422422+ else if (file->f_op->aio_read)423423+ ret = do_sync_read(file, buf, count, pos);424424+ else if (file->f_op->read_iter)425425+ ret = new_sync_read(file, buf, count, pos);426426+ else427427+ ret = -EINVAL;428428+429429+ return ret;430430+}431431+415432ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)416433{417434 ssize_t ret;···443426 ret = rw_verify_area(READ, file, pos, count);444427 if (ret >= 0) {445428 count = ret;446446- if (file->f_op->read)447447- ret = file->f_op->read(file, buf, count, pos);448448- else if (file->f_op->aio_read)449449- ret = do_sync_read(file, buf, count, pos);450450- else451451- ret = new_sync_read(file, buf, count, pos);429429+ ret = __vfs_read(file, buf, count, pos);452430 if (ret > 0) {453431 fsnotify_access(file);454432 add_rchar(current, ret);
···7878#include <linux/context_tracking.h>7979#include <linux/random.h>8080#include <linux/list.h>8181+#include <linux/integrity.h>81828283#include <asm/io.h>8384#include <asm/bugs.h>···10281027 * Ok, we have completed the initial bootup, and10291028 * we're essentially up and running. Get rid of the10301029 * initmem segments and start the user-mode stuff..10301030+ *10311031+ * rootfs is available now, try loading the public keys10321032+ * and default modules10311033 */1032103410331033- /* rootfs is available now, try loading default modules */10351035+ integrity_load_keys();10341036 load_default_modules();10351037}
···162162 (const char *)xattr_data, xattr_len,163163 calc.digest, sizeof(calc.digest));164164 if (!rc) {165165- /* we probably want to replace rsa with hmac here */166166- evm_update_evmxattr(dentry, xattr_name, xattr_value,167167- xattr_value_len);165165+ /* Replace RSA with HMAC if not mounted readonly and166166+ * not immutable167167+ */168168+ if (!IS_RDONLY(dentry->d_inode) &&169169+ !IS_IMMUTABLE(dentry->d_inode))170170+ evm_update_evmxattr(dentry, xattr_name,171171+ xattr_value,172172+ xattr_value_len);168173 }169174 break;170175 default:
+85-3
security/integrity/iint.c
···1919#include <linux/module.h>2020#include <linux/spinlock.h>2121#include <linux/rbtree.h>2222+#include <linux/file.h>2323+#include <linux/uaccess.h>2224#include "integrity.h"23252426static struct rb_root integrity_iint_tree = RB_ROOT;2527static DEFINE_RWLOCK(integrity_iint_lock);2628static struct kmem_cache *iint_cache __read_mostly;2727-2828-int iint_initialized;29293030/*3131 * __integrity_iint_find - return the iint associated with an inode···166166 iint_cache =167167 kmem_cache_create("iint_cache", sizeof(struct integrity_iint_cache),168168 0, SLAB_PANIC, init_once);169169- iint_initialized = 1;170169 return 0;171170}172171security_initcall(integrity_iintcache_init);172172+173173+174174+/*175175+ * integrity_kernel_read - read data from the file176176+ *177177+ * This is a function for reading file content instead of kernel_read().178178+ * It does not perform locking checks to ensure it cannot be blocked.179179+ * It does not perform security checks because it is irrelevant for IMA.180180+ *181181+ */182182+int integrity_kernel_read(struct file *file, loff_t offset,183183+ char *addr, unsigned long count)184184+{185185+ mm_segment_t old_fs;186186+ char __user *buf = (char __user *)addr;187187+ ssize_t ret;188188+189189+ if (!(file->f_mode & FMODE_READ))190190+ return -EBADF;191191+192192+ old_fs = get_fs();193193+ set_fs(get_ds());194194+ ret = __vfs_read(file, buf, count, &offset);195195+ set_fs(old_fs);196196+197197+ return ret;198198+}199199+200200+/*201201+ * integrity_read_file - read entire file content into the buffer202202+ *203203+ * This is function opens a file, allocates the buffer of required204204+ * size, read entire file content to the buffer and closes the file205205+ *206206+ * It is used only by init code.207207+ *208208+ */209209+int __init integrity_read_file(const char *path, char **data)210210+{211211+ struct file *file;212212+ loff_t size;213213+ char *buf;214214+ int rc = -EINVAL;215215+216216+ file = filp_open(path, O_RDONLY, 0);217217+ if (IS_ERR(file)) {218218+ rc = PTR_ERR(file);219219+ pr_err("Unable to open file: %s (%d)", path, rc);220220+ return rc;221221+ }222222+223223+ size = i_size_read(file_inode(file));224224+ if (size <= 0)225225+ goto out;226226+227227+ buf = kmalloc(size, GFP_KERNEL);228228+ if (!buf) {229229+ rc = -ENOMEM;230230+ goto out;231231+ }232232+233233+ rc = integrity_kernel_read(file, 0, buf, size);234234+ if (rc < 0)235235+ kfree(buf);236236+ else if (rc != size)237237+ rc = -EIO;238238+ else239239+ *data = buf;240240+out:241241+ fput(file);242242+ return rc;243243+}244244+245245+/*246246+ * integrity_load_keys - load integrity keys hook247247+ *248248+ * Hooks is called from init/main.c:kernel_init_freeable()249249+ * when rootfs is ready250250+ */251251+void __init integrity_load_keys(void)252252+{253253+ ima_load_x509();254254+}
+25
security/integrity/ima/Kconfig
···131131 help132132 This option requires that all keys added to the .ima133133 keyring be signed by a key on the system trusted keyring.134134+135135+config IMA_LOAD_X509136136+ bool "Load X509 certificate onto the '.ima' trusted keyring"137137+ depends on IMA_TRUSTED_KEYRING138138+ default n139139+ help140140+ File signature verification is based on the public keys141141+ loaded on the .ima trusted keyring. These public keys are142142+ X509 certificates signed by a trusted key on the143143+ .system keyring. This option enables X509 certificate144144+ loading from the kernel onto the '.ima' trusted keyring.145145+146146+config IMA_X509_PATH147147+ string "IMA X509 certificate path"148148+ depends on IMA_LOAD_X509149149+ default "/etc/keys/x509_ima.der"150150+ help151151+ This option defines IMA X509 certificate path.152152+153153+config IMA_APPRAISE_SIGNED_INIT154154+ bool "Require signed user-space initialization"155155+ depends on IMA_LOAD_X509156156+ default n157157+ help158158+ This option requires user-space init to be signed.