fanotify: introduce new event mask FAN_OPEN_EXEC_PERM

A new event mask FAN_OPEN_EXEC_PERM has been defined. This allows users
to receive events and grant access to files that are intending to be
opened for execution. Events of FAN_OPEN_EXEC_PERM type will be
generated when a file has been opened by using either execve(),
execveat() or uselib() system calls.

This acts in the same manner as previous permission event mask, meaning
that an access response is required from the user application in order
to permit any further operations on the file.

Signed-off-by: Matthew Bobrowski <mbobrowski@mbobrowski.org>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
This commit is contained in:
Matthew Bobrowski
2018-11-08 14:12:44 +11:00
committed by Jan Kara
parent a704bba5e3
commit 66917a3130
6 changed files with 23 additions and 11 deletions

View File

@@ -40,9 +40,10 @@ static inline int fsnotify_path(struct inode *inode, const struct path *path,
return fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
}
/* simple call site for access decisions */
/* Simple call site for access decisions */
static inline int fsnotify_perm(struct file *file, int mask)
{
int ret;
const struct path *path = &file->f_path;
struct inode *inode = file_inode(file);
__u32 fsnotify_mask = 0;
@@ -51,12 +52,18 @@ static inline int fsnotify_perm(struct file *file, int mask)
return 0;
if (!(mask & (MAY_READ | MAY_OPEN)))
return 0;
if (mask & MAY_OPEN)
if (mask & MAY_OPEN) {
fsnotify_mask = FS_OPEN_PERM;
else if (mask & MAY_READ)
if (file->f_flags & __FMODE_EXEC) {
ret = fsnotify_path(inode, path, FS_OPEN_EXEC_PERM);
if (ret)
return ret;
}
} else if (mask & MAY_READ) {
fsnotify_mask = FS_ACCESS_PERM;
else
BUG();
}
return fsnotify_path(inode, path, fsnotify_mask);
}