Skip to content

Commit a7811e3

Browse files
robertosassupcmoore
authored andcommitted
security: Introduce inode_post_create_tmpfile hook
In preparation for moving IMA and EVM to the LSM infrastructure, introduce the inode_post_create_tmpfile hook. As temp files can be made persistent, treat new temp files like other new files, so that the file hash is calculated and stored in the security xattr. LSMs could also take some action after temp files have been created. The new hook cannot return an error and cannot cause the operation to be canceled. Signed-off-by: Roberto Sassu <[email protected]> Acked-by: Casey Schaufler <[email protected]> Reviewed-by: Mimi Zohar <[email protected]> Acked-by: Christian Brauner <[email protected]> Reviewed-by: Stefan Berger <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 08abce6 commit a7811e3

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

fs/namei.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3705,6 +3705,7 @@ static int vfs_tmpfile(struct mnt_idmap *idmap,
37053705
inode->i_state |= I_LINKABLE;
37063706
spin_unlock(&inode->i_lock);
37073707
}
3708+
security_inode_post_create_tmpfile(idmap, inode);
37083709
ima_post_create_tmpfile(idmap, inode);
37093710
return 0;
37103711
}

include/linux/lsm_hook_defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ LSM_HOOK(int, 0, inode_init_security_anon, struct inode *inode,
121121
const struct qstr *name, const struct inode *context_inode)
122122
LSM_HOOK(int, 0, inode_create, struct inode *dir, struct dentry *dentry,
123123
umode_t mode)
124+
LSM_HOOK(void, LSM_RET_VOID, inode_post_create_tmpfile, struct mnt_idmap *idmap,
125+
struct inode *inode)
124126
LSM_HOOK(int, 0, inode_link, struct dentry *old_dentry, struct inode *dir,
125127
struct dentry *new_dentry)
126128
LSM_HOOK(int, 0, inode_unlink, struct inode *dir, struct dentry *dentry)

include/linux/security.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ int security_inode_init_security_anon(struct inode *inode,
344344
const struct qstr *name,
345345
const struct inode *context_inode);
346346
int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode);
347+
void security_inode_post_create_tmpfile(struct mnt_idmap *idmap,
348+
struct inode *inode);
347349
int security_inode_link(struct dentry *old_dentry, struct inode *dir,
348350
struct dentry *new_dentry);
349351
int security_inode_unlink(struct inode *dir, struct dentry *dentry);
@@ -811,6 +813,10 @@ static inline int security_inode_create(struct inode *dir,
811813
return 0;
812814
}
813815

816+
static inline void
817+
security_inode_post_create_tmpfile(struct mnt_idmap *idmap, struct inode *inode)
818+
{ }
819+
814820
static inline int security_inode_link(struct dentry *old_dentry,
815821
struct inode *dir,
816822
struct dentry *new_dentry)

security/security.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,21 @@ int security_inode_create(struct inode *dir, struct dentry *dentry,
20132013
}
20142014
EXPORT_SYMBOL_GPL(security_inode_create);
20152015

2016+
/**
2017+
* security_inode_post_create_tmpfile() - Update inode security of new tmpfile
2018+
* @idmap: idmap of the mount
2019+
* @inode: inode of the new tmpfile
2020+
*
2021+
* Update inode security data after a tmpfile has been created.
2022+
*/
2023+
void security_inode_post_create_tmpfile(struct mnt_idmap *idmap,
2024+
struct inode *inode)
2025+
{
2026+
if (unlikely(IS_PRIVATE(inode)))
2027+
return;
2028+
call_void_hook(inode_post_create_tmpfile, idmap, inode);
2029+
}
2030+
20162031
/**
20172032
* security_inode_link() - Check if creating a hard link is allowed
20182033
* @old_dentry: existing file

0 commit comments

Comments
 (0)