From fed960b94a4ddb44b019c3fd1e187864f1ccfb6a Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Fri, 29 May 2020 13:33:12 -0700 Subject: [PATCH] net: tag net socket objects Used for permission validation when accessing the associated file descriptors from user mode. There often get defined in implementation code, expand the search to look in drivers/ and subsys/net/. Signed-off-by: Andrew Boie --- CMakeLists.txt | 2 ++ drivers/modem/modem_socket.h | 2 +- include/net/net_context.h | 2 +- subsys/net/lib/sockets/socketpair.c | 2 +- subsys/net/lib/sockets/sockets_net_mgmt.c | 2 +- subsys/net/lib/websocket/websocket_internal.h | 4 +++- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 02e8ba23d69..e0923ed40cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -594,6 +594,8 @@ add_custom_command( ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/parse_syscalls.py --include ${ZEPHYR_BASE}/include # Read files from this dir + --include ${ZEPHYR_BASE}/drivers # For net sockets + --include ${ZEPHYR_BASE}/subsys/net # More net sockets ${parse_syscalls_include_args} # Read files from these dirs also --json-file ${syscalls_json} # Write this file --tag-struct-file ${struct_tags_json} # Write subsystem list to this file diff --git a/drivers/modem/modem_socket.h b/drivers/modem/modem_socket.h index 055c7b997c5..0efa38378f4 100644 --- a/drivers/modem/modem_socket.h +++ b/drivers/modem/modem_socket.h @@ -23,7 +23,7 @@ extern "C" { #endif -struct modem_socket { +__net_socket struct modem_socket { sa_family_t family; enum net_sock_type type; enum net_ip_protocol ip_proto; diff --git a/include/net/net_context.h b/include/net/net_context.h index 0ad683741af..9d8d39b1ca3 100644 --- a/include/net/net_context.h +++ b/include/net/net_context.h @@ -196,7 +196,7 @@ struct tls_context; * If there is no such source address there, the packet cannot be sent * anyway. This saves 12 bytes / context in IPv6. */ -struct net_context { +__net_socket struct net_context { /** User data. * * First member of the structure to let users either have user data diff --git a/subsys/net/lib/sockets/socketpair.c b/subsys/net/lib/sockets/socketpair.c index be648a24601..0bf97337532 100644 --- a/subsys/net/lib/sockets/socketpair.c +++ b/subsys/net/lib/sockets/socketpair.c @@ -48,7 +48,7 @@ enum { * - write operations may block if the remote @a recv_q is full * - each endpoint may be blocking or non-blocking */ -struct spair { +__net_socket struct spair { int remote; /**< the remote endpoint file descriptor */ u32_t flags; /**< status and option bits */ struct k_sem sem; /**< semaphore for exclusive structure access */ diff --git a/subsys/net/lib/sockets/sockets_net_mgmt.c b/subsys/net/lib/sockets/sockets_net_mgmt.c index cb0c5383c45..97b22df83d1 100644 --- a/subsys/net/lib/sockets/sockets_net_mgmt.c +++ b/subsys/net/lib/sockets/sockets_net_mgmt.c @@ -23,7 +23,7 @@ LOG_MODULE_REGISTER(net_sock_mgmt, CONFIG_NET_SOCKETS_LOG_LEVEL); #define MSG_ALLOC_TIMEOUT K_MSEC(100) -struct net_mgmt_socket { +__net_socket struct net_mgmt_socket { /* Network interface related to this socket */ struct net_if *iface; diff --git a/subsys/net/lib/websocket/websocket_internal.h b/subsys/net/lib/websocket/websocket_internal.h index 150beb3b544..42a10331723 100644 --- a/subsys/net/lib/websocket/websocket_internal.h +++ b/subsys/net/lib/websocket/websocket_internal.h @@ -10,6 +10,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + #define WS_SHA1_OUTPUT_LEN 20 /* Min Websocket header length */ @@ -24,7 +26,7 @@ /** * Websocket connection information */ -struct websocket_context { +__net_socket struct websocket_context { union { /** User data. */