8
8
#include <linux/module.h>
9
9
#include <linux/init.h>
10
10
#include <linux/file.h>
11
+ #include <linux/binfmts.h>
11
12
#include <linux/fs.h>
12
13
#include <linux/xattr.h>
13
14
#include <linux/magic.h>
@@ -469,6 +470,17 @@ int ima_check_blacklist(struct ima_iint_cache *iint,
469
470
return rc ;
470
471
}
471
472
473
+ static bool is_bprm_creds_for_exec (enum ima_hooks func , struct file * file )
474
+ {
475
+ struct linux_binprm * bprm ;
476
+
477
+ if (func == BPRM_CHECK ) {
478
+ bprm = container_of (& file , struct linux_binprm , file );
479
+ return bprm -> is_check ;
480
+ }
481
+ return false;
482
+ }
483
+
472
484
/*
473
485
* ima_appraise_measurement - appraise file measurement
474
486
*
@@ -483,6 +495,7 @@ int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint,
483
495
int xattr_len , const struct modsig * modsig )
484
496
{
485
497
static const char op [] = "appraise_data" ;
498
+ int audit_msgno = AUDIT_INTEGRITY_DATA ;
486
499
const char * cause = "unknown" ;
487
500
struct dentry * dentry = file_dentry (file );
488
501
struct inode * inode = d_backing_inode (dentry );
@@ -494,6 +507,16 @@ int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint,
494
507
if (!(inode -> i_opflags & IOP_XATTR ) && !try_modsig )
495
508
return INTEGRITY_UNKNOWN ;
496
509
510
+ /*
511
+ * Unlike any of the other LSM hooks where the kernel enforces file
512
+ * integrity, enforcing file integrity for the bprm_creds_for_exec()
513
+ * LSM hook with the AT_EXECVE_CHECK flag is left up to the discretion
514
+ * of the script interpreter(userspace). Differentiate kernel and
515
+ * userspace enforced integrity audit messages.
516
+ */
517
+ if (is_bprm_creds_for_exec (func , file ))
518
+ audit_msgno = AUDIT_INTEGRITY_USERSPACE ;
519
+
497
520
/* If reading the xattr failed and there's no modsig, error out. */
498
521
if (rc <= 0 && !try_modsig ) {
499
522
if (rc && rc != - ENODATA )
@@ -569,7 +592,7 @@ int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint,
569
592
(iint -> flags & IMA_FAIL_UNVERIFIABLE_SIGS ))) {
570
593
status = INTEGRITY_FAIL ;
571
594
cause = "unverifiable-signature" ;
572
- integrity_audit_msg (AUDIT_INTEGRITY_DATA , inode , filename ,
595
+ integrity_audit_msg (audit_msgno , inode , filename ,
573
596
op , cause , rc , 0 );
574
597
} else if (status != INTEGRITY_PASS ) {
575
598
/* Fix mode, but don't replace file signatures. */
@@ -589,7 +612,7 @@ int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint,
589
612
status = INTEGRITY_PASS ;
590
613
}
591
614
592
- integrity_audit_msg (AUDIT_INTEGRITY_DATA , inode , filename ,
615
+ integrity_audit_msg (audit_msgno , inode , filename ,
593
616
op , cause , rc , 0 );
594
617
} else {
595
618
ima_cache_flags (iint , func );
0 commit comments