History

ima: define ima_post_create_tmpfile() hook and add missing call

If tmpfiles can be made persistent, then newly created tmpfiles need to be treated like any other new files in policy. This patch indicates which newly created tmpfiles are in policy, causing the file hash to be calculated on __fput().

Mimi Zohar committed 7 years ago

Commit fdb24101 parent c8b37523 files · +39 −2Browse files

Unified · Split

3 files
  1. fs/namei.c +1 −0
  2. include/linux/ima.h +5 −0
  3. security/integrity/ima/ima_main.c +33 −2
fs/namei.c+1−0
@@ -3462,6 +3462,7 @@ struct dentry *vfs_tmpfile(struct dentry *dentry, umode_t mode, int open_flag) · 3461 unmodified lines
34623462 inode->i_state |= I_LINKABLE;
34633463 spin_unlock(&inode->i_lock);
34643464 }
3465+ ima_post_create_tmpfile(inode);
34653466 return child;
34663467
34673468 out_err:
include/linux/ima.h+5−0
@@ -18,6 +18,7 @@ struct linux_binprm; · 17 unmodified lines
1818 #ifdef CONFIG_IMA
1919 extern int ima_bprm_check(struct linux_binprm *bprm);
2020 extern int ima_file_check(struct file *file, int mask);
21+extern void ima_post_create_tmpfile(struct inode *inode);
2122 extern void ima_file_free(struct file *file);
2223 extern int ima_file_mmap(struct file *file, unsigned long prot);
2324 extern int ima_load_data(enum kernel_load_data_id id);
@@ -56,6 +57,10 @@ static inline int ima_file_check(struct file *file, int mask) · 32 unmodified lines
5657 return 0;
5758 }
5859
60+static inline void ima_post_create_tmpfile(struct inode *inode)
61+{
62+}
63+
5964 static inline void ima_file_free(struct file *file)
6065 {
6166 return;
security/integrity/ima/ima_main.c+33−2
@@ -396,6 +396,33 @@ int ima_file_check(struct file *file, int mask) · 395 unmodified lines
396396 }
397397 EXPORT_SYMBOL_GPL(ima_file_check);
398398
399+/**
400+ * ima_post_create_tmpfile - mark newly created tmpfile as new
401+ * @file : newly created tmpfile
402+ *
403+ * No measuring, appraising or auditing of newly created tmpfiles is needed.
404+ * Skip calling process_measurement(), but indicate which newly, created
405+ * tmpfiles are in policy.
406+ */
407+void ima_post_create_tmpfile(struct inode *inode)
408+{
409+ struct integrity_iint_cache *iint;
410+ int must_appraise;
411+
412+ must_appraise = ima_must_appraise(inode, MAY_ACCESS, FILE_CHECK);
413+ if (!must_appraise)
414+ return;
415+
416+ /* Nothing to do if we can't allocate memory */
417+ iint = integrity_inode_get(inode);
418+ if (!iint)
419+ return;
420+
421+ /* needed for writing the security xattrs */
422+ set_bit(IMA_UPDATE_XATTR, &iint->atomic_flags);
423+ iint->ima_file_status = INTEGRITY_PASS;
424+}
425+
399426 /**
400427 * ima_post_path_mknod - mark as a new inode
401428 * @dentry: newly created dentry
@@ -413,9 +440,13 @@ void ima_post_path_mknod(struct dentry *dentry) · 11 unmodified lines
413440 if (!must_appraise)
414441 return;
415442
443+ /* Nothing to do if we can't allocate memory */
416444 iint = integrity_inode_get(inode);
417− if (iint)
418− iint->flags |= IMA_NEW_FILE;
445+ if (!iint)
446+ return;
447+
448+ /* needed for re-opening empty files */
449+ iint->flags |= IMA_NEW_FILE;
419450 }
420451
421452 /**

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t