1 Description: backport of dpdk fix for LP: #1566874
3 Forwarded: n/a (already discussed upstream)
4 Author: Christian Ehrhardt <christian.ehrhardt@canonical.com>
5 Last-Update: 2016-06-06
7 Extended by Christian Ehrhardt <christian.ehrhardt@canonical.com>
8 Close fd on vserver->listenfd (Part of the upstream discussion)
11 From: Patrik Andersson <patrik.r.andersson@ericsson.com>
13 Protect against DPDK crash when allocation of listen fd >= 1023.
14 For events on fd:s >1023, the current implementation will trigger
15 an abort due to access outside of allocated bit mask.
17 Corrections would include:
19 * Match fdset_add() signature in fd_man.c to fd_man.h
20 * Handling of return codes from fdset_add()
21 * Addition of check of fd number in fdset_add_fd()
23 The rationale behind the suggested code change is that,
24 fdset_event_dispatch() could attempt access outside of the FD_SET
25 bitmask if there is an event on a file descriptor that in turn
26 looks up a virtio file descriptor with a value > 1023.
27 Such an attempt will lead to an abort() and a restart of any
30 A discussion topic exist in the ovs-discuss mailing list that can
31 provide a little more background:
33 http://openvswitch.org/pipermail/discuss/2016-February/020243.html
35 Signed-off-by: Patrik Andersson <patrik.r.andersson@ericsson.com>
37 fd_man.c | 11 ++++++-----
38 vhost-net-user.c | 23 +++++++++++++++++++++--
39 2 files changed, 27 insertions(+), 7 deletions(-)
41 Index: deb_dpdk/lib/librte_vhost/vhost_user/fd_man.c
42 ===================================================================
43 --- deb_dpdk.orig/lib/librte_vhost/vhost_user/fd_man.c
44 +++ deb_dpdk/lib/librte_vhost/vhost_user/fd_man.c
45 @@ -71,20 +71,22 @@ fdset_find_free_slot(struct fdset *pfdse
46 return fdset_find_fd(pfdset, -1);
51 fdset_add_fd(struct fdset *pfdset, int idx, int fd,
52 fd_cb rcb, fd_cb wcb, void *dat)
54 struct fdentry *pfdentry;
56 - if (pfdset == NULL || idx >= MAX_FDS)
58 + if (pfdset == NULL || idx >= MAX_FDS || fd >= FD_SETSIZE)
61 pfdentry = &pfdset->fd[idx];
71 @@ -150,12 +152,11 @@ fdset_add(struct fdset *pfdset, int fd,
73 /* Find a free slot in the list. */
74 i = fdset_find_free_slot(pfdset);
76 + if (i == -1 || fdset_add_fd(pfdset, i, fd, rcb, wcb, dat) < 0) {
77 pthread_mutex_unlock(&pfdset->fd_mutex);
81 - fdset_add_fd(pfdset, i, fd, rcb, wcb, dat);
84 pthread_mutex_unlock(&pfdset->fd_mutex);
85 Index: deb_dpdk/lib/librte_vhost/vhost_user/vhost-net-user.c
86 ===================================================================
87 --- deb_dpdk.orig/lib/librte_vhost/vhost_user/vhost-net-user.c
88 +++ deb_dpdk/lib/librte_vhost/vhost_user/vhost-net-user.c
89 @@ -257,6 +257,7 @@ vhost_user_add_connection(int fd, struct
92 struct vhost_user_connection *conn;
95 conn = malloc(sizeof(*conn));
97 @@ -278,7 +279,15 @@ vhost_user_add_connection(int fd, struct
99 conn->vsocket = vsocket;
101 - fdset_add(&vhost_user.fdset, fd, vhost_user_msg_handler, NULL, conn);
102 + ret = fdset_add(&vhost_user.fdset, fd, vhost_user_msg_handler,
107 + RTE_LOG(ERR, VHOST_CONFIG,
108 + "failed to add fd %d into vhost server fdset\n",
113 /* call back when there is new vhost-user connection from client */
114 @@ -469,8 +478,14 @@ vhost_user_create_server(struct vhost_us
117 vsocket->listenfd = fd;
118 - fdset_add(&vhost_user.fdset, fd, vhost_user_server_new_connection,
119 + ret = fdset_add(&vhost_user.fdset, fd, vhost_user_server_new_connection,
122 + RTE_LOG(ERR, VHOST_CONFIG,
123 + "failed to add listen fd %d to vhost server fdset\n",