Commit a7811e34 authored by Roberto Sassu's avatar Roberto Sassu Committed by Paul Moore

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: default avatarRoberto Sassu <roberto.sassu@huawei.com>
Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
Reviewed-by: default avatarMimi Zohar <zohar@linux.ibm.com>
Acked-by: default avatarChristian Brauner <brauner@kernel.org>
Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
parent 08abce60
...@@ -3705,6 +3705,7 @@ static int vfs_tmpfile(struct mnt_idmap *idmap, ...@@ -3705,6 +3705,7 @@ static int vfs_tmpfile(struct mnt_idmap *idmap,
inode->i_state |= I_LINKABLE; inode->i_state |= I_LINKABLE;
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
} }
security_inode_post_create_tmpfile(idmap, inode);
ima_post_create_tmpfile(idmap, inode); ima_post_create_tmpfile(idmap, inode);
return 0; return 0;
} }
......
...@@ -121,6 +121,8 @@ LSM_HOOK(int, 0, inode_init_security_anon, struct inode *inode, ...@@ -121,6 +121,8 @@ LSM_HOOK(int, 0, inode_init_security_anon, struct inode *inode,
const struct qstr *name, const struct inode *context_inode) const struct qstr *name, const struct inode *context_inode)
LSM_HOOK(int, 0, inode_create, struct inode *dir, struct dentry *dentry, LSM_HOOK(int, 0, inode_create, struct inode *dir, struct dentry *dentry,
umode_t mode) umode_t mode)
LSM_HOOK(void, LSM_RET_VOID, inode_post_create_tmpfile, struct mnt_idmap *idmap,
struct inode *inode)
LSM_HOOK(int, 0, inode_link, struct dentry *old_dentry, struct inode *dir, LSM_HOOK(int, 0, inode_link, struct dentry *old_dentry, struct inode *dir,
struct dentry *new_dentry) struct dentry *new_dentry)
LSM_HOOK(int, 0, inode_unlink, struct inode *dir, struct dentry *dentry) LSM_HOOK(int, 0, inode_unlink, struct inode *dir, struct dentry *dentry)
......
...@@ -344,6 +344,8 @@ int security_inode_init_security_anon(struct inode *inode, ...@@ -344,6 +344,8 @@ int security_inode_init_security_anon(struct inode *inode,
const struct qstr *name, const struct qstr *name,
const struct inode *context_inode); const struct inode *context_inode);
int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode); int security_inode_create(struct inode *dir, struct dentry *dentry, umode_t mode);
void security_inode_post_create_tmpfile(struct mnt_idmap *idmap,
struct inode *inode);
int security_inode_link(struct dentry *old_dentry, struct inode *dir, int security_inode_link(struct dentry *old_dentry, struct inode *dir,
struct dentry *new_dentry); struct dentry *new_dentry);
int security_inode_unlink(struct inode *dir, struct dentry *dentry); int security_inode_unlink(struct inode *dir, struct dentry *dentry);
...@@ -811,6 +813,10 @@ static inline int security_inode_create(struct inode *dir, ...@@ -811,6 +813,10 @@ static inline int security_inode_create(struct inode *dir,
return 0; return 0;
} }
static inline void
security_inode_post_create_tmpfile(struct mnt_idmap *idmap, struct inode *inode)
{ }
static inline int security_inode_link(struct dentry *old_dentry, static inline int security_inode_link(struct dentry *old_dentry,
struct inode *dir, struct inode *dir,
struct dentry *new_dentry) struct dentry *new_dentry)
......
...@@ -2013,6 +2013,21 @@ int security_inode_create(struct inode *dir, struct dentry *dentry, ...@@ -2013,6 +2013,21 @@ int security_inode_create(struct inode *dir, struct dentry *dentry,
} }
EXPORT_SYMBOL_GPL(security_inode_create); EXPORT_SYMBOL_GPL(security_inode_create);
/**
* security_inode_post_create_tmpfile() - Update inode security of new tmpfile
* @idmap: idmap of the mount
* @inode: inode of the new tmpfile
*
* Update inode security data after a tmpfile has been created.
*/
void security_inode_post_create_tmpfile(struct mnt_idmap *idmap,
struct inode *inode)
{
if (unlikely(IS_PRIVATE(inode)))
return;
call_void_hook(inode_post_create_tmpfile, idmap, inode);
}
/** /**
* security_inode_link() - Check if creating a hard link is allowed * security_inode_link() - Check if creating a hard link is allowed
* @old_dentry: existing file * @old_dentry: existing file
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment