kcmp: In kcmp_epoll_target use fget_task

Use the helper fget_task and simplify the code.

As well as simplifying the code this removes one unnecessary increment of
struct files_struct.  This unnecessary increment of files_struct.count can
result in exec unnecessarily unsharing files_struct and breaking posix
locks, and it can result in fget_light having to fallback to fget reducing
performance.

Suggested-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@gmail.com>
v1: https://lkml.kernel.org/r/20200817220425.9389-4-ebiederm@xmission.com
Link: https://lkml.kernel.org/r/20201120231441.29911-4-ebiederm@xmission.com
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
This commit is contained in:
Eric W. Biederman 2020-11-20 17:14:21 -06:00
Родитель 950db38ff2
Коммит f43c283a89
1 изменённых файлов: 4 добавлений и 16 удалений

Просмотреть файл

@ -107,7 +107,6 @@ static int kcmp_epoll_target(struct task_struct *task1,
{ {
struct file *filp, *filp_epoll, *filp_tgt; struct file *filp, *filp_epoll, *filp_tgt;
struct kcmp_epoll_slot slot; struct kcmp_epoll_slot slot;
struct files_struct *files;
if (copy_from_user(&slot, uslot, sizeof(slot))) if (copy_from_user(&slot, uslot, sizeof(slot)))
return -EFAULT; return -EFAULT;
@ -116,23 +115,12 @@ static int kcmp_epoll_target(struct task_struct *task1,
if (!filp) if (!filp)
return -EBADF; return -EBADF;
files = get_files_struct(task2); filp_epoll = fget_task(task2, slot.efd);
if (!files) if (!filp_epoll)
return -EBADF; return -EBADF;
spin_lock(&files->file_lock); filp_tgt = get_epoll_tfile_raw_ptr(filp_epoll, slot.tfd, slot.toff);
filp_epoll = fcheck_files(files, slot.efd); fput(filp_epoll);
if (filp_epoll)
get_file(filp_epoll);
else
filp_tgt = ERR_PTR(-EBADF);
spin_unlock(&files->file_lock);
put_files_struct(files);
if (filp_epoll) {
filp_tgt = get_epoll_tfile_raw_ptr(filp_epoll, slot.tfd, slot.toff);
fput(filp_epoll);
}
if (IS_ERR(filp_tgt)) if (IS_ERR(filp_tgt))
return PTR_ERR(filp_tgt); return PTR_ERR(filp_tgt);