lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri,  8 May 2020 17:36:23 +0200
From:   Christoph Hellwig <hch@....de>
To:     Alexander Viro <viro@...iv.linux.org.uk>
Cc:     linux-integrity@...r.kernel.org, linux-kernel@...r.kernel.org,
        linux-gpio@...r.kernel.org, dri-devel@...ts.freedesktop.org,
        linux-rdma@...r.kernel.org, kvm@...r.kernel.org,
        linux-fsdevel@...r.kernel.org, io-uring@...r.kernel.org,
        netdev@...r.kernel.org, bpf@...r.kernel.org
Subject: [PATCH 01/12] fd: add a new __anon_inode_getfd helper

Add a helper that is equivalent to anon_inode_getfd minus the final
fd_install.

Signed-off-by: Christoph Hellwig <hch@....de>
---
 fs/anon_inodes.c            | 41 ++++++++++++++++++++++---------------
 include/linux/anon_inodes.h |  2 ++
 2 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 89714308c25b8..1b2acd2bbaa32 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -106,6 +106,26 @@ struct file *anon_inode_getfile(const char *name,
 }
 EXPORT_SYMBOL_GPL(anon_inode_getfile);
 
+int __anon_inode_getfd(const char *name, const struct file_operations *fops,
+		     void *priv, int flags, struct file **file)
+{
+	int fd;
+
+	fd = get_unused_fd_flags(flags);
+	if (fd < 0)
+		return fd;
+
+	*file = anon_inode_getfile(name, fops, priv, flags);
+	if (IS_ERR(*file))
+		goto err_put_unused_fd;
+	return fd;
+
+err_put_unused_fd:
+	put_unused_fd(fd);
+	return PTR_ERR(*file);
+}
+EXPORT_SYMBOL_GPL(__anon_inode_getfd);
+
 /**
  * anon_inode_getfd - creates a new file instance by hooking it up to an
  *                    anonymous inode, and a dentry that describe the "class"
@@ -125,26 +145,13 @@ EXPORT_SYMBOL_GPL(anon_inode_getfile);
 int anon_inode_getfd(const char *name, const struct file_operations *fops,
 		     void *priv, int flags)
 {
-	int error, fd;
 	struct file *file;
+	int fd;
 
-	error = get_unused_fd_flags(flags);
-	if (error < 0)
-		return error;
-	fd = error;
-
-	file = anon_inode_getfile(name, fops, priv, flags);
-	if (IS_ERR(file)) {
-		error = PTR_ERR(file);
-		goto err_put_unused_fd;
-	}
-	fd_install(fd, file);
-
+	fd = __anon_inode_getfd(name, fops, priv, flags, &file);
+	if (fd >= 0)
+		fd_install(fd, file);
 	return fd;
-
-err_put_unused_fd:
-	put_unused_fd(fd);
-	return error;
 }
 EXPORT_SYMBOL_GPL(anon_inode_getfd);
 
diff --git a/include/linux/anon_inodes.h b/include/linux/anon_inodes.h
index d0d7d96261adf..338449d06b617 100644
--- a/include/linux/anon_inodes.h
+++ b/include/linux/anon_inodes.h
@@ -16,6 +16,8 @@ struct file *anon_inode_getfile(const char *name,
 				void *priv, int flags);
 int anon_inode_getfd(const char *name, const struct file_operations *fops,
 		     void *priv, int flags);
+int __anon_inode_getfd(const char *name, const struct file_operations *fops,
+		     void *priv, int flags, struct file **file);
 
 #endif /* _LINUX_ANON_INODES_H */
 
-- 
2.26.2

Powered by blists - more mailing lists