security: Create file_truncate hook from path_truncate hook

Like path_truncate, the file_truncate hook also restricts file
truncation, but is called in the cases where truncation is attempted
on an already-opened file.

This is required in a subsequent commit to handle ftruncate()
operations differently to truncate() operations.

Acked-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Günther Noack <gnoack3000@gmail.com>
Link: https://lore.kernel.org/r/20221018182216.301684-2-gnoack3000@gmail.com
Signed-off-by: Mickaël Salaün <mic@digikod.net>
This commit is contained in:
Günther Noack
2022-10-18 20:22:06 +02:00
committed by Mickaël Salaün
parent 9abf2313ad
commit 3350607dc5
8 changed files with 42 additions and 3 deletions

View File

@@ -1652,6 +1652,11 @@ int security_file_open(struct file *file)
return fsnotify_perm(file, MAY_OPEN);
}
int security_file_truncate(struct file *file)
{
return call_int_hook(file_truncate, 0, file);
}
int security_task_alloc(struct task_struct *task, unsigned long clone_flags)
{
int rc = lsm_task_alloc(task);