mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-01 10:45:49 +00:00
fsnotify: optionally pass access range in file permission hooks
In preparation for pre-content permission events with file access range, move fsnotify_file_perm() hook out of security_file_permission() and into the callers. Callers that have the access range information call the new hook fsnotify_file_area_perm() with the access range. Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Amir Goldstein <amir73il@gmail.com> Link: https://lore.kernel.org/r/20231212094440.250945-6-amir73il@gmail.com Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
cb383f0668
commit
d9e5d31084
@ -304,6 +304,10 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
ret = fsnotify_file_area_perm(file, MAY_WRITE, &offset, len);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
if (S_ISFIFO(inode->i_mode))
|
if (S_ISFIFO(inode->i_mode))
|
||||||
return -ESPIPE;
|
return -ESPIPE;
|
||||||
|
|
||||||
|
@ -354,6 +354,9 @@ SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
|
|||||||
|
|
||||||
int rw_verify_area(int read_write, struct file *file, const loff_t *ppos, size_t count)
|
int rw_verify_area(int read_write, struct file *file, const loff_t *ppos, size_t count)
|
||||||
{
|
{
|
||||||
|
int mask = read_write == READ ? MAY_READ : MAY_WRITE;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (unlikely((ssize_t) count < 0))
|
if (unlikely((ssize_t) count < 0))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
@ -371,8 +374,11 @@ int rw_verify_area(int read_write, struct file *file, const loff_t *ppos, size_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return security_file_permission(file,
|
ret = security_file_permission(file, mask);
|
||||||
read_write == READ ? MAY_READ : MAY_WRITE);
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return fsnotify_file_area_perm(file, mask, ppos, count);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(rw_verify_area);
|
EXPORT_SYMBOL(rw_verify_area);
|
||||||
|
|
||||||
|
@ -96,6 +96,10 @@ int iterate_dir(struct file *file, struct dir_context *ctx)
|
|||||||
if (res)
|
if (res)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
res = fsnotify_file_perm(file, MAY_READ);
|
||||||
|
if (res)
|
||||||
|
goto out;
|
||||||
|
|
||||||
res = down_read_killable(&inode->i_rwsem);
|
res = down_read_killable(&inode->i_rwsem);
|
||||||
if (res)
|
if (res)
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -102,7 +102,9 @@ static int generic_remap_checks(struct file *file_in, loff_t pos_in,
|
|||||||
static int remap_verify_area(struct file *file, loff_t pos, loff_t len,
|
static int remap_verify_area(struct file *file, loff_t pos, loff_t len,
|
||||||
bool write)
|
bool write)
|
||||||
{
|
{
|
||||||
|
int mask = write ? MAY_WRITE : MAY_READ;
|
||||||
loff_t tmp;
|
loff_t tmp;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (unlikely(pos < 0 || len < 0))
|
if (unlikely(pos < 0 || len < 0))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -110,7 +112,11 @@ static int remap_verify_area(struct file *file, loff_t pos, loff_t len,
|
|||||||
if (unlikely(check_add_overflow(pos, len, &tmp)))
|
if (unlikely(check_add_overflow(pos, len, &tmp)))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
return security_file_permission(file, write ? MAY_WRITE : MAY_READ);
|
ret = security_file_permission(file, mask);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
return fsnotify_file_area_perm(file, mask, &pos, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -101,9 +101,10 @@ static inline int fsnotify_file(struct file *file, __u32 mask)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fsnotify_file_perm - permission hook before file access
|
* fsnotify_file_area_perm - permission hook before access to file range
|
||||||
*/
|
*/
|
||||||
static inline int fsnotify_file_perm(struct file *file, int perm_mask)
|
static inline int fsnotify_file_area_perm(struct file *file, int perm_mask,
|
||||||
|
const loff_t *ppos, size_t count)
|
||||||
{
|
{
|
||||||
__u32 fsnotify_mask = FS_ACCESS_PERM;
|
__u32 fsnotify_mask = FS_ACCESS_PERM;
|
||||||
|
|
||||||
@ -120,6 +121,14 @@ static inline int fsnotify_file_perm(struct file *file, int perm_mask)
|
|||||||
return fsnotify_file(file, fsnotify_mask);
|
return fsnotify_file(file, fsnotify_mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fsnotify_file_perm - permission hook before file access
|
||||||
|
*/
|
||||||
|
static inline int fsnotify_file_perm(struct file *file, int perm_mask)
|
||||||
|
{
|
||||||
|
return fsnotify_file_area_perm(file, perm_mask, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fsnotify_open_perm - permission hook before file open
|
* fsnotify_open_perm - permission hook before file open
|
||||||
*/
|
*/
|
||||||
|
@ -2580,13 +2580,7 @@ int security_kernfs_init_security(struct kernfs_node *kn_dir,
|
|||||||
*/
|
*/
|
||||||
int security_file_permission(struct file *file, int mask)
|
int security_file_permission(struct file *file, int mask)
|
||||||
{
|
{
|
||||||
int ret;
|
return call_int_hook(file_permission, 0, file, mask);
|
||||||
|
|
||||||
ret = call_int_hook(file_permission, 0, file, mask);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
return fsnotify_file_perm(file, mask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user