Another crack at a handshake upcall mechanism
Subsystems (7)
Chuck Lever
maintainerv10 cover Another crack at a handshake upcall mechanism
Hi-
Here is v10 of a series to add generic support for transport layer security handshake on behalf of kernel socket consumers (user space consumers use a security library directly, of course). A summary of the purpose of these patches is archived here:
https://lore.kernel.org/netdev/[email protected]/
The first patch in the series applies to the top-level .gitignore file to address the build warnings reported a few days ago. I intend to submit that separately. I'd like you to consider taking the rest of this series for v6.4.
The full patch set to support SunRPC with TLSv1.3 is available in the topic-rpc-with-tls-upcall branch here, based on net-next/main:
https://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git
This patch set includes support for in-transit confidentiality and peer authentication for both the Linux NFS client and server.
A user space handshake agent for TLSv1.3 to go along with the kernel patches is available in the "main" branch here:
https://github.com/oracle/ktls-utils
---
Changes since v9:
- Address build problems with Kunit tests
Changes since v8:
- Addressed Jakub's v8 review comments
- Fixed build problems with the new unit tests
- Addressed crashes in some corner case
Major changes since v7:
- Addressed Paolo's v7 review comments
- Added initial set of Kunit tests for the handshake API
- Included an NFS server patch to add new TLS_RECORD_TYPE values
Major changes since v6:
- YAML spec and generated artifacts are now under dual license
- Addressed Jakub's v6 review comments
- Implemented a memory-sensitive limit on the number of pending handshake requests
- Implemented upcall support for multiple peer identities
Major changes since v5:
- Added a "timeout" attribute to the handshake netlink protocol
- Removed the GnuTLS-specific "priorities" attribute
- Added support for keyrings to restrict access to keys
- Simplified the kernel consumer TLS handshake API
- The handshake netlink protocol can handle multiple peer IDs or certificates in the ACCEPT and DONE operations, though the implementation does not yet support it.
Major changes since v4:
- Rebased onto net-next/main
- Replaced req reference counting with ->sk_destruct
- CMD_ACCEPT now does the equivalent of a dup(2) rather than an accept(2)
- CMD_DONE no longer closes the user space socket endpoint
- handshake_req_cancel is now tested and working
- Added a YAML specification for the netlink upcall protocol, and simplified the protocol to fit the YAML schema
- Added an initial set of tracepoints
Changes since v3:
- Converted all netlink code to use Generic Netlink
- Reworked handshake request lifetime logic throughout
- Global pending list is now per-net
- On completion, return the remote's identity to the consumer
Changes since v2:
- PF_HANDSHAKE replaced with NETLINK_HANDSHAKE
- Replaced listen(2) / poll(2) with a multicast notification service
- Replaced accept(2) with a netlink operation that can return an open fd and handshake parameters
- Replaced close(2) with a netlink operation that can take arguments
Changes since RFC:
- Generic upcall support split away from kTLS
- Added support for TLS ServerHello
- Documentation has been temporarily removed while API churns
---
Chuck Lever (4):
.gitignore: Do not ignore .kunitconfig files
net/handshake: Create a NETLINK service for handling handshake requests net/handshake: Add a kernel API for requesting a TLSv1.3 handshake net/handshake: Add Kunit tests for the handshake consumer API
.gitignore | 1 + Documentation/netlink/specs/handshake.yaml | 124 +++++ Documentation/networking/index.rst | 1 + Documentation/networking/tls-handshake.rst | 217 +++++++++ MAINTAINERS | 11 + include/net/handshake.h | 43 ++ include/trace/events/handshake.h | 159 +++++++ include/uapi/linux/handshake.h | 73 +++ net/Kconfig | 20 + net/Makefile | 1 + net/handshake/.kunitconfig | 11 + net/handshake/Makefile | 13 + net/handshake/genl.c | 58 +++ net/handshake/genl.h | 24 + net/handshake/handshake-test.c | 523 +++++++++++++++++++++ net/handshake/handshake.h | 87 ++++ net/handshake/netlink.c | 319 +++++++++++++ net/handshake/request.c | 344 ++++++++++++++ net/handshake/tlshd.c | 418 ++++++++++++++++ net/handshake/trace.c | 20 + 20 files changed, 2467 insertions(+) create mode 100644 Documentation/netlink/specs/handshake.yaml create mode 100644 Documentation/networking/tls-handshake.rst create mode 100644 include/net/handshake.h create mode 100644 include/trace/events/handshake.h create mode 100644 include/uapi/linux/handshake.h create mode 100644 net/handshake/.kunitconfig create mode 100644 net/handshake/Makefile create mode 100644 net/handshake/genl.c create mode 100644 net/handshake/genl.h create mode 100644 net/handshake/handshake-test.c create mode 100644 net/handshake/handshake.h create mode 100644 net/handshake/netlink.c create mode 100644 net/handshake/request.c create mode 100644 net/handshake/tlshd.c create mode 100644 net/handshake/trace.c
--
Chuck Lever
Chuck Lever
maintainerPATCH v10 1/4 .gitignore: Do not ignore .kunitconfig files
From: Chuck Lever <[email protected]>
Circumvent the .gitignore wildcard to avoid warnings about ignored .kunitconfig files. As far as I can tell, the warnings are harmless and these files are not actually ignored.
--- .gitignore | 1 + 1 file changed, 1 insertion(+)
.gitignore +1 -0
@@ -105,6 +105,7 @@ modules.order !.gitignore !.mailmap !.rustfmt.toml +!.kunitconfig # # Generated include files
Chuck Lever
maintainerPATCH v10 2/4 net/handshake: Create a NETLINK service for handling handshake requests
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
When a kernel consumer needs a transport layer security session, it first needs a handshake to negotiate and establish a session. This negotiation can be done in user space via one of the several existing library implementations, or it can be done in the kernel.
No in-kernel handshake implementations yet exist. In their absence, we add a netlink service that can:
a. Notify a user space daemon that a handshake is needed.
b. Once notified, the daemon calls the kernel back via this
netlink service to get the handshake parameters, including an open socket on which to establish the session.
c. Once the handshake is complete, the daemon reports the
session status and other information via a second netlink operation. This operation marks that it is safe for the kernel to use the open socket and the security session established there.
The notification service uses a multicast group. Each handshake mechanism (eg, tlshd) adopts its own group number so that the handshake services are completely independent of one another. The kernel can then tell via netlink_has_listeners() whether a handshake service is active and prepared to handle a handshake request.
A new netlink operation, ACCEPT, acts like accept(2) in that it instantiates a file descriptor in the user space daemon's fd table. If this operation is successful, the reply carries the fd number, which can be treated as an open and ready file descriptor.
While user space is performing the handshake, the kernel keeps its muddy paws off the open socket. A second new netlink operation, DONE, indicates that the user space daemon is finished with the socket and it is safe for the kernel to use again. The operation also indicates whether a session was established successfully.
--- Documentation/netlink/specs/handshake.yaml | 122 ++++++++++ MAINTAINERS | 9 + include/trace/events/handshake.h | 159 +++++++++++++ include/uapi/linux/handshake.h | 71 ++++++ net/Kconfig | 5 net/Makefile | 1 net/handshake/Makefile | 11 + net/handshake/genl.c | 57 +++++ net/handshake/genl.h | 23 ++ net/handshake/handshake.h | 82 +++++++ net/handshake/netlink.c | 312 ++++++++++++++++++++++++++ net/handshake/request.c | 339 ++++++++++++++++++++++++++++ net/handshake/trace.c | 20 ++ 13 files changed, 1211 insertions(+) create mode 100644 Documentation/netlink/specs/handshake.yaml create mode 100644 include/trace/events/handshake.h create mode 100644 include/uapi/linux/handshake.h create mode 100644 net/handshake/Makefile create mode 100644 net/handshake/genl.c create mode 100644 net/handshake/genl.h create mode 100644 net/handshake/handshake.h create mode 100644 net/handshake/netlink.c create mode 100644 net/handshake/request.c create mode 100644 net/handshake/trace.c
Documentation/netlink/specs/handshake.yaml new file +122 -0
@@ -0,0 +1,122 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +# +# Author: Chuck Lever <[email protected]> +# +# Copyright (c) 2023, Oracle and/or its affiliates. +# + +name: handshake + +protocol: genetlink + +doc: Netlink protocol to request a transport layer security handshake. + +definitions: + - + type: enum + name: handler-class + value-start: 0 + entries: [ none, max ] + - + type: enum + name: msg-type + value-start: 0 + entries: [ unspec, clienthello, serverhello ] + - + type: enum + name: auth + value-start: 0 + entries: [ unspec, unauth, psk, x509 ] + +attribute-sets: + - + name: x509 + attributes: + - + name: cert + type: u32 + - + name: privkey + type: u32 + - + name: accept + attributes: + - + name: sockfd + type: u32 + - + name: handler-class + type: u32 + enum: handler-class + - + name: message-type + type: u32 + enum: msg-type + - + name: timeout + type: u32 + - + name: auth-mode + type: u32 + enum: auth + - + name: peer-identity + type: u32 + multi-attr: true + - + name: certificate + type: nest + nested-attributes: x509 + multi-attr: true + - + name: done + attributes: + - + name: status + type: u32 + - + name: sockfd + type: u32 + - + name: remote-auth + type: u32 + multi-attr: true + +operations: + list: + - + name: ready + doc: Notify handlers that a new handshake request is waiting + notify: accept + - + name: accept + doc: Handler retrieves next queued handshake request + attribute-set: accept + flags: [ admin-perm ] + do: + request: + attributes: + - handler-class + reply: + attributes: + - sockfd + - message-type + - timeout + - auth-mode + - peer-identity + - certificate + - + name: done + doc: Handler reports handshake completion + attribute-set: done + do: + request: + attributes: + - status + - sockfd + - remote-auth + +mcast-groups: + list: + - + name: none
MAINTAINERS +9 -0
@@ -8947,6 +8947,15 @@ Q: http://patchwork.linuxtv.org/project/linux-media/list/ T: git git://linuxtv.org/anttip/media_tree.git F: drivers/media/usb/hackrf/ +HANDSHAKE UPCALL FOR TRANSPORT LAYER SECURITY +M: Chuck Lever <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: Documentation/netlink/specs/handshake.yaml +F: include/trace/events/handshake.h +F: net/handshake/ + HANTRO VPU CODEC DRIVER M: Ezequiel Garcia <[email protected]> M: Philipp Zabel <[email protected]>
include/trace/events/handshake.h new file +159 -0
159 lines not on this page · raw message
include/uapi/linux/handshake.h new file +71 -0
71 lines not on this page · raw message
net/Kconfig +5 -0
@@ -68,6 +68,11 @@ source "net/iucv/Kconfig" source "net/smc/Kconfig" source "net/xdp/Kconfig" +config NET_HANDSHAKE + bool + depends on SUNRPC || NVME_TARGET_TCP || NVME_TCP + default y + config INET bool "TCP/IP networking" help
net/Makefile +1 -0
@@ -79,3 +79,4 @@ obj-$(CONFIG_NET_NCSI) += ncsi/ obj-$(CONFIG_XDP_SOCKETS) += xdp/ obj-$(CONFIG_MPTCP) += mptcp/ obj-$(CONFIG_MCTP) += mctp/ +obj-$(CONFIG_NET_HANDSHAKE) += handshake/
net/handshake/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for the Generic HANDSHAKE service +# +# Author: Chuck Lever <[email protected]> +# +# Copyright (c) 2023, Oracle and/or its affiliates. +# + +obj-y += handshake.o +handshake-y := genl.o netlink.o request.o trace.o
net/handshake/genl.c new file +57 -0
57 lines not on this page · raw message
net/handshake/genl.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/handshake.yaml */ +/* YNL-GEN kernel header */ + +#ifndef _LINUX_HANDSHAKE_GEN_H +#define _LINUX_HANDSHAKE_GEN_H + +#include <net/netlink.h> +#include <net/genetlink.h> + +#include <linux/handshake.h> + +int handshake_nl_accept_doit (struct sk_buff *skb,struct genl_info *info); +int handshake_nl_done_doit (struct sk_buff *skb,struct genl_info *info); + +enum { +HANDSHAKE_NLGRP_NONE , +}; + +extern struct genl_family handshake_nl_family; + +#endif /* _LINUX_HANDSHAKE_GEN_H */
net/handshake/handshake.h new file +82 -0
82 lines not on this page · raw message
net/handshake/netlink.c new file +312 -0
312 lines not on this page · raw message
net/handshake/request.c new file +339 -0
339 lines not on this page · raw message
net/handshake/trace.c new file +20 -0
@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Trace points for transport security layer handshakes. +* +* Author: Chuck Lever <[email protected]> +* +* Copyright (c) 2023, Oracle and/or its affiliates. +*/ + +#include <linux/types.h> + +#include <net/sock.h> +#include <net/netlink.h> +#include <net/genetlink.h> + +#include "handshake.h" + +#define CREATE_TRACE_POINTS + +#include <trace/events/handshake.h>
Re: [PATCH v10 2/4] net/handshake: Create a NETLINK service for handling handshake requests
Hi Chuck,
Quoted 40 lines · Chuck Lever
From: Chuck Lever <[email protected]>
When a kernel consumer needs a transport layer security session, it first needs a handshake to negotiate and establish a session. This negotiation can be done in user space via one of the several existing library implementations, or it can be done in the kernel.
No in-kernel handshake implementations yet exist. In their absence, we add a netlink service that can:
a. Notify a user space daemon that a handshake is needed.
b. Once notified, the daemon calls the kernel back via this
netlink service to get the handshake parameters, including an open socket on which to establish the session.c. Once the handshake is complete, the daemon reports the
session status and other information via a second netlink operation. This operation marks that it is safe for the kernel to use the open socket and the security session established there.The notification service uses a multicast group. Each handshake mechanism (eg, tlshd) adopts its own group number so that the handshake services are completely independent of one another. The kernel can then tell via
netlink_has_listeners()whether a handshake service is active and prepared to handle a handshake request.A new netlink operation, ACCEPT, acts like accept(2) in that it instantiates a file descriptor in the user space daemon's fd table. If this operation is successful, the reply carries the fd number, which can be treated as an open and ready file descriptor.
While user space is performing the handshake, the kernel keeps its muddy paws off the open socket. A second new netlink operation, DONE, indicates that the user space daemon is finished with the socket and it is safe for the kernel to use again. The operation also indicates whether a session was established successfully.
Signed-off-by Chuck Lever <[email protected]>
...
Quoted 1 line
net/handshake/netlink.c | 312 ++++++++++++++++++++++++++
...
Quoted 6 lines
net/handshake/netlink.c new file +6
-0+static struct pernet_operations __net_initdata handshake_genl_net_ops = { + .init = handshake_net_init, + .exit = handshake_net_exit, + .id = &handshake_net_id, + .size =sizeof (struct handshake_net ), +};
...
net/handshake/netlink.c line 312
Quoted 11 lines
net/handshake/netlink.c new file +11
-0+static void __exit handshake_exit(void) +{ +unregister_pernet_subsys (&handshake_genl_net_ops); + handshake_net_id =0 ; + +handshake_req_hash_destroy (); +genl_unregister_family (&handshake_nl_family); +} + +module_init (handshake_init); +module_exit (handshake_exit);
I am not sure if this has been reported yet but it appears this introduces a section mismatch warning in several configurations according to KernelCI:
https://lore.kernel.org/[email protected]/
$ make -skj"$(nproc)" ARCH=mips CROSS_COMPILE=mips-linux- O=build jazz_defconfig all ... WARNING: modpost: vmlinux.o: section mismatch in reference: handshake_exit (section: .exit.text) -> handshake_genl_net_ops (section: .init.data)
I guess '__net_initdata' should be dropped from handshake_genl_net_ops?
Cheers,
Nathan
Re: [PATCH v10 2/4] net/handshake: Create a NETLINK service for handling handshake requests
Quoted 73 lines · Nathan Chancellor
Hi Chuck,
Quoted 40 lines · Chuck Lever
From: Chuck Lever <[email protected]>
When a kernel consumer needs a transport layer security session, it first needs a handshake to negotiate and establish a session. This negotiation can be done in user space via one of the several existing library implementations, or it can be done in the kernel.
No in-kernel handshake implementations yet exist. In their absence, we add a netlink service that can:
a. Notify a user space daemon that a handshake is needed.
b. Once notified, the daemon calls the kernel back via this
netlink service to get the handshake parameters, including an open socket on which to establish the session.c. Once the handshake is complete, the daemon reports the
session status and other information via a second netlink operation. This operation marks that it is safe for the kernel to use the open socket and the security session established there.The notification service uses a multicast group. Each handshake mechanism (eg, tlshd) adopts its own group number so that the handshake services are completely independent of one another. The kernel can then tell via
netlink_has_listeners()whether a handshake service is active and prepared to handle a handshake request.A new netlink operation, ACCEPT, acts like accept(2) in that it instantiates a file descriptor in the user space daemon's fd table. If this operation is successful, the reply carries the fd number, which can be treated as an open and ready file descriptor.
While user space is performing the handshake, the kernel keeps its muddy paws off the open socket. A second new netlink operation, DONE, indicates that the user space daemon is finished with the socket and it is safe for the kernel to use again. The operation also indicates whether a session was established successfully.
Signed-off-by Chuck Lever <[email protected]>...
Quoted 1 line
net/handshake/netlink.c| 312 ++++++++++++++++++++++++++...
Quoted 6 lines
net/handshake/netlink.c new file +6
-0+static struct pernet_operations __net_initdata handshake_genl_net_ops = { + .init = handshake_net_init, + .exit = handshake_net_exit, + .id = &handshake_net_id, + .size =sizeof (struct handshake_net ), +};...
net/handshake/netlink.c line 312
Quoted 11 lines
net/handshake/netlink.c new file +11
-0+static void __exit handshake_exit(void) +{ +unregister_pernet_subsys (&handshake_genl_net_ops); + handshake_net_id =0 ; + +handshake_req_hash_destroy (); +genl_unregister_family (&handshake_nl_family); +} + +module_init (handshake_init); +module_exit (handshake_exit);I am not sure if this has been reported yet but it appears this introduces a section mismatch warning in several configurations according to KernelCI:
Quoted 7 lines
https://lore.kernel.org/[email protected]/
$ make -skj"$(nproc)" ARCH=mips CROSS_COMPILE=mips-linux- O=build jazz_defconfig all ... WARNING: modpost: vmlinux.o: section mismatch in reference: handshake_exit (section: .exit.text) -> handshake_genl_net_ops (section: .init.data)I guess '
__net_initdata' should be dropped fromhandshake_genl_net_ops?
Thanks, Geert just sent a patch to fix that.
--
Chuck Lever
Re: [PATCH v10 2/4] net/handshake: Create a NETLINK service for handling handshake requests
Quoted 75 lines · Chuck Lever III
Quoted 75 lines · Nathan Chancellor
Hi Chuck,
Quoted 40 lines · Chuck Lever
From: Chuck Lever <[email protected]>
When a kernel consumer needs a transport layer security session, it first needs a handshake to negotiate and establish a session. This negotiation can be done in user space via one of the several existing library implementations, or it can be done in the kernel.
No in-kernel handshake implementations yet exist. In their absence, we add a netlink service that can:
a. Notify a user space daemon that a handshake is needed.
b. Once notified, the daemon calls the kernel back via this
netlink service to get the handshake parameters, including an open socket on which to establish the session.c. Once the handshake is complete, the daemon reports the
session status and other information via a second netlink operation. This operation marks that it is safe for the kernel to use the open socket and the security session established there.The notification service uses a multicast group. Each handshake mechanism (eg, tlshd) adopts its own group number so that the handshake services are completely independent of one another. The kernel can then tell via
netlink_has_listeners()whether a handshake service is active and prepared to handle a handshake request.A new netlink operation, ACCEPT, acts like accept(2) in that it instantiates a file descriptor in the user space daemon's fd table. If this operation is successful, the reply carries the fd number, which can be treated as an open and ready file descriptor.
While user space is performing the handshake, the kernel keeps its muddy paws off the open socket. A second new netlink operation, DONE, indicates that the user space daemon is finished with the socket and it is safe for the kernel to use again. The operation also indicates whether a session was established successfully.
Signed-off-by Chuck Lever <[email protected]>...
Quoted 1 line
net/handshake/netlink.c| 312 ++++++++++++++++++++++++++...
Quoted 6 lines
net/handshake/netlink.c new file +6
-0+static struct pernet_operations __net_initdata handshake_genl_net_ops = { + .init = handshake_net_init, + .exit = handshake_net_exit, + .id = &handshake_net_id, + .size =sizeof (struct handshake_net ), +};...
net/handshake/netlink.c line 312
Quoted 11 lines
net/handshake/netlink.c new file +11
-0+static void __exit handshake_exit(void) +{ +unregister_pernet_subsys (&handshake_genl_net_ops); + handshake_net_id =0 ; + +handshake_req_hash_destroy (); +genl_unregister_family (&handshake_nl_family); +} + +module_init (handshake_init); +module_exit (handshake_exit);I am not sure if this has been reported yet but it appears this introduces a section mismatch warning in several configurations according to KernelCI:
Quoted 7 lines
Quoted 5 lines
$ make -skj"$(nproc)" ARCH=mips CROSS_COMPILE=mips-linux- O=build jazz_defconfig all ... WARNING: modpost: vmlinux.o: section mismatch in reference: handshake_exit (section: .exit.text) -> handshake_genl_net_ops (section: .init.data)I guess '
__net_initdata' should be dropped fromhandshake_genl_net_ops?Thanks, Geert just sent a patch to fix that.
Ha, I did check lore for an existing report or patch before I wrote the mail but not before I sent it... Sorry for the noise!
Cheers,
Nathan
Chuck Lever
maintainerPATCH v10 3/4 net/handshake: Add a kernel API for requesting a TLSv1.3 handshake
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
To enable kernel consumers of TLS to request a TLS handshake, add support to net/handshake/ to request a handshake upcall.
This patch also acts as a template for adding handshake upcall support for other kernel transport layer security providers.
--- Documentation/netlink/specs/handshake.yaml | 4 Documentation/networking/index.rst | 1 Documentation/networking/tls-handshake.rst | 217 +++++++++++++++ MAINTAINERS | 2 include/net/handshake.h | 43 +++ include/uapi/linux/handshake.h | 2 net/handshake/Makefile | 2 net/handshake/genl.c | 3 net/handshake/genl.h | 1 net/handshake/tlshd.c | 417 ++++++++++++++++++++++++++++ 10 files changed, 689 insertions(+), 3 deletions(-) create mode 100644 Documentation/networking/tls-handshake.rst create mode 100644 include/net/handshake.h create mode 100644 net/handshake/tlshd.c
Documentation/netlink/specs/handshake.yaml +3 -1
@@ -16,7 +16,7 @@ definitions: type: enum name: handler-class value-start: 0 - entries: [ none, max ] + entries: [ none, tlshd, max ] - type: enum name: msg-type
@@ -120,3 +120,5 @@ mcast-groups: list: - name: none + - + name: tlshd
Documentation/networking/index.rst +1 -0
@@ -36,6 +36,7 @@ Contents: scaling tls tls-offload + tls-handshake nfc 6lowpan 6pack
Documentation/networking/tls-handshake.rst new file +217 -0
217 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -8953,6 +8953,8 @@ L: [email protected] L: [email protected] S: Maintained F: Documentation/netlink/specs/handshake.yaml +F: Documentation/networking/tls-handshake.rst +F: include/net/handshake.h F: include/trace/events/handshake.h F: net/handshake/
include/net/handshake.h new file +43 -0
43 lines not on this page · raw message
include/uapi/linux/handshake.h +2 -0
@@ -11,6 +11,7 @@enum handshake_handler_class {HANDSHAKE_HANDLER_CLASS_NONE , +HANDSHAKE_HANDLER_CLASS_TLSHD ,HANDSHAKE_HANDLER_CLASS_MAX , };
@@ -67,5 +68,6 @@ enum { };#define HANDSHAKE_MCGRP_NONE "none" +#define HANDSHAKE_MCGRP_TLSHD "tlshd"#endif /* _UAPI_LINUX_HANDSHAKE_H */
net/handshake/Makefile +1 -1
@@ -8,4 +8,4 @@ # obj-y += handshake.o -handshake-y := genl.o netlink.o request.o trace.o +handshake-y := genl.o netlink.o request.o tlshd.o trace.o
net/handshake/genl.c +2 -1
@@ -12,7 +12,7 @@/* HANDSHAKE_CMD_ACCEPT - do */ static const struct nla_policy handshake_accept_nl_policy[HANDSHAKE_A_ACCEPT_HANDLER_CLASS +1 ] = { - [HANDSHAKE_A_ACCEPT_HANDLER_CLASS ] =NLA_POLICY_MAX (NLA_U32 ,1 ), + [HANDSHAKE_A_ACCEPT_HANDLER_CLASS ] =NLA_POLICY_MAX (NLA_U32 ,2 ), };/* HANDSHAKE_CMD_DONE - do */
@@ -42,6 +42,7 @@ static const struct genl_split_ops handshake_nl_ops[] = {static const struct genl_multicast_group handshake_nl_mcgrps[] = { [HANDSHAKE_NLGRP_NONE ] = {"none" , }, + [HANDSHAKE_NLGRP_TLSHD ] = {"tlshd" , }, };struct genl_family handshake_nl_family__ro_after_init = {
net/handshake/genl.h +1 -0
@@ -16,6 +16,7 @@ int handshake_nl_done_doit(struct sk_buff *skb, struct genl_info *info);enum {HANDSHAKE_NLGRP_NONE , +HANDSHAKE_NLGRP_TLSHD , };extern struct genl_family handshake_nl_family;
net/handshake/tlshd.c new file +417 -0
417 lines not on this page · raw message
Chuck Lever
maintainerPATCH v10 4/4 net/handshake: Add Kunit tests for the handshake consumer API
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
These verify the API contracts and help exercise lifetime rules for consumer sockets and handshake_req structures.
One way to run these tests:
./tools/testing/kunit/kunit.py run --kunitconfig ./net/handshake/.kunitconfig
--- net/Kconfig | 15 + net/handshake/.kunitconfig | 11 + net/handshake/Makefile | 2 net/handshake/handshake-test.c | 523 ++++++++++++++++++++++++++++++++++++++++ net/handshake/handshake.h | 5 net/handshake/netlink.c | 7 + net/handshake/request.c | 5 net/handshake/tlshd.c | 1 8 files changed, 569 insertions(+) create mode 100644 net/handshake/.kunitconfig create mode 100644 net/handshake/handshake-test.c
net/Kconfig +15 -0
@@ -73,6 +73,21 @@ config NET_HANDSHAKE depends on SUNRPC || NVME_TARGET_TCP || NVME_TCP default y +config NET_HANDSHAKE_KUNIT_TEST + tristate "KUnit tests for the handshake upcall mechanism" if !KUNIT_ALL_TESTS + default KUNIT_ALL_TESTS + depends on KUNIT + help + This builds the KUnit tests for the handshake upcall mechanism. + + KUnit tests run during boot and output the results to the debug + log in TAP format (https://testanything.org/). Only useful for + kernel devs running KUnit test harness and are not for inclusion + into a production build. + + For more information on KUnit and unit tests in general, refer + to the KUnit documentation in Documentation/dev-tools/kunit/. + config INET bool "TCP/IP networking" help
net/handshake/.kunitconfig new file +11 -0
@@ -0,0 +1,11 @@ +CONFIG_KUNIT=y +CONFIG_UBSAN=y +CONFIG_STACKTRACE=y +CONFIG_NET=y +CONFIG_NETWORK_FILESYSTEMS=y +CONFIG_INET=y +CONFIG_MULTIUSER=y +CONFIG_NFS_FS=y +CONFIG_SUNRPC=y +CONFIG_NET_HANDSHAKE=y +CONFIG_NET_HANDSHAKE_KUNIT_TEST=y
net/handshake/Makefile +2 -0
@@ -9,3 +9,5 @@ obj-y += handshake.o handshake-y := genl.o netlink.o request.o tlshd.o trace.o + +obj-$(CONFIG_NET_HANDSHAKE_KUNIT_TEST) += handshake-test.o
net/handshake/handshake-test.c new file +523 -0
523 lines not on this page · raw message
net/handshake/handshake.h +5 -0
@@ -49,6 +49,7 @@ enum hr_flags_bits {struct handshake_proto {int hp_handler_class;size_t hp_privsize; +unsigned long hp_flags;int (*hp_accept)(struct handshake_req *req,struct genl_info *info,int fd);
@@ -58,6 +59,10 @@ struct handshake_proto {void (*hp_destroy)(struct handshake_req *req); }; +enum hp_flags_bits { +HANDSHAKE_F_PROTO_NOTIFY , +}; +/* netlink.c */ int handshake_genl_notify (struct net *net,const struct handshake_proto *proto,gfp_t flags);
net/handshake/netlink.c +7 -0
@@ -18,6 +18,8 @@#include <net/genetlink.h> #include <net/netns/generic.h> +#include <kunit/visibility.h> +#include <uapi/linux/handshake.h> #include "handshake.h" #include "genl.h"
@@ -38,6 +40,10 @@ int handshake_genl_notify(struct net *net, const struct handshake_proto *proto,struct sk_buff *msg;void *hdr; +/* Disable notifications during unit testing */ +if (!test_bit (HANDSHAKE_F_PROTO_NOTIFY , &proto->hp_flags)) +return 0 ; +if (!genl_has_listeners (&handshake_nl_family, net, proto->hp_handler_class))return -ESRCH ;
@@ -262,6 +268,7 @@ struct handshake_net *handshake_pernet(struct net *net)return handshake_net_id ?net_generic (net, handshake_net_id) :NULL ; } +EXPORT_SYMBOL_IF_KUNIT (handshake_pernet);static int __init handshake_init (void ) {
net/handshake/request.c +5 -0
@@ -20,6 +20,8 @@#include <net/genetlink.h> #include <net/netns/generic.h> +#include <kunit/visibility.h> +#include <uapi/linux/handshake.h> #include "handshake.h"
@@ -60,6 +62,7 @@ struct handshake_req *handshake_req_hash_lookup(struct sock *sk)return rhashtable_lookup_fast (&handshake_rhashtbl, &sk, handshake_rhash_params); } +EXPORT_SYMBOL_IF_KUNIT (handshake_req_hash_lookup);static bool handshake_req_hash_add (struct handshake_req *req) {
@@ -192,6 +195,7 @@ struct handshake_req *handshake_req_next(struct handshake_net *hn, int class)return req; } +EXPORT_SYMBOL_IF_KUNIT (handshake_req_next);/** * handshake_req_submit - Submit a handshake request
@@ -293,6 +297,7 @@ void handshake_complete(struct handshake_req *req, unsigned int status,sock_put (sk); } } +EXPORT_SYMBOL_IF_KUNIT (handshake_complete);/** * handshake_req_cancel - Cancel an in-progress handshake
net/handshake/tlshd.c +1 -0
@@ -249,6 +249,7 @@ static int tls_handshake_accept(struct handshake_req *req,static const struct handshake_proto tls_handshake_proto = { .hp_handler_class =HANDSHAKE_HANDLER_CLASS_TLSHD , .hp_privsize =sizeof (struct tls_handshake_req ), + .hp_flags =BIT (HANDSHAKE_F_PROTO_NOTIFY ), .hp_accept = tls_handshake_accept, .hp_done = tls_handshake_done,
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Mon, 17 Apr 2023 10:32:12 -0400 you wrote:
Hi-
Here is v10 of a series to add generic support for transport layer security handshake on behalf of kernel socket consumers (user space consumers use a security library directly, of course). A summary of the purpose of these patches is archived here:
[...]
Here is the summary with links:
- [v10,1/4] .gitignore: Do not ignore .kunitconfig files
https://git.kernel.org/netdev/net-next/c/2bc42f482bed - [v10,2/4] net/handshake: Create a NETLINK service for handling handshake requests https://git.kernel.org/netdev/net-next/c/3b3009ea8abb - [v10,3/4] net/handshake: Add a kernel API for requesting a TLSv1.3 handshake https://git.kernel.org/netdev/net-next/c/2fd5532044a8 - [v10,4/4] net/handshake: Add Kunit tests for the handshake consumer API https://git.kernel.org/netdev/net-next/c/88232ec1ec5e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html