[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200817220425.9389-17-ebiederm@xmission.com>
Date: Mon, 17 Aug 2020 17:04:25 -0500
From: "Eric W. Biederman" <ebiederm@...ssion.com>
To: linux-kernel@...r.kernel.org
Cc: linux-fsdevel@...r.kernel.org, criu@...nvz.org,
bpf@...r.kernel.org,
Linus Torvalds <torvalds@...ux-foundation.org>,
Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <christian.brauner@...ntu.com>,
Oleg Nesterov <oleg@...hat.com>,
Cyrill Gorcunov <gorcunov@...il.com>,
Jann Horn <jann@...jh.net>, Kees Cook <keescook@...omium.org>,
Daniel P. Berrangé <berrange@...hat.com>,
Jeff Layton <jlayton@...hat.com>,
Miklos Szeredi <miklos@...redi.hu>,
Matthew Wilcox <willy@...ian.org>,
"J. Bruce Fields" <bfields@...ldses.org>,
Matthew Wilcox <matthew@....cx>,
Trond Myklebust <trond.myklebust@....uio.no>,
Chris Wright <chrisw@...hat.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
Andrii Nakryiko <andriin@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...omium.org>,
"Eric W. Biederman" <ebiederm@...ssion.com>
Subject: [PATCH 17/17] file: Rename __close_fd to close_fd and remove the files parameter
The function __close_fd was added to support binder[1]. Now that
binder has been fixed to no longer need __close_fd[2] and
get_files_struct has been removed it is no longer possible to
correctly call __close_fd with anything current->files pass as it's
files parameter.
Therefore transform the files parameter into a local variable
initialized to current->files, and rename __close_fd to close_fd to
reflect this change, and keep it in sync with the similar changes to
__alloc_fd, and __fd_install.
This removes the need for callers to care about the extra care that
needs to be take if anything except current->files is passed, by
limiting the callers to only operation on current->files.
[1] 483ce1d4b8c3 ("take descriptor-related part of close() to file.c")
[2] 44d8047f1d87 ("binder: use standard functions to allocate fds")
Signed-off-by: "Eric W. Biederman" <ebiederm@...ssion.com>
---
fs/file.c | 10 ++++------
fs/open.c | 2 +-
include/linux/fdtable.h | 3 +--
include/linux/syscalls.h | 6 +++---
4 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/fs/file.c b/fs/file.c
index 221fc4f97f61..b06b04d65070 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -614,11 +614,9 @@ static struct file *pick_file(struct files_struct *files, unsigned fd)
return file;
}
-/*
- * The same warnings as for __alloc_fd()/__fd_install() apply here...
- */
-int __close_fd(struct files_struct *files, unsigned fd)
+int close_fd(unsigned fd)
{
+ struct files_struct *files = current->files;
struct file *file;
file = pick_file(files, fd);
@@ -627,7 +625,7 @@ int __close_fd(struct files_struct *files, unsigned fd)
return filp_close(file, files);
}
-EXPORT_SYMBOL(__close_fd); /* for ksys_close() */
+EXPORT_SYMBOL(close_fd); /* for ksys_close() */
/**
* __close_range() - Close all file descriptors in a given range.
@@ -1010,7 +1008,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
struct files_struct *files = current->files;
if (!file)
- return __close_fd(files, fd);
+ return close_fd(fd);
if (fd >= rlimit(RLIMIT_NOFILE))
return -EBADF;
diff --git a/fs/open.c b/fs/open.c
index 9af548fb841b..581a674d7eee 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -1292,7 +1292,7 @@ EXPORT_SYMBOL(filp_close);
*/
SYSCALL_DEFINE1(close, unsigned int, fd)
{
- int retval = __close_fd(current->files, fd);
+ int retval = close_fd(fd);
/* can't restart close syscall because file table entry was cleared */
if (unlikely(retval == -ERESTARTSYS ||
diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
index d8f6c4921d85..d1b8f3d85493 100644
--- a/include/linux/fdtable.h
+++ b/include/linux/fdtable.h
@@ -116,8 +116,7 @@ int iterate_fd(struct files_struct *, unsigned,
int (*)(const void *, struct file *, unsigned),
const void *);
-extern int __close_fd(struct files_struct *files,
- unsigned int fd);
+extern int close_fd(unsigned int fd);
extern int __close_range(unsigned int fd, unsigned int max_fd, unsigned int flags);
extern int __close_fd_get_file(unsigned int fd, struct file **res);
extern int unshare_fd(unsigned long unshare_flags, unsigned int max_fds,
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 75ac7f8ae93c..a3f48cf49206 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -1293,16 +1293,16 @@ static inline long ksys_ftruncate(unsigned int fd, loff_t length)
return do_sys_ftruncate(fd, length, 1);
}
-extern int __close_fd(struct files_struct *files, unsigned int fd);
+extern int close_fd(unsigned int fd);
/*
* In contrast to sys_close(), this stub does not check whether the syscall
* should or should not be restarted, but returns the raw error codes from
- * __close_fd().
+ * close_fd().
*/
static inline int ksys_close(unsigned int fd)
{
- return __close_fd(current->files, fd);
+ return close_fd(fd);
}
extern long do_sys_truncate(const char __user *pathname, loff_t length);
--
2.25.0
Powered by blists - more mailing lists