droping upstreamed backports d/p/ubuntu-fix-bond-symbol-export.patch
[deb_dpdk.git] / debian / patches / ubuntu-backport-33-vhost-user-add-error-handling-for-fd-1023.patch
1 Description: backport of dpdk fix for LP: #1566874
2
3 Forwarded: n/a (already discussed upstream)
4 Author: Christian Ehrhardt <christian.ehrhardt@canonical.com>
5 Last-Update: 2016-06-06
6
7 Extended by Christian Ehrhardt <christian.ehrhardt@canonical.com>
8 Close fd on vserver->listenfd (Part of the upstream discussion)
9
10 Original:
11 From: Patrik Andersson <patrik.r.andersson@ericsson.com>
12
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.
16
17 Corrections would include:
18
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()
22
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
28 vswitch using DPDK.
29
30 A discussion topic exist in the ovs-discuss mailing list that can
31 provide a little more background:
32
33 http://openvswitch.org/pipermail/discuss/2016-February/020243.html
34
35 Signed-off-by: Patrik Andersson <patrik.r.andersson@ericsson.com>
36 ---
37  fd_man.c         |   11 ++++++-----
38  vhost-net-user.c |   23 +++++++++++++++++++++--
39  2 files changed, 27 insertions(+), 7 deletions(-)
40
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);
47  }
48  
49 -static void
50 +static int
51  fdset_add_fd(struct fdset  *pfdset, int idx, int fd,
52         fd_cb rcb, fd_cb wcb, void *dat)
53  {
54         struct fdentry *pfdentry;
55  
56 -       if (pfdset == NULL || idx >= MAX_FDS)
57 -               return;
58 +       if (pfdset == NULL || idx >= MAX_FDS || fd >= FD_SETSIZE)
59 +               return -1;
60  
61         pfdentry = &pfdset->fd[idx];
62         pfdentry->fd = fd;
63         pfdentry->rcb = rcb;
64         pfdentry->wcb = wcb;
65         pfdentry->dat = dat;
66 +
67 +       return 0;
68  }
69  
70  /**
71 @@ -150,12 +152,11 @@ fdset_add(struct fdset *pfdset, int fd,
72  
73         /* Find a free slot in the list. */
74         i = fdset_find_free_slot(pfdset);
75 -       if (i == -1) {
76 +       if (i == -1 || fdset_add_fd(pfdset, i, fd, rcb, wcb, dat) < 0) {
77                 pthread_mutex_unlock(&pfdset->fd_mutex);
78                 return -2;
79         }
80  
81 -       fdset_add_fd(pfdset, i, fd, rcb, wcb, dat);
82         pfdset->num++;
83  
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
90         int vid;
91         size_t size;
92         struct vhost_user_connection *conn;
93 +       int ret;
94  
95         conn = malloc(sizeof(*conn));
96         if (conn == NULL) {
97 @@ -278,7 +279,15 @@ vhost_user_add_connection(int fd, struct
98  
99         conn->vsocket = vsocket;
100         conn->vid = vid;
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,
103 +                       NULL, conn);
104 +       if (ret < 0) {
105 +               free(conn);
106 +               close(fd);
107 +               RTE_LOG(ERR, VHOST_CONFIG,
108 +                       "failed to add fd %d into vhost server fdset\n",
109 +                       fd);
110 +       }
111  }
112  
113  /* call back when there is new vhost-user connection from client  */
114 @@ -469,8 +478,14 @@ vhost_user_create_server(struct vhost_us
115                 goto err;
116  
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,
120                   NULL, vsocket);
121 +       if (ret < 0) {
122 +               RTE_LOG(ERR, VHOST_CONFIG,
123 +                       "failed to add listen fd %d to vhost server fdset\n",
124 +                       fd);
125 +               goto err;
126 +       }
127  
128         return 0;
129