linux-next: manual merge of the integrity tree with the pidfd tree

From: Stephen Rothwell
Date: Wed Jan 27 2021 - 00:09:06 EST


Hi all,

FIXME: Add owner of second tree to To:
Add author(s)/SOB of conflicting commits.

Today's linux-next merge of the integrity tree got a conflict in:

security/integrity/ima/ima_main.c

between commit:

a2d2329e30e2 ("ima: handle idmapped mounts")

from the pidfd tree and commits:

2b4a2474a202 ("IMA: generalize keyring specific measurement constructs")
291af651b350 ("IMA: add support to measure buffer data hash")
d6e645012d97 ("IMA: define a hook to measure kernel integrity critical data")

from the integrity tree.

In ima_measure_critical_data(), process_buffer_measurement() is called
with a NULL inode and func set to CRITCTAL_DATA. In this case, the
mnt_userns parameter is not used (I followed the call chain down) and
so I just passed a NULL for it.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging. You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

--
Cheers,
Stephen Rothwell

diff --cc security/integrity/ima/ima_main.c
index cb1c56eccd6d,6a429846f90a..000000000000
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@@ -816,22 -809,22 +816,24 @@@ int ima_post_load_data(char *buf, loff_
}

/*
- * process_buffer_measurement - Measure the buffer to ima log.
+ * process_buffer_measurement - Measure the buffer or the buffer data hash
+ * @mnt_userns: user namespace of the mount the inode was found from
* @inode: inode associated with the object being measured (NULL for KEY_CHECK)
* @buf: pointer to the buffer that needs to be added to the log.
* @size: size of buffer(in bytes).
* @eventname: event name to be used for the buffer entry.
* @func: IMA hook
* @pcr: pcr to extend the measurement
- * @keyring: keyring name to determine the action to be performed
+ * @func_data: func specific data, may be NULL
+ * @buf_hash: measure buffer data hash
*
- * Based on policy, the buffer is measured into the ima log.
+ * Based on policy, either the buffer data or buffer data hash is measured
*/
-void process_buffer_measurement(struct inode *inode, const void *buf, int size,
+void process_buffer_measurement(struct user_namespace *mnt_userns,
+ struct inode *inode, const void *buf, int size,
const char *eventname, enum ima_hooks func,
- int pcr, const char *keyring)
+ int pcr, const char *func_data,
+ bool buf_hash)
{
int ret = 0;
const char *audit_cause = "ENOMEM";
@@@ -869,9 -864,8 +873,9 @@@
*/
if (func) {
security_task_getsecid(current, &secid);
- action = ima_get_action(inode, current_cred(), secid, 0, func,
- &pcr, &template, func_data);
+ action = ima_get_action(mnt_userns, inode, current_cred(),
+ secid, 0, func, &pcr, &template,
- keyring);
++ func_data);
if (!(action & IMA_MEASURE))
return;
}
@@@ -929,12 -937,38 +947,38 @@@ void ima_kexec_cmdline(int kernel_fd, c
if (!f.file)
return;

- process_buffer_measurement(file_inode(f.file), buf, size,
- "kexec-cmdline", KEXEC_CMDLINE, 0, NULL,
- false);
+ process_buffer_measurement(file_mnt_user_ns(f.file), file_inode(f.file),
+ buf, size, "kexec-cmdline", KEXEC_CMDLINE, 0,
- NULL);
++ NULL, false);
fdput(f);
}

+ /**
+ * ima_measure_critical_data - measure kernel integrity critical data
+ * @event_label: unique event label for grouping and limiting critical data
+ * @event_name: event name for the record in the IMA measurement list
+ * @buf: pointer to buffer data
+ * @buf_len: length of buffer data (in bytes)
+ * @hash: measure buffer data hash
+ *
+ * Measure data critical to the integrity of the kernel into the IMA log
+ * and extend the pcr. Examples of critical data could be various data
+ * structures, policies, and states stored in kernel memory that can
+ * impact the integrity of the system.
+ */
+ void ima_measure_critical_data(const char *event_label,
+ const char *event_name,
+ const void *buf, size_t buf_len,
+ bool hash)
+ {
+ if (!event_name || !event_label || !buf || !buf_len)
+ return;
+
- process_buffer_measurement(NULL, buf, buf_len, event_name,
++ process_buffer_measurement(NULL, NULL, buf, buf_len, event_name,
+ CRITICAL_DATA, 0, event_label,
+ hash);
+ }
+
static int __init init_ima(void)
{
int error;

Attachment: pgpfXGP151enj.pgp
Description: OpenPGP digital signature