Skip to content

Commit 08abce6

Browse files
robertosassupcmoore
authored andcommitted
security: Introduce path_post_mknod hook
In preparation for moving IMA and EVM to the LSM infrastructure, introduce the path_post_mknod hook. IMA-appraisal requires all existing files in policy to have a file hash/signature stored in security.ima. An exception is made for empty files created by mknod, by tagging them as new files. LSMs could also take some action after files are created. The new hook cannot return an error and cannot cause the operation to be reverted. 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 f09068b commit 08abce6

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

fs/namei.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4063,6 +4063,11 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode,
40634063
dentry, mode, 0);
40644064
break;
40654065
}
4066+
4067+
if (error)
4068+
goto out2;
4069+
4070+
security_path_post_mknod(idmap, dentry);
40664071
out2:
40674072
done_path_create(&path, dentry);
40684073
if (retry_estale(error, lookup_flags)) {

include/linux/lsm_hook_defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ LSM_HOOK(int, 0, path_mkdir, const struct path *dir, struct dentry *dentry,
9494
LSM_HOOK(int, 0, path_rmdir, const struct path *dir, struct dentry *dentry)
9595
LSM_HOOK(int, 0, path_mknod, const struct path *dir, struct dentry *dentry,
9696
umode_t mode, unsigned int dev)
97+
LSM_HOOK(void, LSM_RET_VOID, path_post_mknod, struct mnt_idmap *idmap,
98+
struct dentry *dentry)
9799
LSM_HOOK(int, 0, path_truncate, const struct path *path)
98100
LSM_HOOK(int, 0, path_symlink, const struct path *dir, struct dentry *dentry,
99101
const char *old_name)

include/linux/security.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,7 @@ int security_path_mkdir(const struct path *dir, struct dentry *dentry, umode_t m
18931893
int security_path_rmdir(const struct path *dir, struct dentry *dentry);
18941894
int security_path_mknod(const struct path *dir, struct dentry *dentry, umode_t mode,
18951895
unsigned int dev);
1896+
void security_path_post_mknod(struct mnt_idmap *idmap, struct dentry *dentry);
18961897
int security_path_truncate(const struct path *path);
18971898
int security_path_symlink(const struct path *dir, struct dentry *dentry,
18981899
const char *old_name);
@@ -1927,6 +1928,10 @@ static inline int security_path_mknod(const struct path *dir, struct dentry *den
19271928
return 0;
19281929
}
19291930

1931+
static inline void security_path_post_mknod(struct mnt_idmap *idmap,
1932+
struct dentry *dentry)
1933+
{ }
1934+
19301935
static inline int security_path_truncate(const struct path *path)
19311936
{
19321937
return 0;

security/security.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,20 @@ int security_path_mknod(const struct path *dir, struct dentry *dentry,
18001800
}
18011801
EXPORT_SYMBOL(security_path_mknod);
18021802

1803+
/**
1804+
* security_path_post_mknod() - Update inode security field after file creation
1805+
* @idmap: idmap of the mount
1806+
* @dentry: new file
1807+
*
1808+
* Update inode security field after a file has been created.
1809+
*/
1810+
void security_path_post_mknod(struct mnt_idmap *idmap, struct dentry *dentry)
1811+
{
1812+
if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
1813+
return;
1814+
call_void_hook(path_post_mknod, idmap, dentry);
1815+
}
1816+
18031817
/**
18041818
* security_path_mkdir() - Check if creating a new directory is allowed
18051819
* @dir: parent directory

0 commit comments

Comments
 (0)