This is a note to let you know that I've just added the patch titled file: Implement task_lookup_fd_rcu to the 5.10-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: file-implement-task_lookup_fd_rcu.patch and it can be found in the queue-5.10 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit 3f3708f566736fa1cfa783187da901a6cbcde952 Author: Eric W. Biederman <ebiederm@xxxxxxxxxxxx> Date: Fri Nov 20 17:14:28 2020 -0600 file: Implement task_lookup_fd_rcu [ Upstream commit 3a879fb38082125cc0d8aa89b70c7f3a7cdf584b ] As a companion to lookup_fd_rcu implement task_lookup_fd_rcu for querying an arbitrary process about a specific file. Acked-by: Christian Brauner <christian.brauner@xxxxxxxxxx> v1: https://lkml.kernel.org/r/20200818103713.aw46m7vprsy4vlve@wittgenstein Link: https://lkml.kernel.org/r/20201120231441.29911-11-ebiederm@xxxxxxxxxxxx Signed-off-by: Eric W. Biederman <ebiederm@xxxxxxxxxxxx> Signed-off-by: Chuck Lever <chuck.lever@xxxxxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/fs/file.c b/fs/file.c index 6149f75a18a66..60a3ccba728cd 100644 --- a/fs/file.c +++ b/fs/file.c @@ -911,6 +911,21 @@ struct file *fget_task(struct task_struct *task, unsigned int fd) return file; } +struct file *task_lookup_fd_rcu(struct task_struct *task, unsigned int fd) +{ + /* Must be called with rcu_read_lock held */ + struct files_struct *files; + struct file *file = NULL; + + task_lock(task); + files = task->files; + if (files) + file = files_lookup_fd_rcu(files, fd); + task_unlock(task); + + return file; +} + /* * Lightweight file lookup - no refcnt increment if fd table isn't shared. * diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h index 695306cc5337a..a88f68f740677 100644 --- a/include/linux/fdtable.h +++ b/include/linux/fdtable.h @@ -110,6 +110,8 @@ static inline struct file *lookup_fd_rcu(unsigned int fd) return files_lookup_fd_rcu(current->files, fd); } +struct file *task_lookup_fd_rcu(struct task_struct *task, unsigned int fd); + struct task_struct; struct files_struct *get_files_struct(struct task_struct *);