diff mbox series

[06/17] file: Implement fcheck_task

Message ID 20200817220425.9389-6-ebiederm@xmission.com
State Not Applicable
Delegated to: David Miller
Headers show
Series [01/17] exec: Move unshare_files to fix posix file locking during exec | expand

Commit Message

Eric W. Biederman Aug. 17, 2020, 10:04 p.m. UTC
As a companion to fget_task implement fcheck_task for use for querying
a process about a specific file.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 fs/file.c               | 13 +++++++++++++
 include/linux/fdtable.h |  1 +
 2 files changed, 14 insertions(+)

Comments

Christian Brauner Aug. 18, 2020, 10:37 a.m. UTC | #1
On Mon, Aug 17, 2020 at 05:04:14PM -0500, Eric W. Biederman wrote:
> As a companion to fget_task implement fcheck_task for use for querying
> a process about a specific file.
> 
> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
> ---

Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
diff mbox series

Patch

diff --git a/fs/file.c b/fs/file.c
index c585dbaf31a3..8d4b385055e9 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -863,6 +863,19 @@  struct file *fget_task(struct task_struct *task, unsigned int fd)
 	return file;
 }
 
+struct file *fcheck_task(struct task_struct *task, unsigned int fd)
+{
+	/* Must be called with rcu_read_lock held */
+	struct file *file = NULL;
+
+	task_lock(task);
+	if (task->files)
+		file = fcheck_files(task->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 7cc9885044d9..def9debd2ce2 100644
--- a/include/linux/fdtable.h
+++ b/include/linux/fdtable.h
@@ -103,6 +103,7 @@  static inline struct file *fcheck_files(struct files_struct *files, unsigned int
  * Check whether the specified fd has an open file.
  */
 #define fcheck(fd)	fcheck_files(current->files, fd)
+struct file *fcheck_task(struct task_struct *task, unsigned int fd);
 
 struct task_struct;