public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring
@ 2024-06-14 16:30 Gabriel Krisman Bertazi
  2024-06-14 16:30 ` [PATCH v2 2/4] net: Split a __sys_listen " Gabriel Krisman Bertazi
                   ` (5 more replies)
  0 siblings, 6 replies; 17+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-06-14 16:30 UTC (permalink / raw)
  To: axboe; +Cc: io-uring, netdev, Gabriel Krisman Bertazi

io_uring holds a reference to the file and maintains a
sockaddr_storage address.  Similarly to what was done to
__sys_connect_file, split an internal helper for __sys_bind in
preparation to supporting an io_uring bind command.

Reviewed-by: Jens Axboe <[email protected]>
Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
---
 include/linux/socket.h |  2 ++
 net/socket.c           | 25 ++++++++++++++++---------
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/include/linux/socket.h b/include/linux/socket.h
index 89d16b90370b..b3000f49e9f5 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -442,6 +442,8 @@ extern int __sys_accept4(int fd, struct sockaddr __user *upeer_sockaddr,
 extern int __sys_socket(int family, int type, int protocol);
 extern struct file *__sys_socket_file(int family, int type, int protocol);
 extern int __sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen);
+extern int __sys_bind_socket(struct socket *sock, struct sockaddr_storage *address,
+			     int addrlen);
 extern int __sys_connect_file(struct file *file, struct sockaddr_storage *addr,
 			      int addrlen, int file_flags);
 extern int __sys_connect(int fd, struct sockaddr __user *uservaddr,
diff --git a/net/socket.c b/net/socket.c
index e416920e9399..fd0714e10ced 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1822,6 +1822,20 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol,
 	return __sys_socketpair(family, type, protocol, usockvec);
 }
 
+int __sys_bind_socket(struct socket *sock, struct sockaddr_storage *address,
+		      int addrlen)
+{
+	int err;
+
+	err = security_socket_bind(sock, (struct sockaddr *)address,
+				   addrlen);
+	if (!err)
+		err = READ_ONCE(sock->ops)->bind(sock,
+						 (struct sockaddr *)address,
+						 addrlen);
+	return err;
+}
+
 /*
  *	Bind a name to a socket. Nothing much to do here since it's
  *	the protocol's responsibility to handle the local address.
@@ -1839,15 +1853,8 @@ int __sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen)
 	sock = sockfd_lookup_light(fd, &err, &fput_needed);
 	if (sock) {
 		err = move_addr_to_kernel(umyaddr, addrlen, &address);
-		if (!err) {
-			err = security_socket_bind(sock,
-						   (struct sockaddr *)&address,
-						   addrlen);
-			if (!err)
-				err = READ_ONCE(sock->ops)->bind(sock,
-						      (struct sockaddr *)
-						      &address, addrlen);
-		}
+		if (!err)
+			err = __sys_bind_socket(sock, &address, addrlen);
 		fput_light(sock->file, fput_needed);
 	}
 	return err;
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 2/4] net: Split a __sys_listen helper for io_uring
  2024-06-14 16:30 [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring Gabriel Krisman Bertazi
@ 2024-06-14 16:30 ` Gabriel Krisman Bertazi
  2024-06-14 22:44   ` Kuniyuki Iwashima
  2024-06-19  0:50   ` Jakub Kicinski
  2024-06-14 16:30 ` [PATCH v2 3/4] io_uring: Introduce IORING_OP_BIND Gabriel Krisman Bertazi
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 17+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-06-14 16:30 UTC (permalink / raw)
  To: axboe; +Cc: io-uring, netdev, Gabriel Krisman Bertazi

io_uring holds a reference to the file and maintains a sockaddr_storage
address.  Similarly to what was done to __sys_connect_file, split an
internal helper for __sys_listen in preparation to support an
io_uring listen command.

Reviewed-by: Jens Axboe <[email protected]>
Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
---
 include/linux/socket.h |  1 +
 net/socket.c           | 23 ++++++++++++++---------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/include/linux/socket.h b/include/linux/socket.h
index b3000f49e9f5..c1f16cdab677 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -449,6 +449,7 @@ extern int __sys_connect_file(struct file *file, struct sockaddr_storage *addr,
 extern int __sys_connect(int fd, struct sockaddr __user *uservaddr,
 			 int addrlen);
 extern int __sys_listen(int fd, int backlog);
+extern int __sys_listen_socket(struct socket *sock, int backlog);
 extern int __sys_getsockname(int fd, struct sockaddr __user *usockaddr,
 			     int __user *usockaddr_len);
 extern int __sys_getpeername(int fd, struct sockaddr __user *usockaddr,
diff --git a/net/socket.c b/net/socket.c
index fd0714e10ced..fcbdd5bc47ac 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1870,23 +1870,28 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
  *	necessary for a listen, and if that works, we mark the socket as
  *	ready for listening.
  */
+int __sys_listen_socket(struct socket *sock, int backlog)
+{
+	int somaxconn, err;
+
+	somaxconn = READ_ONCE(sock_net(sock->sk)->core.sysctl_somaxconn);
+	if ((unsigned int)backlog > somaxconn)
+		backlog = somaxconn;
+
+	err = security_socket_listen(sock, backlog);
+	if (!err)
+		err = READ_ONCE(sock->ops)->listen(sock, backlog);
+	return err;
+}
 
 int __sys_listen(int fd, int backlog)
 {
 	struct socket *sock;
 	int err, fput_needed;
-	int somaxconn;
 
 	sock = sockfd_lookup_light(fd, &err, &fput_needed);
 	if (sock) {
-		somaxconn = READ_ONCE(sock_net(sock->sk)->core.sysctl_somaxconn);
-		if ((unsigned int)backlog > somaxconn)
-			backlog = somaxconn;
-
-		err = security_socket_listen(sock, backlog);
-		if (!err)
-			err = READ_ONCE(sock->ops)->listen(sock, backlog);
-
+		err = __sys_listen_socket(sock, backlog);
 		fput_light(sock->file, fput_needed);
 	}
 	return err;
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 3/4] io_uring: Introduce IORING_OP_BIND
  2024-06-14 16:30 [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring Gabriel Krisman Bertazi
  2024-06-14 16:30 ` [PATCH v2 2/4] net: Split a __sys_listen " Gabriel Krisman Bertazi
@ 2024-06-14 16:30 ` Gabriel Krisman Bertazi
  2024-06-14 22:46   ` Kuniyuki Iwashima
  2024-06-14 16:30 ` [PATCH v2 4/4] io_uring: Introduce IORING_OP_LISTEN Gabriel Krisman Bertazi
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 17+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-06-14 16:30 UTC (permalink / raw)
  To: axboe; +Cc: io-uring, netdev, Gabriel Krisman Bertazi

IORING_OP_BIND provides the semantic of bind(2) via io_uring.  While
this is an essentially synchronous system call, the main point is to
enable a network path to execute fully with io_uring registered and
descriptorless files.

Signed-off-by: Gabriel Krisman Bertazi <[email protected]>

---
changes since v1:
- drop explocit error handling for move_addr_to_kernel (jens)
- Remove empty line ahead of return;
---
 include/uapi/linux/io_uring.h |  1 +
 io_uring/net.c                | 36 +++++++++++++++++++++++++++++++++++
 io_uring/net.h                |  3 +++
 io_uring/opdef.c              | 13 +++++++++++++
 4 files changed, 53 insertions(+)

diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index 994bf7af0efe..4ef153d95c87 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -257,6 +257,7 @@ enum io_uring_op {
 	IORING_OP_FUTEX_WAITV,
 	IORING_OP_FIXED_FD_INSTALL,
 	IORING_OP_FTRUNCATE,
+	IORING_OP_BIND,
 
 	/* this goes last, obviously */
 	IORING_OP_LAST,
diff --git a/io_uring/net.c b/io_uring/net.c
index 0a48596429d9..8cbc29aff15c 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -51,6 +51,11 @@ struct io_connect {
 	bool				seen_econnaborted;
 };
 
+struct io_bind {
+	struct file			*file;
+	int				addr_len;
+};
+
 struct io_sr_msg {
 	struct file			*file;
 	union {
@@ -1715,6 +1720,37 @@ int io_connect(struct io_kiocb *req, unsigned int issue_flags)
 	return IOU_OK;
 }
 
+int io_bind_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+{
+	struct io_bind *bind = io_kiocb_to_cmd(req, struct io_bind);
+	struct sockaddr __user *uaddr;
+	struct io_async_msghdr *io;
+
+	if (sqe->len || sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in)
+		return -EINVAL;
+
+	uaddr = u64_to_user_ptr(READ_ONCE(sqe->addr));
+	bind->addr_len =  READ_ONCE(sqe->addr2);
+
+	io = io_msg_alloc_async(req);
+	if (unlikely(!io))
+		return -ENOMEM;
+	return move_addr_to_kernel(uaddr, bind->addr_len, &io->addr);
+}
+
+int io_bind(struct io_kiocb *req, unsigned int issue_flags)
+{
+	struct io_bind *bind = io_kiocb_to_cmd(req, struct io_bind);
+	struct io_async_msghdr *io = req->async_data;
+	int ret;
+
+	ret = __sys_bind_socket(sock_from_file(req->file),  &io->addr, bind->addr_len);
+	if (ret < 0)
+		req_set_fail(req);
+	io_req_set_res(req, ret, 0);
+	return 0;
+}
+
 void io_netmsg_cache_free(const void *entry)
 {
 	struct io_async_msghdr *kmsg = (struct io_async_msghdr *) entry;
diff --git a/io_uring/net.h b/io_uring/net.h
index 0eb1c1920fc9..49f9a7bc1113 100644
--- a/io_uring/net.h
+++ b/io_uring/net.h
@@ -49,6 +49,9 @@ int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags);
 int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
 void io_send_zc_cleanup(struct io_kiocb *req);
 
+int io_bind_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
+int io_bind(struct io_kiocb *req, unsigned int issue_flags);
+
 void io_netmsg_cache_free(const void *entry);
 #else
 static inline void io_netmsg_cache_free(const void *entry)
diff --git a/io_uring/opdef.c b/io_uring/opdef.c
index 2de5cca9504e..19ee9445f024 100644
--- a/io_uring/opdef.c
+++ b/io_uring/opdef.c
@@ -495,6 +495,16 @@ const struct io_issue_def io_issue_defs[] = {
 		.prep			= io_ftruncate_prep,
 		.issue			= io_ftruncate,
 	},
+	[IORING_OP_BIND] = {
+#if defined(CONFIG_NET)
+		.needs_file		= 1,
+		.prep			= io_bind_prep,
+		.issue			= io_bind,
+		.async_size		= sizeof(struct io_async_msghdr),
+#else
+		.prep			= io_eopnotsupp_prep,
+#endif
+	},
 };
 
 const struct io_cold_def io_cold_defs[] = {
@@ -711,6 +721,9 @@ const struct io_cold_def io_cold_defs[] = {
 	[IORING_OP_FTRUNCATE] = {
 		.name			= "FTRUNCATE",
 	},
+	[IORING_OP_BIND] = {
+		.name			= "BIND",
+	},
 };
 
 const char *io_uring_get_opcode(u8 opcode)
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 4/4] io_uring: Introduce IORING_OP_LISTEN
  2024-06-14 16:30 [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring Gabriel Krisman Bertazi
  2024-06-14 16:30 ` [PATCH v2 2/4] net: Split a __sys_listen " Gabriel Krisman Bertazi
  2024-06-14 16:30 ` [PATCH v2 3/4] io_uring: Introduce IORING_OP_BIND Gabriel Krisman Bertazi
@ 2024-06-14 16:30 ` Gabriel Krisman Bertazi
  2024-06-14 22:42 ` [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring Kuniyuki Iwashima
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 17+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-06-14 16:30 UTC (permalink / raw)
  To: axboe; +Cc: io-uring, netdev, Gabriel Krisman Bertazi

IORING_OP_LISTEN provides the semantic of listen(2) via io_uring.  While
this is an essentially synchronous system call, the main point is to
enable a network path to execute fully with io_uring registered and
descriptorless files.

Signed-off-by: Gabriel Krisman Bertazi <[email protected]>

---
changes since v1:
- Drop empty lines ahead of return (Jens).
---
 include/uapi/linux/io_uring.h |  1 +
 io_uring/net.c                | 28 ++++++++++++++++++++++++++++
 io_uring/net.h                |  3 +++
 io_uring/opdef.c              | 13 +++++++++++++
 4 files changed, 45 insertions(+)

diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index 4ef153d95c87..2aaf7ee256ac 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -258,6 +258,7 @@ enum io_uring_op {
 	IORING_OP_FIXED_FD_INSTALL,
 	IORING_OP_FTRUNCATE,
 	IORING_OP_BIND,
+	IORING_OP_LISTEN,
 
 	/* this goes last, obviously */
 	IORING_OP_LAST,
diff --git a/io_uring/net.c b/io_uring/net.c
index 8cbc29aff15c..028e126ab30c 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -56,6 +56,11 @@ struct io_bind {
 	int				addr_len;
 };
 
+struct io_listen {
+	struct file			*file;
+	int				backlog;
+};
+
 struct io_sr_msg {
 	struct file			*file;
 	union {
@@ -1751,6 +1756,29 @@ int io_bind(struct io_kiocb *req, unsigned int issue_flags)
 	return 0;
 }
 
+int io_listen_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+{
+	struct io_listen *listen = io_kiocb_to_cmd(req, struct io_listen);
+
+	if (sqe->addr || sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in || sqe->addr2)
+		return -EINVAL;
+
+	listen->backlog = READ_ONCE(sqe->len);
+	return 0;
+}
+
+int io_listen(struct io_kiocb *req, unsigned int issue_flags)
+{
+	struct io_listen *listen = io_kiocb_to_cmd(req, struct io_listen);
+	int ret;
+
+	ret = __sys_listen_socket(sock_from_file(req->file), listen->backlog);
+	if (ret < 0)
+		req_set_fail(req);
+	io_req_set_res(req, ret, 0);
+	return 0;
+}
+
 void io_netmsg_cache_free(const void *entry)
 {
 	struct io_async_msghdr *kmsg = (struct io_async_msghdr *) entry;
diff --git a/io_uring/net.h b/io_uring/net.h
index 49f9a7bc1113..52bfee05f06a 100644
--- a/io_uring/net.h
+++ b/io_uring/net.h
@@ -52,6 +52,9 @@ void io_send_zc_cleanup(struct io_kiocb *req);
 int io_bind_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
 int io_bind(struct io_kiocb *req, unsigned int issue_flags);
 
+int io_listen_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
+int io_listen(struct io_kiocb *req, unsigned int issue_flags);
+
 void io_netmsg_cache_free(const void *entry);
 #else
 static inline void io_netmsg_cache_free(const void *entry)
diff --git a/io_uring/opdef.c b/io_uring/opdef.c
index 19ee9445f024..7d5c51fb8e6e 100644
--- a/io_uring/opdef.c
+++ b/io_uring/opdef.c
@@ -503,6 +503,16 @@ const struct io_issue_def io_issue_defs[] = {
 		.async_size		= sizeof(struct io_async_msghdr),
 #else
 		.prep			= io_eopnotsupp_prep,
+#endif
+	},
+	[IORING_OP_LISTEN] = {
+#if defined(CONFIG_NET)
+		.needs_file		= 1,
+		.prep			= io_listen_prep,
+		.issue			= io_listen,
+		.async_size		= sizeof(struct io_async_msghdr),
+#else
+		.prep			= io_eopnotsupp_prep,
 #endif
 	},
 };
@@ -724,6 +734,9 @@ const struct io_cold_def io_cold_defs[] = {
 	[IORING_OP_BIND] = {
 		.name			= "BIND",
 	},
+	[IORING_OP_LISTEN] = {
+		.name			= "LISTEN",
+	},
 };
 
 const char *io_uring_get_opcode(u8 opcode)
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring
  2024-06-14 16:30 [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring Gabriel Krisman Bertazi
                   ` (2 preceding siblings ...)
  2024-06-14 16:30 ` [PATCH v2 4/4] io_uring: Introduce IORING_OP_LISTEN Gabriel Krisman Bertazi
@ 2024-06-14 22:42 ` Kuniyuki Iwashima
  2024-06-19  0:49 ` Jakub Kicinski
  2024-06-19 14:58 ` Jens Axboe
  5 siblings, 0 replies; 17+ messages in thread
From: Kuniyuki Iwashima @ 2024-06-14 22:42 UTC (permalink / raw)
  To: krisman; +Cc: axboe, io-uring, netdev, Kuniyuki Iwashima

From: Gabriel Krisman Bertazi <[email protected]>
Date: Fri, 14 Jun 2024 12:30:44 -0400
> io_uring holds a reference to the file and maintains a
> sockaddr_storage address.  Similarly to what was done to
> __sys_connect_file, split an internal helper for __sys_bind in
> preparation to supporting an io_uring bind command.
> 
> Reviewed-by: Jens Axboe <[email protected]>
> Signed-off-by: Gabriel Krisman Bertazi <[email protected]>

Reviewed-by: Kuniyuki Iwashima <[email protected]>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 2/4] net: Split a __sys_listen helper for io_uring
  2024-06-14 16:30 ` [PATCH v2 2/4] net: Split a __sys_listen " Gabriel Krisman Bertazi
@ 2024-06-14 22:44   ` Kuniyuki Iwashima
  2024-06-19  0:50   ` Jakub Kicinski
  1 sibling, 0 replies; 17+ messages in thread
From: Kuniyuki Iwashima @ 2024-06-14 22:44 UTC (permalink / raw)
  To: krisman; +Cc: axboe, io-uring, netdev, Kuniyuki Iwashima

From: Gabriel Krisman Bertazi <[email protected]>
Date: Fri, 14 Jun 2024 12:30:45 -0400
> io_uring holds a reference to the file and maintains a sockaddr_storage
> address.  Similarly to what was done to __sys_connect_file, split an
> internal helper for __sys_listen in preparation to support an
> io_uring listen command.
> 
> Reviewed-by: Jens Axboe <[email protected]>
> Signed-off-by: Gabriel Krisman Bertazi <[email protected]>

Reviewed-by: Kuniyuki Iwashima <[email protected]>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 3/4] io_uring: Introduce IORING_OP_BIND
  2024-06-14 16:30 ` [PATCH v2 3/4] io_uring: Introduce IORING_OP_BIND Gabriel Krisman Bertazi
@ 2024-06-14 22:46   ` Kuniyuki Iwashima
  2024-06-15  0:27     ` Jens Axboe
  0 siblings, 1 reply; 17+ messages in thread
From: Kuniyuki Iwashima @ 2024-06-14 22:46 UTC (permalink / raw)
  To: krisman; +Cc: axboe, io-uring, netdev

From: Gabriel Krisman Bertazi <[email protected]>
Date: Fri, 14 Jun 2024 12:30:46 -0400
> IORING_OP_BIND provides the semantic of bind(2) via io_uring.  While
> this is an essentially synchronous system call, the main point is to
> enable a network path to execute fully with io_uring registered and
> descriptorless files.
> 
> Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
> 
> ---
> changes since v1:
> - drop explocit error handling for move_addr_to_kernel (jens)
> - Remove empty line ahead of return;
> ---
>  include/uapi/linux/io_uring.h |  1 +
>  io_uring/net.c                | 36 +++++++++++++++++++++++++++++++++++
>  io_uring/net.h                |  3 +++
>  io_uring/opdef.c              | 13 +++++++++++++
>  4 files changed, 53 insertions(+)
> 
> diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
> index 994bf7af0efe..4ef153d95c87 100644
> --- a/include/uapi/linux/io_uring.h
> +++ b/include/uapi/linux/io_uring.h
> @@ -257,6 +257,7 @@ enum io_uring_op {
>  	IORING_OP_FUTEX_WAITV,
>  	IORING_OP_FIXED_FD_INSTALL,
>  	IORING_OP_FTRUNCATE,
> +	IORING_OP_BIND,
>  
>  	/* this goes last, obviously */
>  	IORING_OP_LAST,
> diff --git a/io_uring/net.c b/io_uring/net.c
> index 0a48596429d9..8cbc29aff15c 100644
> --- a/io_uring/net.c
> +++ b/io_uring/net.c
> @@ -51,6 +51,11 @@ struct io_connect {
>  	bool				seen_econnaborted;
>  };
>  
> +struct io_bind {
> +	struct file			*file;
> +	int				addr_len;
> +};
> +
>  struct io_sr_msg {
>  	struct file			*file;
>  	union {
> @@ -1715,6 +1720,37 @@ int io_connect(struct io_kiocb *req, unsigned int issue_flags)
>  	return IOU_OK;
>  }
>  
> +int io_bind_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
> +{
> +	struct io_bind *bind = io_kiocb_to_cmd(req, struct io_bind);
> +	struct sockaddr __user *uaddr;
> +	struct io_async_msghdr *io;
> +
> +	if (sqe->len || sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in)
> +		return -EINVAL;
> +
> +	uaddr = u64_to_user_ptr(READ_ONCE(sqe->addr));
> +	bind->addr_len =  READ_ONCE(sqe->addr2);
                        ^^
nit: double space


> +
> +	io = io_msg_alloc_async(req);
> +	if (unlikely(!io))
> +		return -ENOMEM;
> +	return move_addr_to_kernel(uaddr, bind->addr_len, &io->addr);
> +}
> +
> +int io_bind(struct io_kiocb *req, unsigned int issue_flags)
> +{
> +	struct io_bind *bind = io_kiocb_to_cmd(req, struct io_bind);
> +	struct io_async_msghdr *io = req->async_data;
> +	int ret;
> +
> +	ret = __sys_bind_socket(sock_from_file(req->file),  &io->addr, bind->addr_len);
                                                          ^^
ditto


> +	if (ret < 0)
> +		req_set_fail(req);
> +	io_req_set_res(req, ret, 0);
> +	return 0;
> +}
> +
>  void io_netmsg_cache_free(const void *entry)
>  {
>  	struct io_async_msghdr *kmsg = (struct io_async_msghdr *) entry;
> diff --git a/io_uring/net.h b/io_uring/net.h
> index 0eb1c1920fc9..49f9a7bc1113 100644
> --- a/io_uring/net.h
> +++ b/io_uring/net.h
> @@ -49,6 +49,9 @@ int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags);
>  int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
>  void io_send_zc_cleanup(struct io_kiocb *req);
>  
> +int io_bind_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
> +int io_bind(struct io_kiocb *req, unsigned int issue_flags);
> +
>  void io_netmsg_cache_free(const void *entry);
>  #else
>  static inline void io_netmsg_cache_free(const void *entry)
> diff --git a/io_uring/opdef.c b/io_uring/opdef.c
> index 2de5cca9504e..19ee9445f024 100644
> --- a/io_uring/opdef.c
> +++ b/io_uring/opdef.c
> @@ -495,6 +495,16 @@ const struct io_issue_def io_issue_defs[] = {
>  		.prep			= io_ftruncate_prep,
>  		.issue			= io_ftruncate,
>  	},
> +	[IORING_OP_BIND] = {
> +#if defined(CONFIG_NET)
> +		.needs_file		= 1,
> +		.prep			= io_bind_prep,
> +		.issue			= io_bind,
> +		.async_size		= sizeof(struct io_async_msghdr),
> +#else
> +		.prep			= io_eopnotsupp_prep,
> +#endif
> +	},
>  };
>  
>  const struct io_cold_def io_cold_defs[] = {
> @@ -711,6 +721,9 @@ const struct io_cold_def io_cold_defs[] = {
>  	[IORING_OP_FTRUNCATE] = {
>  		.name			= "FTRUNCATE",
>  	},
> +	[IORING_OP_BIND] = {
> +		.name			= "BIND",
> +	},
>  };
>  
>  const char *io_uring_get_opcode(u8 opcode)
> -- 
> 2.45.2

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 3/4] io_uring: Introduce IORING_OP_BIND
  2024-06-14 22:46   ` Kuniyuki Iwashima
@ 2024-06-15  0:27     ` Jens Axboe
  0 siblings, 0 replies; 17+ messages in thread
From: Jens Axboe @ 2024-06-15  0:27 UTC (permalink / raw)
  To: Kuniyuki Iwashima, krisman; +Cc: io-uring, netdev

On 6/14/24 4:46 PM, Kuniyuki Iwashima wrote:
> From: Gabriel Krisman Bertazi <[email protected]>
> Date: Fri, 14 Jun 2024 12:30:46 -0400
>> IORING_OP_BIND provides the semantic of bind(2) via io_uring.  While
>> this is an essentially synchronous system call, the main point is to
>> enable a network path to execute fully with io_uring registered and
>> descriptorless files.
>>
>> Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
>>
>> ---
>> changes since v1:
>> - drop explocit error handling for move_addr_to_kernel (jens)
>> - Remove empty line ahead of return;
>> ---
>>  include/uapi/linux/io_uring.h |  1 +
>>  io_uring/net.c                | 36 +++++++++++++++++++++++++++++++++++
>>  io_uring/net.h                |  3 +++
>>  io_uring/opdef.c              | 13 +++++++++++++
>>  4 files changed, 53 insertions(+)
>>
>> diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
>> index 994bf7af0efe..4ef153d95c87 100644
>> --- a/include/uapi/linux/io_uring.h
>> +++ b/include/uapi/linux/io_uring.h
>> @@ -257,6 +257,7 @@ enum io_uring_op {
>>  	IORING_OP_FUTEX_WAITV,
>>  	IORING_OP_FIXED_FD_INSTALL,
>>  	IORING_OP_FTRUNCATE,
>> +	IORING_OP_BIND,
>>  
>>  	/* this goes last, obviously */
>>  	IORING_OP_LAST,
>> diff --git a/io_uring/net.c b/io_uring/net.c
>> index 0a48596429d9..8cbc29aff15c 100644
>> --- a/io_uring/net.c
>> +++ b/io_uring/net.c
>> @@ -51,6 +51,11 @@ struct io_connect {
>>  	bool				seen_econnaborted;
>>  };
>>  
>> +struct io_bind {
>> +	struct file			*file;
>> +	int				addr_len;
>> +};
>> +
>>  struct io_sr_msg {
>>  	struct file			*file;
>>  	union {
>> @@ -1715,6 +1720,37 @@ int io_connect(struct io_kiocb *req, unsigned int issue_flags)
>>  	return IOU_OK;
>>  }
>>  
>> +int io_bind_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
>> +{
>> +	struct io_bind *bind = io_kiocb_to_cmd(req, struct io_bind);
>> +	struct sockaddr __user *uaddr;
>> +	struct io_async_msghdr *io;
>> +
>> +	if (sqe->len || sqe->buf_index || sqe->rw_flags || sqe->splice_fd_in)
>> +		return -EINVAL;
>> +
>> +	uaddr = u64_to_user_ptr(READ_ONCE(sqe->addr));
>> +	bind->addr_len =  READ_ONCE(sqe->addr2);
>                         ^^
> nit: double space

Thanks for spotting those, I can just remove those two while applying.
Mostly just a note to Grabriel, no need to re-post for that.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring
  2024-06-14 16:30 [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring Gabriel Krisman Bertazi
                   ` (3 preceding siblings ...)
  2024-06-14 22:42 ` [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring Kuniyuki Iwashima
@ 2024-06-19  0:49 ` Jakub Kicinski
  2024-06-19 13:40   ` Jens Axboe
  2024-06-19 14:58 ` Jens Axboe
  5 siblings, 1 reply; 17+ messages in thread
From: Jakub Kicinski @ 2024-06-19  0:49 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: axboe, io-uring, netdev

On Fri, 14 Jun 2024 12:30:44 -0400 Gabriel Krisman Bertazi wrote:
> io_uring holds a reference to the file and maintains a
> sockaddr_storage address.  Similarly to what was done to
> __sys_connect_file, split an internal helper for __sys_bind in
> preparation to supporting an io_uring bind command.
> 
> Reviewed-by: Jens Axboe <[email protected]>
> Signed-off-by: Gabriel Krisman Bertazi <[email protected]>

Acked-by: Jakub Kicinski <[email protected]>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 2/4] net: Split a __sys_listen helper for io_uring
  2024-06-14 16:30 ` [PATCH v2 2/4] net: Split a __sys_listen " Gabriel Krisman Bertazi
  2024-06-14 22:44   ` Kuniyuki Iwashima
@ 2024-06-19  0:50   ` Jakub Kicinski
  1 sibling, 0 replies; 17+ messages in thread
From: Jakub Kicinski @ 2024-06-19  0:50 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: axboe, io-uring, netdev

On Fri, 14 Jun 2024 12:30:45 -0400 Gabriel Krisman Bertazi wrote:
> io_uring holds a reference to the file and maintains a sockaddr_storage
> address.  Similarly to what was done to __sys_connect_file, split an
> internal helper for __sys_listen in preparation to support an
> io_uring listen command.
> 
> Reviewed-by: Jens Axboe <[email protected]>
> Signed-off-by: Gabriel Krisman Bertazi <[email protected]>

Acked-by: Jakub Kicinski <[email protected]>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring
  2024-06-19  0:49 ` Jakub Kicinski
@ 2024-06-19 13:40   ` Jens Axboe
  2024-06-19 15:04     ` Jakub Kicinski
  0 siblings, 1 reply; 17+ messages in thread
From: Jens Axboe @ 2024-06-19 13:40 UTC (permalink / raw)
  To: Jakub Kicinski, Gabriel Krisman Bertazi; +Cc: io-uring, netdev

On 6/18/24 6:49 PM, Jakub Kicinski wrote:
> On Fri, 14 Jun 2024 12:30:44 -0400 Gabriel Krisman Bertazi wrote:
>> io_uring holds a reference to the file and maintains a
>> sockaddr_storage address.  Similarly to what was done to
>> __sys_connect_file, split an internal helper for __sys_bind in
>> preparation to supporting an io_uring bind command.
>>
>> Reviewed-by: Jens Axboe <[email protected]>
>> Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
> 
> Acked-by: Jakub Kicinski <[email protected]>

Are you fine with me queueing up 1-2 via the io_uring branch?
I'm guessing the risk of conflict should be very low, so doesn't
warrant a shared branch.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring
  2024-06-14 16:30 [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring Gabriel Krisman Bertazi
                   ` (4 preceding siblings ...)
  2024-06-19  0:49 ` Jakub Kicinski
@ 2024-06-19 14:58 ` Jens Axboe
  5 siblings, 0 replies; 17+ messages in thread
From: Jens Axboe @ 2024-06-19 14:58 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: io-uring, netdev


On Fri, 14 Jun 2024 12:30:44 -0400, Gabriel Krisman Bertazi wrote:
> io_uring holds a reference to the file and maintains a
> sockaddr_storage address.  Similarly to what was done to
> __sys_connect_file, split an internal helper for __sys_bind in
> preparation to supporting an io_uring bind command.
> 
> 

Applied, thanks!

[1/4] net: Split a __sys_bind helper for io_uring
      commit: dc2e77979412d289df9049d8c693761db8602867
[2/4] net: Split a __sys_listen helper for io_uring
      commit: bb6aaf736680f0f3c2e6281735c47c64e2042819
[3/4] io_uring: Introduce IORING_OP_BIND
      commit: 7481fd93fa0a851740e26026485f56a1305454ce
[4/4] io_uring: Introduce IORING_OP_LISTEN
      commit: ff140cc8628abfb1755691d16cfa8788d8820ef7

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring
  2024-06-19 13:40   ` Jens Axboe
@ 2024-06-19 15:04     ` Jakub Kicinski
  2024-06-19 15:06       ` Jens Axboe
  0 siblings, 1 reply; 17+ messages in thread
From: Jakub Kicinski @ 2024-06-19 15:04 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Gabriel Krisman Bertazi, io-uring, netdev

On Wed, 19 Jun 2024 07:40:40 -0600 Jens Axboe wrote:
> On 6/18/24 6:49 PM, Jakub Kicinski wrote:
> > On Fri, 14 Jun 2024 12:30:44 -0400 Gabriel Krisman Bertazi wrote:  
> >> io_uring holds a reference to the file and maintains a
> >> sockaddr_storage address.  Similarly to what was done to
> >> __sys_connect_file, split an internal helper for __sys_bind in
> >> preparation to supporting an io_uring bind command.
> >>
> >> Reviewed-by: Jens Axboe <[email protected]>
> >> Signed-off-by: Gabriel Krisman Bertazi <[email protected]>  
> > 
> > Acked-by: Jakub Kicinski <[email protected]>  
> 
> Are you fine with me queueing up 1-2 via the io_uring branch?
> I'm guessing the risk of conflict should be very low, so doesn't
> warrant a shared branch.

Yup, exactly, these can go via io_uring without branch juggling.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring
  2024-06-19 15:04     ` Jakub Kicinski
@ 2024-06-19 15:06       ` Jens Axboe
  2024-07-15 12:49         ` Matus Jokay
  0 siblings, 1 reply; 17+ messages in thread
From: Jens Axboe @ 2024-06-19 15:06 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: Gabriel Krisman Bertazi, io-uring, netdev

On 6/19/24 9:04 AM, Jakub Kicinski wrote:
> On Wed, 19 Jun 2024 07:40:40 -0600 Jens Axboe wrote:
>> On 6/18/24 6:49 PM, Jakub Kicinski wrote:
>>> On Fri, 14 Jun 2024 12:30:44 -0400 Gabriel Krisman Bertazi wrote:  
>>>> io_uring holds a reference to the file and maintains a
>>>> sockaddr_storage address.  Similarly to what was done to
>>>> __sys_connect_file, split an internal helper for __sys_bind in
>>>> preparation to supporting an io_uring bind command.
>>>>
>>>> Reviewed-by: Jens Axboe <[email protected]>
>>>> Signed-off-by: Gabriel Krisman Bertazi <[email protected]>  
>>>
>>> Acked-by: Jakub Kicinski <[email protected]>  
>>
>> Are you fine with me queueing up 1-2 via the io_uring branch?
>> I'm guessing the risk of conflict should be very low, so doesn't
>> warrant a shared branch.
> 
> Yup, exactly, these can go via io_uring without branch juggling.

Great thanks!

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring
  2024-06-19 15:06       ` Jens Axboe
@ 2024-07-15 12:49         ` Matus Jokay
  2024-07-15 13:59           ` Tetsuo Handa
  0 siblings, 1 reply; 17+ messages in thread
From: Matus Jokay @ 2024-07-15 12:49 UTC (permalink / raw)
  To: Jens Axboe, Jakub Kicinski
  Cc: Gabriel Krisman Bertazi, io-uring, netdev, linux-security-module

On 19. 6. 2024 17:06, Jens Axboe wrote:
> On 6/19/24 9:04 AM, Jakub Kicinski wrote:
>> On Wed, 19 Jun 2024 07:40:40 -0600 Jens Axboe wrote:
>>> On 6/18/24 6:49 PM, Jakub Kicinski wrote:
>>>> On Fri, 14 Jun 2024 12:30:44 -0400 Gabriel Krisman Bertazi wrote:  
>>>>> io_uring holds a reference to the file and maintains a
>>>>> sockaddr_storage address.  Similarly to what was done to
>>>>> __sys_connect_file, split an internal helper for __sys_bind in
>>>>> preparation to supporting an io_uring bind command.
>>>>>
>>>>> Reviewed-by: Jens Axboe <[email protected]>
>>>>> Signed-off-by: Gabriel Krisman Bertazi <[email protected]>  
>>>>
>>>> Acked-by: Jakub Kicinski <[email protected]>  
>>>
>>> Are you fine with me queueing up 1-2 via the io_uring branch?
>>> I'm guessing the risk of conflict should be very low, so doesn't
>>> warrant a shared branch.
>>
>> Yup, exactly, these can go via io_uring without branch juggling.
> 
> Great thanks!
> 
Please fix io_bind and io_listen to not pass NULL ptr to related helpers
__sys_bind_socket and __sys_listen_socket. The first helper's argument
shouldn't be NULL, as related security hooks expect a valid socket object.

See the syzkaller's bug report:
https://lore.kernel.org/linux-security-module/[email protected]/

Thanks,
mY

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring
  2024-07-15 12:49         ` Matus Jokay
@ 2024-07-15 13:59           ` Tetsuo Handa
  2024-07-22 12:37             ` Matus Jokay
  0 siblings, 1 reply; 17+ messages in thread
From: Tetsuo Handa @ 2024-07-15 13:59 UTC (permalink / raw)
  To: Matus Jokay, Jens Axboe, Jakub Kicinski
  Cc: Gabriel Krisman Bertazi, io-uring, netdev, linux-security-module

On 2024/07/15 21:49, Matus Jokay wrote:
> Please fix io_bind and io_listen to not pass NULL ptr to related helpers
> __sys_bind_socket and __sys_listen_socket. The first helper's argument
> shouldn't be NULL, as related security hooks expect a valid socket object.
> 
> See the syzkaller's bug report:
> https://lore.kernel.org/linux-security-module/[email protected]/

That was already fixed.

https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git/commit/?h=for-next&id=ad00e629145b2b9f0d78aa46e204a9df7d628978


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring
  2024-07-15 13:59           ` Tetsuo Handa
@ 2024-07-22 12:37             ` Matus Jokay
  0 siblings, 0 replies; 17+ messages in thread
From: Matus Jokay @ 2024-07-22 12:37 UTC (permalink / raw)
  To: Tetsuo Handa, Jens Axboe, Jakub Kicinski
  Cc: Gabriel Krisman Bertazi, io-uring, netdev, linux-security-module

On 15. 7. 2024 15:59, Tetsuo Handa wrote:
> On 2024/07/15 21:49, Matus Jokay wrote:
>> Please fix io_bind and io_listen to not pass NULL ptr to related helpers
>> __sys_bind_socket and __sys_listen_socket. The first helper's argument
>> shouldn't be NULL, as related security hooks expect a valid socket object.
>>
>> See the syzkaller's bug report:
>> https://lore.kernel.org/linux-security-module/[email protected]/
> 
> That was already fixed.
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git/commit/?h=for-next&id=ad00e629145b2b9f0d78aa46e204a9df7d628978
> 
> 
Tetsuo, you are very fast ;)
Thank you!
mY


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-07-22 12:38 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-14 16:30 [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring Gabriel Krisman Bertazi
2024-06-14 16:30 ` [PATCH v2 2/4] net: Split a __sys_listen " Gabriel Krisman Bertazi
2024-06-14 22:44   ` Kuniyuki Iwashima
2024-06-19  0:50   ` Jakub Kicinski
2024-06-14 16:30 ` [PATCH v2 3/4] io_uring: Introduce IORING_OP_BIND Gabriel Krisman Bertazi
2024-06-14 22:46   ` Kuniyuki Iwashima
2024-06-15  0:27     ` Jens Axboe
2024-06-14 16:30 ` [PATCH v2 4/4] io_uring: Introduce IORING_OP_LISTEN Gabriel Krisman Bertazi
2024-06-14 22:42 ` [PATCH v2 1/4] net: Split a __sys_bind helper for io_uring Kuniyuki Iwashima
2024-06-19  0:49 ` Jakub Kicinski
2024-06-19 13:40   ` Jens Axboe
2024-06-19 15:04     ` Jakub Kicinski
2024-06-19 15:06       ` Jens Axboe
2024-07-15 12:49         ` Matus Jokay
2024-07-15 13:59           ` Tetsuo Handa
2024-07-22 12:37             ` Matus Jokay
2024-06-19 14:58 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox