[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <cover.1743449872.git.metze@samba.org>
Date: Mon, 31 Mar 2025 22:10:52 +0200
From: Stefan Metzmacher <metze@...ba.org>
To: Linus Torvalds <torvalds@...ux-foundation.org>,
Jens Axboe <axboe@...nel.dk>
Cc: Stefan Metzmacher <metze@...ba.org>,
Pavel Begunkov <asml.silence@...il.com>,
Breno Leitao <leitao@...ian.org>,
Jakub Kicinski <kuba@...nel.org>,
Christoph Hellwig <hch@....de>,
Karsten Keil <isdn@...ux-pingi.de>,
Ayush Sawal <ayush.sawal@...lsio.com>,
Andrew Lunn <andrew+netdev@...n.ch>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Paolo Abeni <pabeni@...hat.com>,
Simon Horman <horms@...nel.org>,
Kuniyuki Iwashima <kuniyu@...zon.com>,
Willem de Bruijn <willemb@...gle.com>,
David Ahern <dsahern@...nel.org>,
Marcelo Ricardo Leitner <marcelo.leitner@...il.com>,
Xin Long <lucien.xin@...il.com>,
Neal Cardwell <ncardwell@...gle.com>,
Joerg Reuter <jreuter@...na.de>,
Marcel Holtmann <marcel@...tmann.org>,
Johan Hedberg <johan.hedberg@...il.com>,
Luiz Augusto von Dentz <luiz.dentz@...il.com>,
Oliver Hartkopp <socketcan@...tkopp.net>,
Marc Kleine-Budde <mkl@...gutronix.de>,
Robin van der Gracht <robin@...tonic.nl>,
Oleksij Rempel <o.rempel@...gutronix.de>,
kernel@...gutronix.de,
Alexander Aring <alex.aring@...il.com>,
Stefan Schmidt <stefan@...enfreihafen.org>,
Miquel Raynal <miquel.raynal@...tlin.com>,
Alexandra Winter <wintera@...ux.ibm.com>,
Thorsten Winkler <twinkler@...ux.ibm.com>,
James Chapman <jchapman@...alix.com>,
Jeremy Kerr <jk@...econstruct.com.au>,
Matt Johnston <matt@...econstruct.com.au>,
Matthieu Baerts <matttbe@...nel.org>,
Mat Martineau <martineau@...nel.org>,
Geliang Tang <geliang@...nel.org>,
Krzysztof Kozlowski <krzk@...nel.org>,
Remi Denis-Courmont <courmisch@...il.com>,
Allison Henderson <allison.henderson@...cle.com>,
David Howells <dhowells@...hat.com>,
Marc Dionne <marc.dionne@...istor.com>,
Wenjia Zhang <wenjia@...ux.ibm.com>,
Jan Karcher <jaka@...ux.ibm.com>,
"D. Wythe" <alibuda@...ux.alibaba.com>,
Tony Lu <tonylu@...ux.alibaba.com>,
Wen Gu <guwen@...ux.alibaba.com>,
Jon Maloy <jmaloy@...hat.com>,
Boris Pismenny <borisp@...dia.com>,
John Fastabend <john.fastabend@...il.com>,
Stefano Garzarella <sgarzare@...hat.com>,
Martin Schiller <ms@....tdt.de>,
Björn Töpel <bjorn@...nel.org>,
Magnus Karlsson <magnus.karlsson@...el.com>,
Maciej Fijalkowski <maciej.fijalkowski@...el.com>,
Jonathan Lemon <jonathan.lemon@...il.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Jesper Dangaard Brouer <hawk@...nel.org>,
netdev@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-sctp@...r.kernel.org,
linux-hams@...r.kernel.org,
linux-bluetooth@...r.kernel.org,
linux-can@...r.kernel.org,
dccp@...r.kernel.org,
linux-wpan@...r.kernel.org,
linux-s390@...r.kernel.org,
mptcp@...ts.linux.dev,
linux-rdma@...r.kernel.org,
rds-devel@....oracle.com,
linux-afs@...ts.infradead.org,
tipc-discussion@...ts.sourceforge.net,
virtualization@...ts.linux.dev,
linux-x25@...r.kernel.org,
bpf@...r.kernel.org,
isdn4linux@...tserv.isdn4linux.de,
io-uring@...r.kernel.org
Subject: [RFC PATCH 0/4] net/io_uring: pass a kernel pointer via optlen_t to proto[_ops].getsockopt()
The motivation for this is to remove the SOL_SOCKET limitation
from io_uring_cmd_getsockopt().
The reason for this limitation is that io_uring_cmd_getsockopt()
passes a kernel pointer as optlen to do_sock_getsockopt()
and can't reach the ops->getsockopt() path.
The first idea would be to change the optval and optlen arguments
to the protocol specific hooks also to sockptr_t, as that
is already used for setsockopt() and also by do_sock_getsockopt()
sk_getsockopt() and BPF_CGROUP_RUN_PROG_GETSOCKOPT().
But as Linus don't like 'sockptr_t' I used a different approach.
@Linus, would that optlen_t approach fit better for you?
Instead of passing the optlen as user or kernel pointer,
we only ever pass a kernel pointer and do the
translation from/to userspace in do_sock_getsockopt().
The simple solution would be to just remove the
'__user' from the int *optlen argument, but it
seems the compiler doesn't complain about
'__user' vs. without it, so instead I used
a helper struct in order to make sure everything
compiles with a typesafe change.
The patchset does the transformation in 3
easy to review steps:
1/4: introduces get_optlen(len, optlen) and put_optlen(len, optlen) helpers
on top of the existing get_user(len, optlen) and put_user(len, optlen)
usages.
2/4: introduces a simple optlen_t that just contains 'int __user *up;'
that makes sure get_optlen and put_optlen get a typesafe optlen argument
and they are the only functions looking at optlen.
(The existing sockptr_t optlen code gets OPTLEN_SOCKPTR(optlen) passed)
3/4: The changes do_sock_getsockopt() to pass a kernel pointer instead
of a __user pointer via optlen_t. This is a bit tricky as
directly failing the copy_from_sockptr(&koptlen, optlen, sizeof(koptlen)
with -EFAULT might change the uapi, as some getsockopt() hooks
doesn't even touch optlen at all. And userspace could do something
like this:
feature_x_supported = true;
ret = getsockopt(fd, level, optname, NULL, NULL);
if (ret == -1 && errno == ENOTSUPP) {
feature_x_supported = false;
}
And this should not give -EFAULT after the changes,
so optlen.kp is passed down as NULL, so that -EFAULT is
deferred to get_optlen() and put_optlen().
4/4: Removes the SOL_SOCKET restriction for io-uring.
This patchset doesn't touch any existing getsockopt() that
was already converted to sockptr_t optlen, that's something
for a later cleanup.
Link: https://lore.kernel.org/io-uring/86b1dce5-4bb4-4a0b-9cff-e72f488bf57d@samba.org/T/#t
Cc: Jens Axboe <axboe@...nel.dk>
Cc: Pavel Begunkov <asml.silence@...il.com>
Cc: Breno Leitao <leitao@...ian.org>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Jakub Kicinski <kuba@...nel.org>
Cc: Christoph Hellwig <hch@....de>
Cc: Karsten Keil <isdn@...ux-pingi.de>
Cc: Ayush Sawal <ayush.sawal@...lsio.com>
Cc: Andrew Lunn <andrew+netdev@...n.ch>
Cc: "David S. Miller" <davem@...emloft.net>
Cc: Eric Dumazet <edumazet@...gle.com>
Cc: Paolo Abeni <pabeni@...hat.com>
Cc: Simon Horman <horms@...nel.org>
Cc: Kuniyuki Iwashima <kuniyu@...zon.com>
Cc: Willem de Bruijn <willemb@...gle.com>
Cc: David Ahern <dsahern@...nel.org>
Cc: Marcelo Ricardo Leitner <marcelo.leitner@...il.com>
Cc: Xin Long <lucien.xin@...il.com>
Cc: Neal Cardwell <ncardwell@...gle.com>
Cc: Joerg Reuter <jreuter@...na.de>
Cc: Marcel Holtmann <marcel@...tmann.org>
Cc: Johan Hedberg <johan.hedberg@...il.com>
Cc: Luiz Augusto von Dentz <luiz.dentz@...il.com>
Cc: Oliver Hartkopp <socketcan@...tkopp.net>
Cc: Marc Kleine-Budde <mkl@...gutronix.de>
Cc: Robin van der Gracht <robin@...tonic.nl>
Cc: Oleksij Rempel <o.rempel@...gutronix.de>
Cc: kernel@...gutronix.de
Cc: Alexander Aring <alex.aring@...il.com>
Cc: Stefan Schmidt <stefan@...enfreihafen.org>
Cc: Miquel Raynal <miquel.raynal@...tlin.com>
Cc: Alexandra Winter <wintera@...ux.ibm.com>
Cc: Thorsten Winkler <twinkler@...ux.ibm.com>
Cc: James Chapman <jchapman@...alix.com>
Cc: Jeremy Kerr <jk@...econstruct.com.au>
Cc: Matt Johnston <matt@...econstruct.com.au>
Cc: Matthieu Baerts <matttbe@...nel.org>
Cc: Mat Martineau <martineau@...nel.org>
Cc: Geliang Tang <geliang@...nel.org>
Cc: Krzysztof Kozlowski <krzk@...nel.org>
Cc: Remi Denis-Courmont <courmisch@...il.com>
Cc: Allison Henderson <allison.henderson@...cle.com>
Cc: David Howells <dhowells@...hat.com>
Cc: Marc Dionne <marc.dionne@...istor.com>
Cc: Wenjia Zhang <wenjia@...ux.ibm.com>
Cc: Jan Karcher <jaka@...ux.ibm.com>
Cc: "D. Wythe" <alibuda@...ux.alibaba.com>
Cc: Tony Lu <tonylu@...ux.alibaba.com>
Cc: Wen Gu <guwen@...ux.alibaba.com>
Cc: Jon Maloy <jmaloy@...hat.com>
Cc: Boris Pismenny <borisp@...dia.com>
Cc: John Fastabend <john.fastabend@...il.com>
Cc: Stefano Garzarella <sgarzare@...hat.com>
Cc: Martin Schiller <ms@....tdt.de>
Cc: "Björn Töpel" <bjorn@...nel.org>
Cc: Magnus Karlsson <magnus.karlsson@...el.com>
Cc: Maciej Fijalkowski <maciej.fijalkowski@...el.com>
Cc: Jonathan Lemon <jonathan.lemon@...il.com>
Cc: Alexei Starovoitov <ast@...nel.org>
Cc: Daniel Borkmann <daniel@...earbox.net>
Cc: Jesper Dangaard Brouer <hawk@...nel.org>
CC: Stefan Metzmacher <metze@...ba.org>
Cc: netdev@...r.kernel.org
Cc: linux-kernel@...r.kernel.org
Cc: linux-sctp@...r.kernel.org
Cc: linux-hams@...r.kernel.org
Cc: linux-bluetooth@...r.kernel.org
Cc: linux-can@...r.kernel.org
Cc: dccp@...r.kernel.org
Cc: linux-wpan@...r.kernel.org
Cc: linux-s390@...r.kernel.org
Cc: mptcp@...ts.linux.dev
Cc: linux-rdma@...r.kernel.org
Cc: rds-devel@....oracle.com
Cc: linux-afs@...ts.infradead.org
Cc: tipc-discussion@...ts.sourceforge.net
Cc: virtualization@...ts.linux.dev
Cc: linux-x25@...r.kernel.org
Cc: bpf@...r.kernel.org
Cc: isdn4linux@...tserv.isdn4linux.de
Cc: io-uring@...r.kernel.org
Stefan Metzmacher (4):
net: introduce get_optlen() and put_optlen() helpers
net: pass 'optlen_t' to proto[ops].getsockopt() hooks
net: pass a kernel pointer via 'optlen_t' to proto[ops].getsockopt()
hooks
io_uring: let io_uring_cmd_getsockopt() allow level other than
SOL_SOCKET
drivers/isdn/mISDN/socket.c | 4 +-
.../chelsio/inline_crypto/chtls/chtls_main.c | 4 +-
include/linux/net.h | 2 +-
include/linux/sockptr.h | 41 ++++
include/net/inet_connection_sock.h | 2 +-
include/net/ip.h | 2 +-
include/net/ipv6.h | 2 +-
include/net/sctp/structs.h | 2 +-
include/net/sock.h | 4 +-
include/net/tcp.h | 2 +-
include/net/udp.h | 2 +-
io_uring/uring_cmd.c | 3 -
net/atm/common.c | 4 +-
net/atm/common.h | 2 +-
net/atm/pvc.c | 2 +-
net/atm/svc.c | 4 +-
net/ax25/af_ax25.c | 6 +-
net/bluetooth/hci_sock.c | 6 +-
net/bluetooth/iso.c | 6 +-
net/bluetooth/l2cap_sock.c | 8 +-
net/bluetooth/rfcomm/sock.c | 8 +-
net/bluetooth/sco.c | 10 +-
net/can/isotp.c | 6 +-
net/can/j1939/socket.c | 6 +-
net/can/raw.c | 14 +-
net/core/sock.c | 2 +-
net/dccp/ccid.c | 4 +-
net/dccp/ccid.h | 10 +-
net/dccp/ccids/ccid3.c | 8 +-
net/dccp/dccp.h | 2 +-
net/dccp/proto.c | 12 +-
net/ieee802154/socket.c | 8 +-
net/ipv4/ip_sockglue.c | 8 +-
net/ipv4/raw.c | 10 +-
net/ipv4/tcp.c | 4 +-
net/ipv4/udp.c | 8 +-
net/ipv4/udp_impl.h | 2 +-
net/ipv6/ipv6_sockglue.c | 8 +-
net/ipv6/raw.c | 14 +-
net/ipv6/udp.c | 2 +-
net/ipv6/udp_impl.h | 2 +-
net/iucv/af_iucv.c | 6 +-
net/kcm/kcmsock.c | 6 +-
net/l2tp/l2tp_ppp.c | 6 +-
net/llc/af_llc.c | 6 +-
net/mctp/af_mctp.c | 4 +-
net/mptcp/protocol.h | 2 +-
net/mptcp/sockopt.c | 48 ++--
net/netlink/af_netlink.c | 8 +-
net/netrom/af_netrom.c | 6 +-
net/nfc/llcp_sock.c | 6 +-
net/packet/af_packet.c | 6 +-
net/phonet/pep.c | 6 +-
net/rds/af_rds.c | 8 +-
net/rds/info.c | 6 +-
net/rds/info.h | 2 +-
net/rose/af_rose.c | 6 +-
net/rxrpc/af_rxrpc.c | 6 +-
net/sctp/socket.c | 220 +++++++++---------
net/smc/af_smc.c | 8 +-
net/smc/smc.h | 2 +-
net/socket.c | 34 ++-
net/tipc/socket.c | 8 +-
net/tls/tls_main.c | 18 +-
net/vmw_vsock/af_vsock.c | 6 +-
net/x25/af_x25.c | 6 +-
net/xdp/xsk.c | 10 +-
67 files changed, 387 insertions(+), 319 deletions(-)
--
2.34.1
Powered by blists - more mailing lists