Skip to contentSkip to conversation

kproxy: Kernel Proxy

RFC PATCH In review Tom Herbert 4 participants 13 messages Jun 29, 2017 – Jul 3, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover kproxy: Kernel Proxy

This is raw, minimally tested, and error hanlding needs work. Posting as RFC to get feedback on the design...

Sidecar proxies are becoming quite popular on server as a means to perform layer 7 processing on application data as it is sent. Such sidecars are used for SSL proxies, application firewalls, and L7 load balancers. While these proxies provide nice functionality, their performance is obviously terrible since all the data needs to take an extra hop though userspace.

Consider transmitting data on a TCP socket that goes through a sidecar paroxy. The application does a sendmsg in userpsace, data goes into kernel, back to userspace, and back to kernel. That is two trips through TCP TX, one TCP RX, potentially three copies, three sockets are touched, and three context switches. Using a proxy in the receive path would have a similarly long path.

	 +--------------+      +------------------+
	 |  Application |      | Proxy            |
	 |              |      |                  |
	 |  sendmsg     |      | recvmsg sendmsg  |
	 +--------------+      +------------------+
	       |                    |       |
               |                    ^       |
---------------V--------------------|-------|--------------
	       |                    |       |
	       +---->--------->-----+       V
            TCP TX              TCP RX    TCP TX

The "boomerang" model this employs is quite expensive. This is even much worse in the case that the proxy is an SSL proxy (e.g. performing SSL inspection to implement and application firewall). In this case The application encrypts using TLS, the proxy immediately decrypts (it knows the key by virtue of have pretended to be a certificate authority). Subsequently, the proxy re-encrpyts it again to send. So each byte undergoes three crypto operations in this path!

This patch set creates and in kernel proxy (kproxy). The concept is fairly straightforward, two sockets are joined in the kernel as a proxy. Proxy functionality will be done by BPF on the data stream, kTLS is needed to make an SSL proxy. The most prominent ULP for a proxy is http so we'll need a parser for http to make an in kernel http proxy.

	 +--------------+
	 |  Application |
	 |              |
	 |  sendmsg     |
	 +--------------+
	       |
               |
---------------V-------------------------------------------
               |
	       |        +---------------+
               +------->|   Proxy       |---+
			| strparser+BPF |   |
			+---------------+   |
            TCP TX   TCP RX                 |
					    V
					 TCP TX

This patch set implements a very rudimentary kernel proxy, it just provides an interface to create a proxy between two sockets. Once the RX and TX paths are done for kTLS it should be straightforward to enable to make an in kernel SSL proxy. Proxy functionality (like application level filtering) will be implemented by BPF programs set on the kproxy. This will use strparser to provide message deliniation (we'll need a slight mofication to strparse to allow pass through mode). In kernel layer 7 load balancing is also feasible, in that case we may want to use a multiplexor structure like KCM (I had consider overloading KCM for kproxy but decided they are too different.

kproxy eliminates the userspace boomerang, but you may notice that even with kproxy we still have same number of sockets and sill potentially perform three crypto ops on every byte. I have some ideas for how to create a "zero proxy" that eliminates these without loss of the proxy functionality. That would be the subject of a future path set.

Tom Herbert (2):
skbuff: Function to send an skbuf on a socket
kproxy: Kernel proxy

 include/linux/skbuff.h              |   2 +
 include/linux/socket.h              |   4 +-
 include/net/kproxy.h                |  80 +++++
 include/uapi/linux/kproxy.h         |  30 ++
 net/Kconfig                         |   1 +
 net/Makefile                        |   1 +
 net/core/skbuff.c                   |  66 ++++
 net/kproxy/Kconfig                  |  10 +
 net/kproxy/Makefile                 |   3 +
 net/kproxy/kproxyproc.c             | 246 +++++++++++++++
 net/kproxy/kproxysock.c             | 605 ++++++++++++++++++++++++++++++++++++
 security/selinux/hooks.c            |   4 +-
 security/selinux/include/classmap.h |   4 +-
 13 files changed, 1053 insertions(+), 3 deletions(-)
 create mode 100644 include/net/kproxy.h
 create mode 100644 include/uapi/linux/kproxy.h
 create mode 100644 net/kproxy/Kconfig
 create mode 100644 net/kproxy/Makefile
 create mode 100644 net/kproxy/kproxyproc.c
 create mode 100644 net/kproxy/kproxysock.c
Signature · 1 line
2.7.4
#1 lore raw

RFC PATCH 1/2 skbuff: Function to send an skbuf on a socket

Add skb_send_sock to send an skbuff on a socket within the kernel. Arguments include and offset so that an skbuf might be sent in mulitple calls (e.g. send buffer limit is hit).

---
 include/linux/skbuff.h |  2 ++
 net/core/skbuff.c      | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)
include/linux/skbuff.h +2 -0
index a17e235..83849e3 100644
@@ -3115,6 +3115,8 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, u8 *to,
 int skb_splice_bits(struct sk_buff *skb, struct sock *sk, unsigned int offset,
 		    struct pipe_inode_info *pipe, unsigned int len,
 		    unsigned int flags);
+int skb_send_sock(struct sk_buff *skb, struct socket *sock,
+				  unsigned int offset);
 void skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to);
 unsigned int skb_zerocopy_headlen(const struct sk_buff *from);
 int skb_zerocopy(struct sk_buff *to, struct sk_buff *from,
net/core/skbuff.c +66 -0

72 lines not on this page · raw message

Signature · 1 line
2.7.4
#3 lore raw

RFC PATCH 2/2 kproxy: Kernel proxy

In reply to Tom Herbert

Implement an in-kernel proxy.

This patch defines a new address family for create a kproxy socket (AF_KPROXY). Two IOCTL operations are defined SIOCKPROXYJOIN and SIOCKPROXYUNJOIN. The first takes two (TCP) sockets and creates a proxy between them, the latter destroys the proxy. When the proxy is established packets received on on socket are sent on the other. Proxy functionality (e.g. applicatation layer filtering will be implement via BPF programs attached to the proxy.

A proc file (/prox/net/kproxy) is created to list all the running kernel proxies and relevant statistics for them.

---
 include/linux/socket.h              |   4 +-
 include/net/kproxy.h                |  80 +++++
 include/uapi/linux/kproxy.h         |  30 ++
 net/Kconfig                         |   1 +
 net/Makefile                        |   1 +
 net/core/skbuff.c                   |   4 +-
 net/kproxy/Kconfig                  |  10 +
 net/kproxy/Makefile                 |   3 +
 net/kproxy/kproxyproc.c             | 246 +++++++++++++++
 net/kproxy/kproxysock.c             | 605 ++++++++++++++++++++++++++++++++++++
 security/selinux/hooks.c            |   4 +-
 security/selinux/include/classmap.h |   4 +-
 12 files changed, 987 insertions(+), 5 deletions(-)
 create mode 100644 include/net/kproxy.h
 create mode 100644 include/uapi/linux/kproxy.h
 create mode 100644 net/kproxy/Kconfig
 create mode 100644 net/kproxy/Makefile
 create mode 100644 net/kproxy/kproxyproc.c
 create mode 100644 net/kproxy/kproxysock.c
include/linux/socket.h +3 -1
index 8b13db5..50b8ccf 100644
@@ -206,8 +206,9 @@ struct ucred {
 				 * PF_SMC protocol family that
 				 * reuses AF_INET address family
 				 */
+#define AF_KPROXY	44	/* Kernel Proxy */
 
-#define AF_MAX		44	/* For now.. */
+#define AF_MAX		45	/* For now.. */
 
 /* Protocol families, same as address families. */
 #define PF_UNSPEC	AF_UNSPEC
@@ -257,6 +258,7 @@ struct ucred {
 #define PF_QIPCRTR	AF_QIPCRTR
 #define PF_SMC		AF_SMC
 #define PF_MAX		AF_MAX
+#define PF_KPROXY	AF_KPROXY
 
 /* Maximum queue length specifiable by listen.  */
 #define SOMAXCONN	128
include/net/kproxy.h new file +80 -0

80 lines not on this page · raw message

include/uapi/linux/kproxy.h new file +30 -0
new file mode 100644
index 0000000..d9a3e9c
@@ -0,0 +1,30 @@
+/*
+ * Kernel Proxy
+ *
+ * Copyright (c) 2017 Tom Herbert <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * User API to create in-kernel proxies.
+ */
+
+#ifndef KPROXYKERNEL_H
+#define KPROXYKERNEL_H
+
+struct kproxy_join {
+	int client_fd;
+	int server_fd;
+};
+
+struct kproxy_unjoin {
+	int client_fd;
+	int server_fd;
+};
+
+#define SIOCKPROXYJOIN		(SIOCPROTOPRIVATE + 0)
+#define SIOCKPROXYUNJOIN	(SIOCPROTOPRIVATE + 1)
+
+#endif
+
net/Kconfig +1 -0
index 7d57ef3..1f2263d 100644
@@ -368,6 +368,7 @@ source "net/irda/Kconfig"
 source "net/bluetooth/Kconfig"
 source "net/rxrpc/Kconfig"
 source "net/kcm/Kconfig"
+source "net/kproxy/Kconfig"
 source "net/strparser/Kconfig"
 
 config FIB_RULES
net/Makefile +1 -0
index bed80fa..7f7026d 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_BT)		+= bluetooth/
 obj-$(CONFIG_SUNRPC)		+= sunrpc/
 obj-$(CONFIG_AF_RXRPC)		+= rxrpc/
 obj-$(CONFIG_AF_KCM)		+= kcm/
+obj-$(CONFIG_AF_KPROXY)		+= kproxy/
 obj-$(CONFIG_STREAM_PARSER)	+= strparser/
 obj-$(CONFIG_ATM)		+= atm/
 obj-$(CONFIG_L2TP)		+= l2tp/
net/core/skbuff.c +2 -2
index ff9f88d..a3b09e4 100644
@@ -2009,7 +2009,7 @@ EXPORT_SYMBOL_GPL(skb_splice_bits);
 int skb_send_sock(struct sk_buff *skb, struct socket *sock, unsigned int offset)
 {
 	unsigned int sent = 0;
-	unsigned int ret;
+	int ret;
 	unsigned short fragidx;
 
 	/* Deal with head data */
@@ -2053,7 +2053,7 @@ int skb_send_sock(struct sk_buff *skb, struct socket *sock, unsigned int offset)
 				      frag->page_offset + offset,
 				      frag->size - offset,
 				      MSG_DONTWAIT);
-		if (ret < 0)
+		if (ret <= 0)
 			goto error;
 
 		sent += ret;
net/kproxy/Kconfig new file +10 -0
new file mode 100644
index 0000000..4754406
@@ -0,0 +1,10 @@
+
+config AF_KPROXY
+	tristate "Kernel proxy"
+	depends on INET
+	select BPF_SYSCALL
+	select STREAM_PARSER
+	---help---
+	  Kernel proxy implements an in kernel TCP proxy for performance.
+	  Filtering is done by BPF on incoming sockets.
+
net/kproxy/Makefile new file +3 -0
new file mode 100644
index 0000000..fdcd3a7
@@ -0,0 +1,3 @@
+obj-$(CONFIG_AF_KPROXY) += kproxy.o
+
+kproxy-y := kproxysock.o kproxyproc.o
net/kproxy/kproxyproc.c new file +246 -0

246 lines not on this page · raw message

net/kproxy/kproxysock.c new file +605 -0

605 lines not on this page · raw message

security/selinux/hooks.c +3 -1
index 819fd68..7f4c164 100644
@@ -1404,7 +1404,9 @@ static inline u16 socket_type_to_security_class(int family, int type, int protoc
 			return SECCLASS_QIPCRTR_SOCKET;
 		case PF_SMC:
 			return SECCLASS_SMC_SOCKET;
-#if PF_MAX > 44
+		case PF_KPROXY:
+			return SECCLASS_KPROXY_SOCKET;
+#if PF_MAX > 45
 #error New address family defined, please update this function.
 #endif
 		}
security/selinux/include/classmap.h +3 -1
index 1e0cc9b..047831e 100644
@@ -231,9 +231,11 @@ struct security_class_mapping secclass_map[] = {
 	  { COMMON_SOCK_PERMS, NULL } },
 	{ "smc_socket",
 	  { COMMON_SOCK_PERMS, NULL } },
+	{ "kproxy_socket",
+	  { COMMON_SOCK_PERMS, NULL } },
 	{ NULL }
   };
 
-#if PF_MAX > 44
+#if PF_MAX > 45
 #error New address family defined, please update secclass_map.
 #endif
Signature · 1 line
2.7.4
#5 lore raw
In reply to Tom Herbert

Hi Tom,

Quoted 26 lines · Tom Herbert

Sidecar proxies are becoming quite popular on server as a means to perform layer 7 processing on application data as it is sent. Such sidecars are used for SSL proxies, application firewalls, and L7 load balancers. While these proxies provide nice functionality, their performance is obviously terrible since all the data needs to take an extra hop though userspace.

Consider transmitting data on a TCP socket that goes through a sidecar paroxy. The application does a sendmsg in userpsace, data goes into kernel, back to userspace, and back to kernel. That is two trips through TCP TX, one TCP RX, potentially three copies, three sockets are touched, and three context switches. Using a proxy in the receive path would have a similarly long path.

	 +--------------+      +------------------+
	 |  Application |      | Proxy            |
	 |              |      |                  |
	 |  sendmsg     |      | recvmsg sendmsg  |
	 +--------------+      +------------------+
	       |                    |       |
               |                    ^       |
---------------V--------------------|-------|--------------
	       |                    |       |
	       +---->--------->-----+       V
            TCP TX              TCP RX    TCP TX
Quoted 3 lines

The "boomerang" model this employs is quite expensive. This is even much worse in the case that the proxy is an SSL proxy (e.g. performing SSL inspection to implement and application firewall).

In fact that's not much what I observe in field. In practice, large data streams are cheaply relayed using splice(), I could achieve 60 Gbps of HTTP forwarding via HAProxy on a 4-core xeon 2 years ago. And when you use SSL, the cost of the copy to/from kernel is small compared to all the crypto operations surrounding this.

Another point is that most HTTP requests are quite small (typically ~80% 20kB or less), and in this case the L7 processing and certain syscalls significantly dominate the operations, data copies are comparatively small. Simply parsing a HTTP header takes time (when you do it correctly). You can hardly parse and index more than 800MB-1GB/s of HTTP headers per core, which limits you to roughly 1-1.2 M req+resp per second for a 400 byte request and a 400 byte response, and that's without any processing at all. But when doing this, certain syscalls like connect(), close() or epollctl() start to be quite expensive. Even splice() is expensive to forward small data chunks because you need two calls, and recv+send is faster. In fact our TCP stack has been so much optimized for realistic workloads over the years that it becomes hard to gain more by cheating on it :-)

In the end in haproxy I'm seeing about 300k req+resp per second in HTTP keep-alive and more like 100-130k with close, when disabling TCP quick-ack during accept() and connect() to save one ACK on each side (just doing this generally brings performance gains between 7 and 10%).

Regarding kernel-side protocol parsing, there's an unfortunate trend at moving more and more protocols to userland due to these protocols evolving very quickly. At least you'll want to find a way to provide these parsers from userspace, which will inevitably come with its set of problems or limitations :-/

All this to say that while I can definitely imagine the benefits of having in-kernel sockets for in-kernel L7 processing or filtering, I'm having strong doubts about the benefits that userland may receive by using this (or maybe you already have any performance numbers supporting this ?).

Just my two cents,
Willy

#6 lore raw

Hi Willy,

Thanks for the comments!

Quoted 6 lines

In fact that's not much what I observe in field. In practice, large data streams are cheaply relayed using splice(), I could achieve 60 Gbps of HTTP forwarding via HAProxy on a 4-core xeon 2 years ago. And when you use SSL, the cost of the copy to/from kernel is small compared to all the crypto operations surrounding this.

Right, getting rid of the extra crypto operations and so called "SSL inspection" is the ultimate goal this is going towards.

Quoted 14 lines

Another point is that most HTTP requests are quite small (typically ~80% 20kB or less), and in this case the L7 processing and certain syscalls significantly dominate the operations, data copies are comparatively small. Simply parsing a HTTP header takes time (when you do it correctly). You can hardly parse and index more than 800MB-1GB/s of HTTP headers per core, which limits you to roughly 1-1.2 M req+resp per second for a 400 byte request and a 400 byte response, and that's without any processing at all. But when doing this, certain syscalls like connect(), close() or epollctl() start to be quite expensive. Even splice() is expensive to forward small data chunks because you need two calls, and recv+send is faster. In fact our TCP stack has been so much optimized for realistic workloads over the years that it becomes hard to gain more by cheating on it :-)

Quoted 6 lines

In the end in haproxy I'm seeing about 300k req+resp per second in HTTP keep-alive and more like 100-130k with close, when disabling TCP quick-ack during accept() and connect() to save one ACK on each side (just doing this generally brings performance gains between 7 and 10%).

HTTP is only one use case. The are other interesting use cases such as those in container security where the application protocol might be something like simple RPC. Performance is relevant because we potentially want security applied to every message in every communication in a containerized data center. Putting the userspace hop in the datapath of every packet is know to be problematic, not just for the performance hit also because it increases the attack surface on users' privacy.

Quoted 6 lines

Regarding kernel-side protocol parsing, there's an unfortunate trend at moving more and more protocols to userland due to these protocols evolving very quickly. At least you'll want to find a way to provide these parsers from userspace, which will inevitably come with its set of problems or limitations :-/

That's why everything is going BPF now ;-)

Quoted 6 lines

All this to say that while I can definitely imagine the benefits of having in-kernel sockets for in-kernel L7 processing or filtering, I'm having strong doubts about the benefits that userland may receive by using this (or maybe you already have any performance numbers supporting this ?).

Nope, no numbers yet.

Quoted 2 lines

Just my two cents,
Willy

#7 lore raw
Quoted 8 lines · Tom Herbert
Quoted 6 lines

In fact that's not much what I observe in field. In practice, large data streams are cheaply relayed using splice(), I could achieve 60 Gbps of HTTP forwarding via HAProxy on a 4-core xeon 2 years ago. And when you use SSL, the cost of the copy to/from kernel is small compared to all the crypto operations surrounding this.

Right, getting rid of the extra crypto operations and so called "SSL inspection" is the ultimate goal this is going towards.

Yep but in order to take decisions at L7 you need to decapsulate SSL.

Quoted 3 lines

HTTP is only one use case. The are other interesting use cases such as those in container security where the application protocol might be something like simple RPC.

OK that indeed makes sense in such environments.

Quoted 6 lines

Performance is relevant because we
potentially want security applied to every message in every communication in a containerized data center. Putting the userspace hop in the datapath of every packet is know to be problematic, not just for the performance hit also because it increases the attack surface on users' privacy.

While I totally agree on the performance hit when inspecting each packet, I fail to see the relation with users' privacy. In fact under some circumstances it can even be the opposite. For example, using something like kTLS for a TCP/HTTP proxy can result in cleartext being observable in strace while it's not visible when TLS is terminated in userland because all you see are openssl's read()/write() operations. Maybe you have specific attacks in mind ?

Quoted 7 lines
Quoted 6 lines

Regarding kernel-side protocol parsing, there's an unfortunate trend at moving more and more protocols to userland due to these protocols evolving very quickly. At least you'll want to find a way to provide these parsers from userspace, which will inevitably come with its set of problems or limitations :-/

That's why everything is going BPF now ;-)

Yes, I knew you were going to suggest this :-) I'm still prudent on it to be honnest. I don't think it would be that easy to implement an HPACK encoder/decoder using BPF. And even regarding just plain HTTP parsing, certain very small operations in haproxy's parser can quickly result in a 10% performance degradation when improperly optimized (ie: changing a "likely", altering branch prediction, or cache walk patterns when using arrays to evaluate character classes faster). But for general usage I indeed think it should be OK.

Quoted 7 lines
Quoted 6 lines

All this to say that while I can definitely imagine the benefits of having in-kernel sockets for in-kernel L7 processing or filtering, I'm having strong doubts about the benefits that userland may receive by using this (or maybe you already have any performance numbers supporting this ?).

Nope, no numbers yet.

OK, no worries. Thanks for your explanations!

Willy

#10 lore raw
In reply to Tom Herbert

Hi Tom

Quoted 9 lines · Tom Herbert

This is raw, minimally tested, and error hanlding needs work. Posting as RFC to get feedback on the design...

Sidecar proxies are becoming quite popular on server as a means to perform layer 7 processing on application data as it is sent. Such sidecars are used for SSL proxies, application firewalls, and L7 load balancers. While these proxies provide nice functionality, their performance is obviously terrible since all the data needs to take an extra hop though userspace.

I really appreciate this work. It would have been nice to at least attribute me in some way as this is exactly what I presented at Netconf 2017 [0].

I'm also wondering why this is not built on top of KCM which you suggested to use when we discussed this.

[0] https://docs.google.com/presentation/d/1dwSKSBGpUHD3WO5xxzZWj8awV_-xL-oYhvqQMOBhhtk/edit#slide=id.g203aae413f_0_0

#11 lore raw
Quoted 13 lines · Thomas Graf

Hi Tom

Quoted 9 lines · Tom Herbert

This is raw, minimally tested, and error hanlding needs work. Posting as RFC to get feedback on the design...

Sidecar proxies are becoming quite popular on server as a means to perform layer 7 processing on application data as it is sent. Such sidecars are used for SSL proxies, application firewalls, and L7 load balancers. While these proxies provide nice functionality, their performance is obviously terrible since all the data needs to take an extra hop though userspace.

Hi Thomas,

Quoted 4 lines

I really appreciate this work. It would have been nice to at least attribute me in some way as this is exactly what I presented at Netconf 2017 [0].

Sure, will do that!

Quoted 3 lines

I'm also wondering why this is not built on top of KCM which you suggested to use when we discussed this.

I think the main part of that discussion was around stream parser which is needed for message delineation. For a 1:1 proxy, KCM is probably overkill (the whole KCM data path and lock becomes superfluous). Also, there's no concept of creating a whole message before routing it, in the 1:1 case we should let the message pass through once it's cleared by the filter (this is the strparser change I referred to). As I mentioned, for L7 load balancing we would want a multiplexor probably also M:N, but the structure is different since there's still no user facing sockets, they're all TCP for instance. IMO, the 1:1 proxy case is compelling to solve in itself...

Tom

Quoted 1 line

[0] https://docs.google.com/presentation/d/1dwSKSBGpUHD3WO5xxzZWj8awV_-xL-oYhvqQMOBhhtk/edit#slide=id.g203aae413f_0_0

#8 lore raw
In reply to Willy Tarreau
Quoted 7 lines · Willy Tarreau
Quoted 6 lines · Tom Herbert
Quoted 6 lines

In fact that's not much what I observe in field. In practice, large data streams are cheaply relayed using splice(), I could achieve 60 Gbps of HTTP forwarding via HAProxy on a 4-core xeon 2 years ago. And when you use SSL, the cost of the copy to/from kernel is small compared to all the crypto operations surrounding this.

Quoted 5 lines
Quoted 2 lines

Right, getting rid of the extra crypto operations and so called "SSL inspection" is the ultimate goal this is going towards.

Yep but in order to take decisions at L7 you need to decapsulate SSL.

Decapsulate or decrypt? There's a big difference... :-) I'm am aiming to just have to decapsulate.

Quoted 13 lines
Quoted 3 lines

HTTP is only one use case. The are other interesting use cases such as those in container security where the application protocol might be something like simple RPC.

OK that indeed makes sense in such environments.

Quoted 6 lines

Performance is relevant because we
potentially want security applied to every message in every communication in a containerized data center. Putting the userspace hop in the datapath of every packet is know to be problematic, not just for the performance hit also because it increases the attack surface on users' privacy.

Quoted 8 lines

While I totally agree on the performance hit when inspecting each packet, I fail to see the relation with users' privacy. In fact under some circumstances it can even be the opposite. For example, using something like kTLS for a TCP/HTTP proxy can result in cleartext being observable in strace while it's not visible when TLS is terminated in userland because all you see are openssl's read()/write() operations. Maybe you have specific attacks in mind ?

No, just the normal problem of making yet one more tool systematically have access to user data.

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

Regarding kernel-side protocol parsing, there's an unfortunate trend at moving more and more protocols to userland due to these protocols evolving very quickly. At least you'll want to find a way to provide these parsers from userspace, which will inevitably come with its set of problems or limitations :-/

That's why everything is going BPF now ;-)

Quoted 9 lines

Yes, I knew you were going to suggest this :-) I'm still prudent on it to be honnest. I don't think it would be that easy to implement an HPACK encoder/decoder using BPF. And even regarding just plain HTTP parsing, certain very small operations in haproxy's parser can quickly result in a 10% performance degradation when improperly optimized (ie: changing a "likely", altering branch prediction, or cache walk patterns when using arrays to evaluate character classes faster). But for general usage I indeed think it should be OK.

HTTP might qualify as a special case, and I believe there's already been some work to put http in kernel by Alexander Krizhanovsky and others. In this case maybe http parse could be front end before BPF. Although, pretty clear we'll need regex in BPF if we want use it with http.

Tom

#12 lore raw
In reply to Tom Herbert
Quoted 10 lines · Tom Herbert

I think the main part of that discussion was around stream parser which is needed for message delineation. For a 1:1 proxy, KCM is probably overkill (the whole KCM data path and lock becomes superfluous). Also, there's no concept of creating a whole message before routing it, in the 1:1 case we should let the message pass through once it's cleared by the filter (this is the strparser change I referred to). As I mentioned, for L7 load balancing we would want a multiplexor probably also M:N, but the structure is different since there's still no user facing sockets, they're all TCP for instance. IMO, the 1:1 proxy case is compelling to solve in itself...

I see. I was definitely thinking m:n. We should definitely evaluate whether it makes sense to have a specific 1:1 implementation if we need m:n anyway. For L7 LB, m:n seems obvious as a particular L4 connection may act as a transport for multiple requests bidirectional. KCM looks like a good starting point for that.

When I talked about enqueueing entire messages, the main concern is to buffer up the payload after the TLS handshake to the point to where a forwarding decision can be made. I would definitely not advocate to buffer entire messages before starting to forward.

#9 lore raw
In reply to Tom Herbert
Quoted 8 lines · Tom Herbert
Quoted 7 lines · Willy Tarreau
Quoted 6 lines · Tom Herbert
Quoted 6 lines

In fact that's not much what I observe in field. In practice, large data streams are cheaply relayed using splice(), I could achieve 60 Gbps of HTTP forwarding via HAProxy on a 4-core xeon 2 years ago. And when you use SSL, the cost of the copy to/from kernel is small compared to all the crypto operations surrounding this.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Right, getting rid of the extra crypto operations and so called "SSL inspection" is the ultimate goal this is going towards.

Yep but in order to take decisions at L7 you need to decapsulate SSL.

Decapsulate or decrypt? There's a big difference... :-) I'm am aiming to just have to decapsulate.

Sorry, but what difference do you make ? For me "decapsulate" means "extract the next level layer", and for SSL it means you need to decrypt.

Quoted 16 lines
Quoted 8 lines
Quoted 7 lines

Performance is relevant because we
potentially want security applied to every message in every communication in a containerized data center. Putting the userspace hop in the datapath of every packet is know to be problematic, not just for the performance hit also because it increases the attack surface on users' privacy.

Quoted 8 lines

While I totally agree on the performance hit when inspecting each packet, I fail to see the relation with users' privacy. In fact under some circumstances it can even be the opposite. For example, using something like kTLS for a TCP/HTTP proxy can result in cleartext being observable in strace while it's not visible when TLS is terminated in userland because all you see are openssl's read()/write() operations. Maybe you have specific attacks in mind ?

Quoted 2 lines

No, just the normal problem of making yet one more tool systematically have access to user data.

OK.

Quoted 17 lines
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

Regarding kernel-side protocol parsing, there's an unfortunate trend at moving more and more protocols to userland due to these protocols evolving very quickly. At least you'll want to find a way to provide these parsers from userspace, which will inevitably come with its set of problems or limitations :-/

That's why everything is going BPF now ;-)

Quoted 9 lines

Yes, I knew you were going to suggest this :-) I'm still prudent on it to be honnest. I don't think it would be that easy to implement an HPACK encoder/decoder using BPF. And even regarding just plain HTTP parsing, certain very small operations in haproxy's parser can quickly result in a 10% performance degradation when improperly optimized (ie: changing a "likely", altering branch prediction, or cache walk patterns when using arrays to evaluate character classes faster). But for general usage I indeed think it should be OK.

Quoted 3 lines

HTTP might qualify as a special case, and I believe there's already been some work to put http in kernel by Alexander Krizhanovsky and others. In this case maybe http parse could be front end before BPF.

It could indeed be an option. We've seen this with Tux in the past.

Quoted 2 lines

Although, pretty clear we'll need regex in BPF if we want use it with http.

I think so as well. And some loop-like operations (foreach or stuff like this so that they remain bounded).

Willy

maintainer
#2 lore raw

Re: [PATCH RFC 1/2] skbuff: Function to send an skbuf on a socket

In reply to Tom Herbert

From: Tom Herbert <[email protected]>
Date: Thu, 29 Jun 2017 11:27:04 -0700

net/core/skbuff.c int skb_splice_bits(struct sk_buff *skb, struct sock *sk, unsigned int offset, · line 2013

Quoted 5 lines
net/core/skbuff.c +5 -0
+int skb_send_sock(struct sk_buff *skb, struct socket *sock, unsigned int offset)
+{
+	unsigned int sent = 0;
+	unsigned int ret;
+	unsigned short fragidx;

Please use reverse christmas tree ordering for these local variables.

net/core/skbuff.c int skb_splice_bits(struct sk_buff *skb, struct sock *sk, unsigned int offset, · line 2019

Quoted 5 lines
net/core/skbuff.c +5 -0
+	/* Deal with head data */
+	while (offset < skb_headlen(skb)) {
+		size_t len = skb_headlen(skb) - offset;
+		struct kvec kv;
+		struct msghdr msg;

Likewise.

maintainer
#4 lore raw

Re: [PATCH RFC 2/2] kproxy: Kernel proxy

In reply to Tom Herbert

From: Tom Herbert <[email protected]>
Date: Thu, 29 Jun 2017 11:27:05 -0700

Quoted 2 lines

A proc file (/prox/net/kproxy) is created to list all the running kernel proxies and relevant statistics for them.

proc is deprecated for dumping information like this, please use sock diag instead.