Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 701b389

Browse files
robertosassutorvalds
authored andcommittedApr 3, 2024
security: Place security_path_post_mknod() where the original IMA call was
Commit 08abce6 ("security: Introduce path_post_mknod hook") introduced security_path_post_mknod(), to replace the IMA-specific call to ima_post_path_mknod(). For symmetry with security_path_mknod(), security_path_post_mknod() was called after a successful mknod operation, for any file type, rather than only for regular files at the time there was the IMA call. However, as reported by VFS maintainers, successful mknod operation does not mean that the dentry always has an inode attached to it (for example, not for FIFOs on a SAMBA mount). If that condition happens, the kernel crashes when security_path_post_mknod() attempts to verify if the inode associated to the dentry is private. Move security_path_post_mknod() where the ima_post_path_mknod() call was, which is obviously correct from IMA/EVM perspective. IMA/EVM are the only in-kernel users, and only need to inspect regular files. Reported-by: Steve French <smfrench@gmail.com> Closes: https://lore.kernel.org/linux-kernel/CAH2r5msAVzxCUHHG8VKrMPUKQHmBpE6K9_vjhgDa1uAvwx4ppw@mail.gmail.com/ Suggested-by: Al Viro <viro@zeniv.linux.org.uk> Fixes: 08abce6 ("security: Introduce path_post_mknod hook") Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Reviewed-by: Christian Brauner <brauner@kernel.org> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com> Acked-by: Paul Moore <paul@paul-moore.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0e11073 commit 701b389

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed
 

‎fs/namei.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -4050,6 +4050,8 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode,
40504050
case 0: case S_IFREG:
40514051
error = vfs_create(idmap, path.dentry->d_inode,
40524052
dentry, mode, true);
4053+
if (!error)
4054+
security_path_post_mknod(idmap, dentry);
40534055
break;
40544056
case S_IFCHR: case S_IFBLK:
40554057
error = vfs_mknod(idmap, path.dentry->d_inode,
@@ -4060,11 +4062,6 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode,
40604062
dentry, mode, 0);
40614063
break;
40624064
}
4063-
4064-
if (error)
4065-
goto out2;
4066-
4067-
security_path_post_mknod(idmap, dentry);
40684065
out2:
40694066
done_path_create(&path, dentry);
40704067
if (retry_estale(error, lookup_flags)) {

‎security/security.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1793,11 +1793,11 @@ int security_path_mknod(const struct path *dir, struct dentry *dentry,
17931793
EXPORT_SYMBOL(security_path_mknod);
17941794

17951795
/**
1796-
* security_path_post_mknod() - Update inode security field after file creation
1796+
* security_path_post_mknod() - Update inode security after reg file creation
17971797
* @idmap: idmap of the mount
17981798
* @dentry: new file
17991799
*
1800-
* Update inode security field after a file has been created.
1800+
* Update inode security field after a regular file has been created.
18011801
*/
18021802
void security_path_post_mknod(struct mnt_idmap *idmap, struct dentry *dentry)
18031803
{

0 commit comments

Comments
 (0)
Please sign in to comment.