]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
sockets.c: Refuse to deal with non-sockets
authorFlorian Schmidt <florian.schmidt@neclab.eu>
Mon, 20 May 2019 11:29:50 +0000 (13:29 +0200)
committerFelipe Huici <felipe.huici@neclab.eu>
Wed, 29 May 2019 12:36:04 +0000 (14:36 +0200)
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 <florian.schmidt@neclab.eu>
Reviewed-by: Felipe Huici <felipe.huici@neclab.eu>
sockets.c

index bbee72b4e5755e82f1f4dbc17630c928f3e026bf..b2a65bb45c7b40e88f15c2d340a965bf8a17a15b 100644 (file)
--- 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",