From: Florian Schmidt Date: Mon, 20 May 2019 11:29:50 +0000 (+0200) Subject: sockets.c: Refuse to deal with non-sockets X-Git-Tag: RELEASE-0.4~66 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=44d3880c58fa24e0390062617e70a1ad45922603;p=unikraft%2Flibs%2Flwip.git sockets.c: Refuse to deal with non-sockets Otherwise, socket_net_file_get() will try to look up lwip's file descriptors for file objects not created by lwip, reading garbage from where it expects sock_fd in sock_net_file. Signed-off-by: Florian Schmidt Reviewed-by: Felipe Huici --- diff --git a/sockets.c b/sockets.c index bbee72b..b2a65bb 100644 --- a/sockets.c +++ b/sockets.c @@ -65,6 +65,12 @@ static inline struct sock_net_file *sock_net_file_get(int fd) file = ERR2PTR(-EINVAL); goto EXIT; } + if (fos->f_dentry->d_vnode->v_type != VSOCK) { + LWIP_DEBUGF(SOCKETS_DEBUG, + ("file descriptor is not a socket\n")); + file = ERR2PTR(-EBADF); + goto EXIT; + } file = __containerof(fos, struct sock_net_file, vfscore_file); EXIT: return file; @@ -122,6 +128,7 @@ static int sock_fd_alloc(struct vnops *v_op, int sock_fd) uk_mutex_init(&s_vnode->v_lock); s_vnode->v_refcnt = 1; s_vnode->v_data = file; + s_vnode->v_type = VSOCK; file->sock_fd = sock_fd; LWIP_DEBUGF(SOCKETS_DEBUG, ("Allocated socket %d (%x)\n",