public inbox for [email protected]
 help / color / mirror / Atom feed
From: Jens Axboe <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], Jens Axboe <[email protected]>
Subject: [PATCH 5/6] net: allow specific fd selection for __sys_accept4_file()
Date: Wed,  4 Mar 2020 11:00:15 -0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

If 'open_fd' being passed in is != -1, make accept4() use the specific
fd instead of finding a free unused one.

Signed-off-by: Jens Axboe <[email protected]>
---
 include/linux/socket.h | 2 +-
 net/socket.c           | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/linux/socket.h b/include/linux/socket.h
index fc59ac825561..ce6c97d4a439 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -405,7 +405,7 @@ extern int __sys_sendto(int fd, void __user *buff, size_t len,
 			int addr_len);
 extern int __sys_accept4_file(struct file *file, unsigned file_flags,
 			struct sockaddr __user *upeer_sockaddr,
-			 int __user *upeer_addrlen, int flags);
+			 int __user *upeer_addrlen, int flags, int open_fd);
 extern int __sys_accept4(int fd, struct sockaddr __user *upeer_sockaddr,
 			 int __user *upeer_addrlen, int flags);
 extern int __sys_socket(int family, int type, int protocol);
diff --git a/net/socket.c b/net/socket.c
index 70ede74ab24b..a9793b778701 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1707,7 +1707,7 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
 
 int __sys_accept4_file(struct file *file, unsigned file_flags,
 		       struct sockaddr __user *upeer_sockaddr,
-		       int __user *upeer_addrlen, int flags)
+		       int __user *upeer_addrlen, int flags, int open_fd)
 {
 	struct socket *sock, *newsock;
 	struct file *newfile;
@@ -1719,6 +1719,8 @@ int __sys_accept4_file(struct file *file, unsigned file_flags,
 
 	if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
 		flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
+	if (open_fd != -1)
+		flags |= O_SPECIFIC_FD;
 
 	sock = sock_from_file(file, &err);
 	if (!sock)
@@ -1738,7 +1740,7 @@ int __sys_accept4_file(struct file *file, unsigned file_flags,
 	 */
 	__module_get(newsock->ops->owner);
 
-	newfd = get_unused_fd_flags(flags);
+	newfd = get_specific_unused_fd_flags(open_fd, flags);
 	if (unlikely(newfd < 0)) {
 		err = newfd;
 		sock_release(newsock);
@@ -1807,7 +1809,7 @@ int __sys_accept4(int fd, struct sockaddr __user *upeer_sockaddr,
 	f = fdget(fd);
 	if (f.file) {
 		ret = __sys_accept4_file(f.file, 0, upeer_sockaddr,
-						upeer_addrlen, flags);
+						upeer_addrlen, flags, -1);
 		if (f.flags)
 			fput(f.file);
 	}
-- 
2.25.1


  parent reply	other threads:[~2020-03-04 18:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-04 18:00 [PATCHSET v2 0/6] Support selectable file descriptors Jens Axboe
2020-03-04 18:00 ` [PATCH 1/6] fs: openat2: Extend open_how to allow userspace-selected fds Jens Axboe
2020-03-04 18:00 ` [PATCH 2/6] io_uring: move CLOSE req->file checking into handler Jens Axboe
2020-03-04 18:00 ` [PATCH 3/6] io_uring: move read/write side file based prep into op handler Jens Axboe
2020-03-04 18:00 ` [PATCH 4/6] io_uring: support deferred retrival of file from fd Jens Axboe
2020-03-04 18:00 ` Jens Axboe [this message]
2020-03-04 18:00 ` [PATCH 6/6] io_uring: allow specific fd for IORING_OP_ACCEPT Jens Axboe
2020-03-04 19:02   ` Josh Triplett
2020-03-04 19:09     ` Jens Axboe
2020-03-04 19:51       ` Josh Triplett
2020-03-04 19:03 ` [PATCHSET v2 0/6] Support selectable file descriptors Josh Triplett
2020-03-04 19:10   ` Jens Axboe
2020-03-04 19:28     ` Jeff Layton
2020-03-04 19:50       ` Jens Axboe
2020-03-04 19:56     ` Josh Triplett
2020-03-04 20:00       ` Jens Axboe
2020-03-04 20:09         ` Josh Triplett
2020-03-04 20:14           ` Jens Axboe
2020-03-09 20:33 ` Stefan Metzmacher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox