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
3462 inode->i_state |= I_LINKABLE;3462 inode->i_state |= I_LINKABLE;
3463 spin_unlock(&inode->i_lock);3463 spin_unlock(&inode->i_lock);
3464 }3464 }
3465 ima_post_create_tmpfile(inode);
3465 return child;3466 return child;
3466 3467
3467out_err:3468out_err:
include/linux/ima.h+5−0
@@ -18,6 +18,7 @@ struct linux_binprm; · 17 unmodified lines
18#ifdef CONFIG_IMA18#ifdef CONFIG_IMA
19extern int ima_bprm_check(struct linux_binprm *bprm);19extern int ima_bprm_check(struct linux_binprm *bprm);
20extern int ima_file_check(struct file *file, int mask);20extern int ima_file_check(struct file *file, int mask);
21extern void ima_post_create_tmpfile(struct inode *inode);
21extern void ima_file_free(struct file *file);22extern void ima_file_free(struct file *file);
22extern int ima_file_mmap(struct file *file, unsigned long prot);23extern int ima_file_mmap(struct file *file, unsigned long prot);
23extern int ima_load_data(enum kernel_load_data_id id);24extern 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
56 return 0;57 return 0;
57}58}
58 59
60static inline void ima_post_create_tmpfile(struct inode *inode)
61{
62}
63
59static inline void ima_file_free(struct file *file)64static inline void ima_file_free(struct file *file)
60{65{
61 return;66 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
396}396}
397EXPORT_SYMBOL_GPL(ima_file_check);397EXPORT_SYMBOL_GPL(ima_file_check);
398 398
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 */
407void 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
399/**426/**
400 * ima_post_path_mknod - mark as a new inode427 * ima_post_path_mknod - mark as a new inode
401 * @dentry: newly created dentry428 * @dentry: newly created dentry
@@ -413,9 +440,13 @@ void ima_post_path_mknod(struct dentry *dentry) · 11 unmodified lines
413 if (!must_appraise)440 if (!must_appraise)
414 return;441 return;
415 442
443 /* Nothing to do if we can't allocate memory */
416 iint = integrity_inode_get(inode);444 iint = integrity_inode_get(inode);
417 if (iint)445 if (!iint)
418 iint->flags |= IMA_NEW_FILE;446 return;
447
448 /* needed for re-opening empty files */
449 iint->flags |= IMA_NEW_FILE;
419}450}
420 451
421/**452/**

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