Skip to content
Permalink
Browse files

net: socket: Add userspace support to setsockopt()

Allow userspace application to call setsockopt() without crashing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar authored and andrewboie committed Jun 19, 2019
1 parent 40ec4bc commit ee849826e3ec680ec7c1eae76725d6b48475e335
Showing with 22 additions and 4 deletions.
  1. +2 −2 include/net/socket.h
  2. +20 −2 subsys/net/lib/sockets/sockets.c
@@ -367,8 +367,8 @@ int zsock_getsockopt(int sock, int level, int optname,
* if :option:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* @endrst
*/
int zsock_setsockopt(int sock, int level, int optname,
const void *optval, socklen_t optlen);
__syscall int zsock_setsockopt(int sock, int level, int optname,
const void *optval, socklen_t optlen);

/**
* @brief Get socket name
@@ -1169,12 +1169,30 @@ int zsock_setsockopt_ctx(struct net_context *ctx, int level, int optname,
return -1;
}

int zsock_setsockopt(int sock, int level, int optname,
const void *optval, socklen_t optlen)
int z_impl_zsock_setsockopt(int sock, int level, int optname,
const void *optval, socklen_t optlen)
{
VTABLE_CALL(setsockopt, sock, level, optname, optval, optlen);
}

#ifdef CONFIG_USERSPACE
Z_SYSCALL_HANDLER(zsock_setsockopt, sock, level, optname, optval, optlen)
{
void *kernel_optval;
int ret;

kernel_optval = z_user_alloc_from_copy((const void *)optval, optlen);
Z_OOPS(!kernel_optval);

ret = z_impl_zsock_setsockopt(sock, level, optname,
kernel_optval, optlen);

k_free(kernel_optval);

return ret;
}
#endif /* CONFIG_USERSPACE */

int zsock_getsockname_ctx(struct net_context *ctx, struct sockaddr *addr,
socklen_t *addrlen)
{

0 comments on commit ee84982

Please sign in to comment.
You can’t perform that action at this time.