2019-06-04 10:11:33 +02:00
|
|
|
|
2020-07-22 17:32:06 +01:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-04 15:52:57 +03:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-03 12:38:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-10 13:21:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-19 06:11:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-03 16:50:49 +01:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2010-04-02 06:18:49 +00:00
|
|
|
|
2020-07-22 17:32:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-02 06:18:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-22 17:32:06 +01:00
|
|
|
|
2010-04-02 06:19:10 +00:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
|
|
|
|
|
l2tp: store l2tpv3 sessions in per-net IDR
L2TPv3 sessions are currently held in one of two fixed-size hash
lists: either a per-net hashlist (IP-encap), or a per-tunnel hashlist
(UDP-encap), keyed by the L2TPv3 32-bit session_id.
In order to lookup L2TPv3 sessions in UDP-encap tunnels efficiently
without finding the tunnel first via sk_user_data, UDP sessions are
now kept in a per-net session list, keyed by session ID. Convert the
existing per-net hashlist to use an IDR for better performance when
there are many sessions and have L2TPv3 UDP sessions use the same IDR.
Although the L2TPv3 RFC states that the session ID alone identifies
the session, our implementation has allowed the same session ID to be
used in different L2TP UDP tunnels. To retain support for this, a new
per-net session hashtable is used, keyed by the sock and session
ID. If on creating a new session, a session already exists with that
ID in the IDR, the colliding sessions are added to the new hashtable
and the existing IDR entry is flagged. When looking up sessions, the
approach is to first check the IDR and if no unflagged match is found,
check the new hashtable. The sock is made available to session getters
where session ID collisions are to be considered. In this way, the new
hashtable is used only for session ID collisions so can be kept small.
For managing session removal, we need a list of colliding sessions
matching a given ID in order to update or remove the IDR entry of the
ID. This is necessary to detect session ID collisions when future
sessions are created. The list head is allocated on first collision
of a given ID and refcounted.
Signed-off-by: James Chapman <jchapman@katalix.com>
Reviewed-by: Tom Parkin <tparkin@katalix.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2024-06-20 12:22:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
|
|
|
|
|
2024-06-20 12:22:44 +01:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
2020-08-22 15:59:05 +01:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2020-07-22 17:32:06 +01:00
|
|
|
|
l2tp: fix race between l2tp_session_delete() and l2tp_tunnel_closeall()
There are several ways to remove L2TP sessions:
* deleting a session explicitly using the netlink interface (with
L2TP_CMD_SESSION_DELETE),
* deleting the session's parent tunnel (either by closing the
tunnel's file descriptor or using the netlink interface),
* closing the PPPOL2TP file descriptor of a PPP pseudo-wire.
In some cases, when these methods are used concurrently on the same
session, the session can be removed twice, leading to use-after-free
bugs.
This patch adds a 'dead' flag, used by l2tp_session_delete() and
l2tp_tunnel_closeall() to prevent them from stepping on each other's
toes.
The session deletion path used when closing a PPPOL2TP file descriptor
doesn't need to be adapted. It already has to ensure that a session
remains valid for the lifetime of its PPPOL2TP file descriptor.
So it takes an extra reference on the session in the ->session_close()
callback (pppol2tp_session_close()), which is eventually dropped
in the ->sk_destruct() callback of the PPPOL2TP socket
(pppol2tp_session_destruct()).
Still, __l2tp_session_unhash() and l2tp_session_queue_purge() can be
called twice and even concurrently for a given session, but thanks to
proper locking and re-initialisation of list fields, this is not an
issue.
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-09-22 15:39:24 +02:00
|
|
|
|
2024-07-29 16:38:08 +01:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2020-07-22 17:32:06 +01:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
|
|
|
|
|
2010-04-02 06:18:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2013-07-02 20:28:59 +01:00
|
|
|
|
|
|
|
|
|
2013-07-02 20:29:00 +01:00
|
|
|
|
2020-07-22 17:32:06 +01:00
|
|
|
|
2013-07-02 20:29:00 +01:00
|
|
|
|
2024-06-20 12:22:44 +01:00
|
|
|
|
2017-07-04 15:52:58 +03:00
|
|
|
|
l2tp: store l2tpv3 sessions in per-net IDR
L2TPv3 sessions are currently held in one of two fixed-size hash
lists: either a per-net hashlist (IP-encap), or a per-tunnel hashlist
(UDP-encap), keyed by the L2TPv3 32-bit session_id.
In order to lookup L2TPv3 sessions in UDP-encap tunnels efficiently
without finding the tunnel first via sk_user_data, UDP sessions are
now kept in a per-net session list, keyed by session ID. Convert the
existing per-net hashlist to use an IDR for better performance when
there are many sessions and have L2TPv3 UDP sessions use the same IDR.
Although the L2TPv3 RFC states that the session ID alone identifies
the session, our implementation has allowed the same session ID to be
used in different L2TP UDP tunnels. To retain support for this, a new
per-net session hashtable is used, keyed by the sock and session
ID. If on creating a new session, a session already exists with that
ID in the IDR, the colliding sessions are added to the new hashtable
and the existing IDR entry is flagged. When looking up sessions, the
approach is to first check the IDR and if no unflagged match is found,
check the new hashtable. The sock is made available to session getters
where session ID collisions are to be considered. In this way, the new
hashtable is used only for session ID collisions so can be kept small.
For managing session removal, we need a list of colliding sessions
matching a given ID in order to update or remove the IDR entry of the
ID. This is necessary to detect session ID collisions when future
sessions are created. The list head is allocated on first collision
of a given ID and refcounted.
Signed-off-by: James Chapman <jchapman@katalix.com>
Reviewed-by: Tom Parkin <tparkin@katalix.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2024-06-20 12:22:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2020-08-22 15:59:05 +01:00
|
|
|
|
2010-04-02 06:19:10 +00:00
|
|
|
|
2020-07-22 17:32:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-05-09 23:43:08 +00:00
|
|
|
|
2010-04-02 06:18:49 +00:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2024-07-29 16:38:07 +01:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-06-20 12:22:44 +01:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
|
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-02 06:19:33 +00:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
2020-07-22 17:32:06 +01:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
|
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2010-04-02 06:19:00 +00:00
|
|
|
|
2010-04-02 06:19:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-04-29 21:48:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-02 06:19:40 +00:00
|
|
|
|
|
|
|
|
|
2014-05-23 08:47:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
|
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-06-20 12:22:44 +01:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
|
|
|
|
|
2020-08-22 15:59:05 +01:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2017-09-26 16:16:43 +02:00
|
|
|
|
|
|
|
|
|
2012-08-24 01:07:38 +00:00
|
|
|
|
2024-06-20 12:22:44 +01:00
|
|
|
|
2020-07-22 17:32:06 +01:00
|
|
|
|
2024-06-20 12:22:44 +01:00
|
|
|
|
2017-09-01 17:58:48 +02:00
|
|
|
|
2024-06-20 12:22:44 +01:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-22 15:59:05 +01:00
|
|
|
|
2010-04-02 06:19:00 +00:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-04 15:52:57 +03:00
|
|
|
|
2020-07-22 17:32:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2013-01-31 23:43:00 +00:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
|
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
2010-04-02 06:19:10 +00:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-01 17:58:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-28 18:20:30 +01:00
|
|
|
|
2010-04-02 06:19:10 +00:00
|
|
|
|
|
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
2024-08-07 07:54:50 +01:00
|
|
|
|
|
|
|
|
|
2020-07-28 18:20:29 +01:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-25 16:51:40 +02:00
|
|
|
|
2024-08-07 07:54:48 +01:00
|
|
|
|
2018-04-12 20:50:33 +02:00
|
|
|
|
l2tp: store l2tpv3 sessions in per-net IDR
L2TPv3 sessions are currently held in one of two fixed-size hash
lists: either a per-net hashlist (IP-encap), or a per-tunnel hashlist
(UDP-encap), keyed by the L2TPv3 32-bit session_id.
In order to lookup L2TPv3 sessions in UDP-encap tunnels efficiently
without finding the tunnel first via sk_user_data, UDP sessions are
now kept in a per-net session list, keyed by session ID. Convert the
existing per-net hashlist to use an IDR for better performance when
there are many sessions and have L2TPv3 UDP sessions use the same IDR.
Although the L2TPv3 RFC states that the session ID alone identifies
the session, our implementation has allowed the same session ID to be
used in different L2TP UDP tunnels. To retain support for this, a new
per-net session hashtable is used, keyed by the sock and session
ID. If on creating a new session, a session already exists with that
ID in the IDR, the colliding sessions are added to the new hashtable
and the existing IDR entry is flagged. When looking up sessions, the
approach is to first check the IDR and if no unflagged match is found,
check the new hashtable. The sock is made available to session getters
where session ID collisions are to be considered. In this way, the new
hashtable is used only for session ID collisions so can be kept small.
For managing session removal, we need a list of colliding sessions
matching a given ID in order to update or remove the IDR entry of the
ID. This is necessary to detect session ID collisions when future
sessions are created. The list head is allocated on first collision
of a given ID and refcounted.
Signed-off-by: James Chapman <jchapman@katalix.com>
Reviewed-by: Tom Parkin <tparkin@katalix.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2024-06-20 12:22:38 +01:00
|
|
|
|
2024-06-20 12:22:39 +01:00
|
|
|
|
2024-06-20 12:22:42 +01:00
|
|
|
|
|
|
|
|
|
2024-08-07 07:54:48 +01:00
|
|
|
|
|
|
|
|
|
2017-04-12 10:05:29 +02:00
|
|
|
|
2017-10-31 17:36:42 +01:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-03 09:54:49 +01:00
|
|
|
|
2013-10-18 13:48:25 -07:00
|
|
|
|
|
|
|
|
|
l2tp: fix races in tunnel creation
l2tp_tunnel_create() inserts the new tunnel into the namespace's tunnel
list and sets the socket's ->sk_user_data field, before returning it to
the caller. Therefore, there are two ways the tunnel can be accessed
and freed, before the caller even had the opportunity to take a
reference. In practice, syzbot could crash the module by closing the
socket right after a new tunnel was returned to pppol2tp_create().
This patch moves tunnel registration out of l2tp_tunnel_create(), so
that the caller can safely hold a reference before publishing the
tunnel. This second step is done with the new l2tp_tunnel_register()
function, which is now responsible for associating the tunnel to its
socket and for inserting it into the namespace's list.
While moving the code to l2tp_tunnel_register(), a few modifications
have been done. First, the socket validation tests are done in a helper
function, for clarity. Also, modifying the socket is now done after
having inserted the tunnel to the namespace's tunnels list. This will
allow insertion to fail, without having to revert theses modifications
in the error path (a followup patch will check for duplicate tunnels
before insertion). Either the socket is a kernel socket which we
control, or it is a user-space socket for which we have a reference on
the file descriptor. In any case, the socket isn't going to be closed
from under us.
Reported-by: syzbot+fbeeb5c3b538e8545644@syzkaller.appspotmail.com
Fixes: fd558d186df2 ("l2tp: Split pppol2tp patch into separate l2tp and ppp parts")
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-04-10 21:01:12 +02:00
|
|
|
|
|
|
|
|
|
2017-09-26 16:16:43 +02:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
2013-10-18 13:48:25 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-27 16:51:50 +02:00
|
|
|
|
|
|
|
|
|
2020-07-28 18:20:30 +01:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-18 13:48:25 -07:00
|
|
|
|
|
|
|
|
|
2018-07-25 14:53:33 +02:00
|
|
|
|
2013-10-18 13:48:25 -07:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
2024-07-29 16:38:10 +01:00
|
|
|
|
|
|
|
|
|
2020-09-03 09:54:47 +01:00
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-18 13:48:25 -07:00
|
|
|
|
2020-07-28 18:20:33 +01:00
|
|
|
|
|
|
|
|
|
net: ioctl: Use kernel memory on protocol ioctl callbacks
Most of the ioctls to net protocols operates directly on userspace
argument (arg). Usually doing get_user()/put_user() directly in the
ioctl callback. This is not flexible, because it is hard to reuse these
functions without passing userspace buffers.
Change the "struct proto" ioctls to avoid touching userspace memory and
operate on kernel buffers, i.e., all protocol's ioctl callbacks is
adapted to operate on a kernel memory other than on userspace (so, no
more {put,get}_user() and friends being called in the ioctl callback).
This changes the "struct proto" ioctl format in the following way:
int (*ioctl)(struct sock *sk, int cmd,
- unsigned long arg);
+ int *karg);
(Important to say that this patch does not touch the "struct proto_ops"
protocols)
So, the "karg" argument, which is passed to the ioctl callback, is a
pointer allocated to kernel space memory (inside a function wrapper).
This buffer (karg) may contain input argument (copied from userspace in
a prep function) and it might return a value/buffer, which is copied
back to userspace if necessary. There is not one-size-fits-all format
(that is I am using 'may' above), but basically, there are three type of
ioctls:
1) Do not read from userspace, returns a result to userspace
2) Read an input parameter from userspace, and does not return anything
to userspace
3) Read an input from userspace, and return a buffer to userspace.
The default case (1) (where no input parameter is given, and an "int" is
returned to userspace) encompasses more than 90% of the cases, but there
are two other exceptions. Here is a list of exceptions:
* Protocol RAW:
* cmd = SIOCGETVIFCNT:
* input and output = struct sioc_vif_req
* cmd = SIOCGETSGCNT
* input and output = struct sioc_sg_req
* Explanation: for the SIOCGETVIFCNT case, userspace passes the input
argument, which is struct sioc_vif_req. Then the callback populates
the struct, which is copied back to userspace.
* Protocol RAW6:
* cmd = SIOCGETMIFCNT_IN6
* input and output = struct sioc_mif_req6
* cmd = SIOCGETSGCNT_IN6
* input and output = struct sioc_sg_req6
* Protocol PHONET:
* cmd == SIOCPNADDRESOURCE | SIOCPNDELRESOURCE
* input int (4 bytes)
* Nothing is copied back to userspace.
For the exception cases, functions sock_sk_ioctl_inout() will
copy the userspace input, and copy it back to kernel space.
The wrapper that prepare the buffer and put the buffer back to user is
sk_ioctl(), so, instead of calling sk->sk_prot->ioctl(), the callee now
calls sk_ioctl(), which will handle all cases.
Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://lore.kernel.org/r/20230609152800.830401-1-leitao@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2023-06-09 08:27:42 -07:00
|
|
|
|
2010-04-02 06:19:10 +00:00
|
|
|
|
2024-07-29 16:38:00 +01:00
|
|
|
|
2020-09-03 09:54:51 +01:00
|
|
|
|
2018-01-16 23:01:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-03 12:38:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-08-10 13:21:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-30 14:55:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-09-23 21:33:34 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-02 06:18:33 +00:00
|
|
|
|