Gentoo Archives: gentoo-commits

From: Matthias Maier <tamiko@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: app-emulation/qemu/, app-emulation/qemu/files/
Date: Wed, 26 Oct 2016 21:48:35
Message-Id: 1477518501.5a981e9d23127c779dc8ecb1d05ef08fe4d3a011.tamiko@gentoo
1 commit: 5a981e9d23127c779dc8ecb1d05ef08fe4d3a011
2 Author: Matthias Maier <tamiko <AT> gentoo <DOT> org>
3 AuthorDate: Wed Oct 26 21:47:50 2016 +0000
4 Commit: Matthias Maier <tamiko <AT> gentoo <DOT> org>
5 CommitDate: Wed Oct 26 21:48:21 2016 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5a981e9d
7
8 app-emulation/qemu: multiple security fixes for 2.7.0-r5
9
10 CVE-2016-7466, bug 594520
11 CVE-2016-7907, bug 596048
12 CVE-2016-7908, bug 596049
13 CVE-2016-7909, bug 596048
14 CVE-2016-7994, bug 596738
15 CVE-2016-7994, bug 596738
16 CVE-2016-8576, bug 596752
17 CVE-2016-8577, bug 596776
18 CVE-2016-8578, bug 596774
19 CVE-2016-8668, bug 597110
20 CVE-2016-8669, bug 597108
21 CVE-2016-8669, bug 597108
22 CVE-2016-8909, bug 598044
23 CVE-2016-8910, bug 598046
24
25 Package-Manager: portage-2.3.0
26
27 .../qemu/files/qemu-2.7.0-CVE-2016-7907.patch | 45 ++
28 .../qemu/files/qemu-2.7.0-CVE-2016-7908.patch | 52 ++
29 .../qemu/files/qemu-2.7.0-CVE-2016-7909.patch | 32 +
30 .../qemu/files/qemu-2.7.0-CVE-2016-7994-1.patch | 25 +
31 .../qemu/files/qemu-2.7.0-CVE-2016-7994-2.patch | 26 +
32 .../qemu/files/qemu-2.7.0-CVE-2016-8576.patch | 61 ++
33 .../qemu/files/qemu-2.7.0-CVE-2016-8577.patch | 34 +
34 .../qemu/files/qemu-2.7.0-CVE-2016-8578.patch | 58 ++
35 .../qemu/files/qemu-2.7.0-CVE-2016-8668.patch | 30 +
36 .../qemu/files/qemu-2.7.0-CVE-2016-8669-1.patch | 29 +
37 .../qemu/files/qemu-2.7.0-CVE-2016-8669-2.patch | 34 +
38 .../qemu/files/qemu-2.7.0-CVE-2016-8909.patch | 31 +
39 .../qemu/files/qemu-2.7.0-CVE-2016-8910.patch | 29 +
40 app-emulation/qemu/qemu-2.7.0-r5.ebuild | 703 +++++++++++++++++++++
41 14 files changed, 1189 insertions(+)
42
43 diff --git a/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7907.patch b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7907.patch
44 new file mode 100644
45 index 00000000..34b095a
46 --- /dev/null
47 +++ b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7907.patch
48 @@ -0,0 +1,45 @@
49 +From: Prasad J Pandit <address@hidden>
50 +
51 +i.MX Fast Ethernet Controller uses buffer descriptors to manage
52 +data flow to/fro receive & transmit queues. While transmitting
53 +packets, it could continue to read buffer descriptors if a buffer
54 +descriptor has length of zero and has crafted values in bd.flags.
55 +Set an upper limit to number of buffer descriptors.
56 +
57 +Reported-by: Li Qiang <address@hidden>
58 +Signed-off-by: Prasad J Pandit <address@hidden>
59 +---
60 + hw/net/imx_fec.c | 6 ++++--
61 + 1 file changed, 4 insertions(+), 2 deletions(-)
62 +
63 +Update per
64 + -> https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg05284.html
65 +
66 +diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c
67 +index 1c415ab..1d74827 100644
68 +--- a/hw/net/imx_fec.c
69 ++++ b/hw/net/imx_fec.c
70 +@@ -220,6 +220,8 @@ static const VMStateDescription vmstate_imx_eth = {
71 + #define PHY_INT_PARFAULT (1 << 2)
72 + #define PHY_INT_AUTONEG_PAGE (1 << 1)
73 +
74 ++#define IMX_MAX_DESC 1024
75 ++
76 + static void imx_eth_update(IMXFECState *s);
77 +
78 + /*
79 +@@ -402,12 +404,12 @@ static void imx_eth_update(IMXFECState *s)
80 +
81 + static void imx_fec_do_tx(IMXFECState *s)
82 + {
83 +- int frame_size = 0;
84 ++ int frame_size = 0, descnt = 0;
85 + uint8_t frame[ENET_MAX_FRAME_SIZE];
86 + uint8_t *ptr = frame;
87 + uint32_t addr = s->tx_descriptor;
88 +
89 +- while (1) {
90 ++ while (descnt++ < IMX_MAX_DESC) {
91 + IMXFECBufDesc bd;
92 + int len;
93 +
94
95 diff --git a/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7908.patch b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7908.patch
96 new file mode 100644
97 index 00000000..16d072f
98 --- /dev/null
99 +++ b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7908.patch
100 @@ -0,0 +1,52 @@
101 +From 070c4b92b8cd5390889716677a0b92444d6e087a Mon Sep 17 00:00:00 2001
102 +From: Prasad J Pandit <pjp@×××××××××××××.org>
103 +Date: Thu, 22 Sep 2016 16:02:37 +0530
104 +Subject: [PATCH] net: mcf: limit buffer descriptor count
105 +
106 +ColdFire Fast Ethernet Controller uses buffer descriptors to manage
107 +data flow to/fro receive & transmit queues. While transmitting
108 +packets, it could continue to read buffer descriptors if a buffer
109 +descriptor has length of zero and has crafted values in bd.flags.
110 +Set upper limit to number of buffer descriptors.
111 +
112 +Reported-by: Li Qiang <liqiang6-s@×××.cn>
113 +Signed-off-by: Prasad J Pandit <pjp@×××××××××××××.org>
114 +Reviewed-by: Paolo Bonzini <pbonzini@××××××.com>
115 +Signed-off-by: Jason Wang <jasowang@××××××.com>
116 +---
117 + hw/net/mcf_fec.c | 5 +++--
118 + 1 files changed, 3 insertions(+), 2 deletions(-)
119 +
120 +diff --git a/hw/net/mcf_fec.c b/hw/net/mcf_fec.c
121 +index 0ee8ad9..d31fea1 100644
122 +--- a/hw/net/mcf_fec.c
123 ++++ b/hw/net/mcf_fec.c
124 +@@ -23,6 +23,7 @@ do { printf("mcf_fec: " fmt , ## __VA_ARGS__); } while (0)
125 + #define DPRINTF(fmt, ...) do {} while(0)
126 + #endif
127 +
128 ++#define FEC_MAX_DESC 1024
129 + #define FEC_MAX_FRAME_SIZE 2032
130 +
131 + typedef struct {
132 +@@ -149,7 +150,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s)
133 + uint32_t addr;
134 + mcf_fec_bd bd;
135 + int frame_size;
136 +- int len;
137 ++ int len, descnt = 0;
138 + uint8_t frame[FEC_MAX_FRAME_SIZE];
139 + uint8_t *ptr;
140 +
141 +@@ -157,7 +158,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s)
142 + ptr = frame;
143 + frame_size = 0;
144 + addr = s->tx_descriptor;
145 +- while (1) {
146 ++ while (descnt++ < FEC_MAX_DESC) {
147 + mcf_fec_read_bd(&bd, addr);
148 + DPRINTF("tx_bd %x flags %04x len %d data %08x\n",
149 + addr, bd.flags, bd.length, bd.data);
150 +--
151 +1.7.0.4
152 +
153
154 diff --git a/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7909.patch b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7909.patch
155 new file mode 100644
156 index 00000000..8e6ecff
157 --- /dev/null
158 +++ b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7909.patch
159 @@ -0,0 +1,32 @@
160 +From: Prasad J Pandit <address@hidden>
161 +
162 +The AMD PC-Net II emulator has set of control and status(CSR)
163 +registers. Of these, CSR76 and CSR78 hold receive and transmit
164 +descriptor ring length respectively. This ring length could range
165 +from 1 to 65535. Setting ring length to zero leads to an infinite
166 +loop in pcnet_rdra_addr. Add check to avoid it.
167 +
168 +Reported-by: Li Qiang <address@hidden>
169 +Signed-off-by: Prasad J Pandit <address@hidden>
170 +---
171 + hw/net/pcnet.c | 3 +++
172 + 1 file changed, 3 insertions(+)
173 +
174 +diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c
175 +index 198a01f..3078de8 100644
176 +--- a/hw/net/pcnet.c
177 ++++ b/hw/net/pcnet.c
178 +@@ -1429,8 +1429,11 @@ static void pcnet_csr_writew(PCNetState *s, uint32_t rap, uint32_t new_value)
179 + case 47: /* POLLINT */
180 + case 72:
181 + case 74:
182 ++ break;
183 + case 76: /* RCVRL */
184 + case 78: /* XMTRL */
185 ++ val = (val > 0) ? val : 512;
186 ++ break;
187 + case 112:
188 + if (CSR_STOP(s) || CSR_SPND(s))
189 + break;
190 +--
191 +2.5.5
192
193 diff --git a/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7994-1.patch b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7994-1.patch
194 new file mode 100644
195 index 00000000..6fe77f3
196 --- /dev/null
197 +++ b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7994-1.patch
198 @@ -0,0 +1,25 @@
199 +From: Li Qiang <address@hidden>
200 +
201 +In virtio gpu resource create dispatch, if the pixman format is zero
202 +it doesn't free the resource object allocated previously. Thus leading
203 +a host memory leak issue. This patch avoid this.
204 +
205 +Signed-off-by: Li Qiang <address@hidden>
206 +---
207 + hw/display/virtio-gpu.c | 1 +
208 + 1 file changed, 1 insertion(+)
209 +
210 +diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
211 +index 7fe6ed8..5b6d17b 100644
212 +--- a/hw/display/virtio-gpu.c
213 ++++ b/hw/display/virtio-gpu.c
214 +@@ -333,6 +333,7 @@ static void virtio_gpu_resource_create_2d(VirtIOGPU *g,
215 + qemu_log_mask(LOG_GUEST_ERROR,
216 + "%s: host couldn't handle guest format %d\n",
217 + __func__, c2d.format);
218 ++ g_free(res);
219 + cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
220 + return;
221 + }
222 +--
223 +1.8.3.1
224
225 diff --git a/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7994-2.patch b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7994-2.patch
226 new file mode 100644
227 index 00000000..dce1b2b
228 --- /dev/null
229 +++ b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-7994-2.patch
230 @@ -0,0 +1,26 @@
231 +From: Li Qiang <address@hidden>
232 +
233 +While processing isochronous transfer descriptors(iTD), if the page
234 +select(PG) field value is out of bands it will return. In this
235 +situation the ehci's sg list doesn't be freed thus leading a memory
236 +leak issue. This patch avoid this.
237 +
238 +Signed-off-by: Li Qiang <address@hidden>
239 +---
240 + hw/usb/hcd-ehci.c | 1 +
241 + 1 file changed, 1 insertion(+)
242 +
243 +diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
244 +index b093db7..f4ece9a 100644
245 +--- a/hw/usb/hcd-ehci.c
246 ++++ b/hw/usb/hcd-ehci.c
247 +@@ -1426,6 +1426,7 @@ static int ehci_process_itd(EHCIState *ehci,
248 + if (off + len > 4096) {
249 + /* transfer crosses page border */
250 + if (pg == 6) {
251 ++ qemu_sglist_destroy(&ehci->isgl);
252 + return -1; /* avoid page pg + 1 */
253 + }
254 + ptr2 = (itd->bufptr[pg + 1] & ITD_BUFPTR_MASK);
255 +--
256 +1.8.3.1
257
258 diff --git a/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8576.patch b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8576.patch
259 new file mode 100644
260 index 00000000..9617cd5
261 --- /dev/null
262 +++ b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8576.patch
263 @@ -0,0 +1,61 @@
264 +From 20009bdaf95d10bf748fa69b104672d3cfaceddf Mon Sep 17 00:00:00 2001
265 +From: Gerd Hoffmann <address@hidden>
266 +Date: Fri, 7 Oct 2016 10:15:29 +0200
267 +Subject: [PATCH] xhci: limit the number of link trbs we are willing to process
268 +
269 +Signed-off-by: Gerd Hoffmann <address@hidden>
270 +---
271 + hw/usb/hcd-xhci.c | 10 ++++++++++
272 + 1 file changed, 10 insertions(+)
273 +
274 +diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
275 +index 726435c..ee4fa48 100644
276 +--- a/hw/usb/hcd-xhci.c
277 ++++ b/hw/usb/hcd-xhci.c
278 +@@ -54,6 +54,8 @@
279 + * to the specs when it gets them */
280 + #define ER_FULL_HACK
281 +
282 ++#define TRB_LINK_LIMIT 4
283 ++
284 + #define LEN_CAP 0x40
285 + #define LEN_OPER (0x400 + 0x10 * MAXPORTS)
286 + #define LEN_RUNTIME ((MAXINTRS + 1) * 0x20)
287 +@@ -1000,6 +1002,7 @@ static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB *trb,
288 + dma_addr_t *addr)
289 + {
290 + PCIDevice *pci_dev = PCI_DEVICE(xhci);
291 ++ uint32_t link_cnt = 0;
292 +
293 + while (1) {
294 + TRBType type;
295 +@@ -1026,6 +1029,9 @@ static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB *trb,
296 + ring->dequeue += TRB_SIZE;
297 + return type;
298 + } else {
299 ++ if (++link_cnt > TRB_LINK_LIMIT) {
300 ++ return 0;
301 ++ }
302 + ring->dequeue = xhci_mask64(trb->parameter);
303 + if (trb->control & TRB_LK_TC) {
304 + ring->ccs = !ring->ccs;
305 +@@ -1043,6 +1049,7 @@ static int xhci_ring_chain_length(XHCIState *xhci, const XHCIRing *ring)
306 + bool ccs = ring->ccs;
307 + /* hack to bundle together the two/three TDs that make a setup transfer */
308 + bool control_td_set = 0;
309 ++ uint32_t link_cnt = 0;
310 +
311 + while (1) {
312 + TRBType type;
313 +@@ -1058,6 +1065,9 @@ static int xhci_ring_chain_length(XHCIState *xhci, const XHCIRing *ring)
314 + type = TRB_TYPE(trb);
315 +
316 + if (type == TR_LINK) {
317 ++ if (++link_cnt > TRB_LINK_LIMIT) {
318 ++ return -length;
319 ++ }
320 + dequeue = xhci_mask64(trb.parameter);
321 + if (trb.control & TRB_LK_TC) {
322 + ccs = !ccs;
323 +--
324 +1.8.3.1
325
326 diff --git a/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8577.patch b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8577.patch
327 new file mode 100644
328 index 00000000..8c29580
329 --- /dev/null
330 +++ b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8577.patch
331 @@ -0,0 +1,34 @@
332 +From: Li Qiang <address@hidden>
333 +
334 +In 9pfs read dispatch function, it doesn't free two QEMUIOVector
335 +object thus causing potential memory leak. This patch avoid this.
336 +
337 +Signed-off-by: Li Qiang <address@hidden>
338 +---
339 + hw/9pfs/9p.c | 5 +++--
340 + 1 file changed, 3 insertions(+), 2 deletions(-)
341 +
342 +diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
343 +index 119ee58..543a791 100644
344 +--- a/hw/9pfs/9p.c
345 ++++ b/hw/9pfs/9p.c
346 +@@ -1826,14 +1826,15 @@ static void v9fs_read(void *opaque)
347 + if (len < 0) {
348 + /* IO error return the error */
349 + err = len;
350 +- goto out;
351 ++ goto out_free_iovec;
352 + }
353 + } while (count < max_count && len > 0);
354 + err = pdu_marshal(pdu, offset, "d", count);
355 + if (err < 0) {
356 +- goto out;
357 ++ goto out_free_iovec;
358 + }
359 + err += offset + count;
360 ++out_free_iovec:
361 + qemu_iovec_destroy(&qiov);
362 + qemu_iovec_destroy(&qiov_full);
363 + } else if (fidp->fid_type == P9_FID_XATTR) {
364 +--
365 +1.8.3.1
366
367 diff --git a/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8578.patch b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8578.patch
368 new file mode 100644
369 index 00000000..74eee7e
370 --- /dev/null
371 +++ b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8578.patch
372 @@ -0,0 +1,58 @@
373 +From ba42ebb863ab7d40adc79298422ed9596df8f73a Mon Sep 17 00:00:00 2001
374 +From: Li Qiang <liqiang6-s@×××.cn>
375 +Date: Mon, 17 Oct 2016 14:13:58 +0200
376 +Subject: [PATCH] 9pfs: allocate space for guest originated empty strings
377 +
378 +If a guest sends an empty string paramater to any 9P operation, the current
379 +code unmarshals it into a V9fsString equal to { .size = 0, .data = NULL }.
380 +
381 +This is unfortunate because it can cause NULL pointer dereference to happen
382 +at various locations in the 9pfs code. And we don't want to check str->data
383 +everywhere we pass it to strcmp() or any other function which expects a
384 +dereferenceable pointer.
385 +
386 +This patch enforces the allocation of genuine C empty strings instead, so
387 +callers don't have to bother.
388 +
389 +Out of all v9fs_iov_vunmarshal() users, only v9fs_xattrwalk() checks if
390 +the returned string is empty. It now uses v9fs_string_size() since
391 +name.data cannot be NULL anymore.
392 +
393 +Signed-off-by: Li Qiang <liqiang6-s@×××.cn>
394 +[groug, rewritten title and changelog,
395 + fix empty string check in v9fs_xattrwalk()]
396 +Signed-off-by: Greg Kurz <groug@××××.org>
397 +---
398 + fsdev/9p-iov-marshal.c | 2 +-
399 + hw/9pfs/9p.c | 2 +-
400 + 2 files changed, 2 insertions(+), 2 deletions(-)
401 +
402 +diff --git a/fsdev/9p-iov-marshal.c b/fsdev/9p-iov-marshal.c
403 +index 663cad5..1d16f8d 100644
404 +--- a/fsdev/9p-iov-marshal.c
405 ++++ b/fsdev/9p-iov-marshal.c
406 +@@ -125,7 +125,7 @@ ssize_t v9fs_iov_vunmarshal(struct iovec *out_sg, int out_num, size_t offset,
407 + str->data = g_malloc(str->size + 1);
408 + copied = v9fs_unpack(str->data, out_sg, out_num, offset,
409 + str->size);
410 +- if (copied > 0) {
411 ++ if (copied >= 0) {
412 + str->data[str->size] = 0;
413 + } else {
414 + v9fs_string_free(str);
415 +diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
416 +index 119ee58..39a7e1d 100644
417 +--- a/hw/9pfs/9p.c
418 ++++ b/hw/9pfs/9p.c
419 +@@ -3174,7 +3174,7 @@ static void v9fs_xattrwalk(void *opaque)
420 + goto out;
421 + }
422 + v9fs_path_copy(&xattr_fidp->path, &file_fidp->path);
423 +- if (name.data == NULL) {
424 ++ if (!v9fs_string_size(&name)) {
425 + /*
426 + * listxattr request. Get the size first
427 + */
428 +--
429 +2.7.3
430 +
431
432 diff --git a/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8668.patch b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8668.patch
433 new file mode 100644
434 index 00000000..a27d3a6
435 --- /dev/null
436 +++ b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8668.patch
437 @@ -0,0 +1,30 @@
438 +From: Prasad J Pandit <address@hidden>
439 +
440 +Rocker network switch emulator has test registers to help debug
441 +DMA operations. While testing host DMA access, a buffer address
442 +is written to register 'TEST_DMA_ADDR' and its size is written to
443 +register 'TEST_DMA_SIZE'. When performing TEST_DMA_CTRL_INVERT
444 +test, if DMA buffer size was greater than 'INT_MAX', it leads to
445 +an invalid buffer access. Limit the DMA buffer size to avoid it.
446 +
447 +Reported-by: Huawei PSIRT <address@hidden>
448 +Signed-off-by: Prasad J Pandit <address@hidden>
449 +---
450 + hw/net/rocker/rocker.c | 2 +-
451 + 1 file changed, 1 insertion(+), 1 deletion(-)
452 +
453 +diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
454 +index 30f2ce4..e9d215a 100644
455 +--- a/hw/net/rocker/rocker.c
456 ++++ b/hw/net/rocker/rocker.c
457 +@@ -860,7 +860,7 @@ static void rocker_io_writel(void *opaque, hwaddr addr, uint32_t val)
458 + rocker_msix_irq(r, val);
459 + break;
460 + case ROCKER_TEST_DMA_SIZE:
461 +- r->test_dma_size = val;
462 ++ r->test_dma_size = val & 0xFFFF;
463 + break;
464 + case ROCKER_TEST_DMA_ADDR + 4:
465 + r->test_dma_addr = ((uint64_t)val) << 32 | r->lower32;
466 +--
467 +2.5.5
468
469 diff --git a/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8669-1.patch b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8669-1.patch
470 new file mode 100644
471 index 00000000..457f022
472 --- /dev/null
473 +++ b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8669-1.patch
474 @@ -0,0 +1,29 @@
475 +From: Prasad J Pandit <address@hidden>
476 +
477 +The JAZZ RC4030 chipset emulator has a periodic timer and
478 +associated interval reload register. The reload value is used
479 +as divider when computing timer's next tick value. If reload
480 +value is large, it could lead to divide by zero error. Limit
481 +the interval reload value to avoid it.
482 +
483 +Reported-by: Huawei PSIRT <address@hidden>
484 +Signed-off-by: Prasad J Pandit <address@hidden>
485 +---
486 + hw/dma/rc4030.c | 2 +-
487 + 1 file changed, 1 insertion(+), 1 deletion(-)
488 +
489 +diff --git a/hw/dma/rc4030.c b/hw/dma/rc4030.c
490 +index 2f2576f..c1b4997 100644
491 +--- a/hw/dma/rc4030.c
492 ++++ b/hw/dma/rc4030.c
493 +@@ -460,7 +460,7 @@ static void rc4030_write(void *opaque, hwaddr addr, uint64_t data,
494 + break;
495 + /* Interval timer reload */
496 + case 0x0228:
497 +- s->itr = val;
498 ++ s->itr = val & 0x01FF;
499 + qemu_irq_lower(s->timer_irq);
500 + set_next_tick(s);
501 + break;
502 +--
503 +2.5.5
504
505 diff --git a/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8669-2.patch b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8669-2.patch
506 new file mode 100644
507 index 00000000..23393b7
508 --- /dev/null
509 +++ b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8669-2.patch
510 @@ -0,0 +1,34 @@
511 +From: Prasad J Pandit <address@hidden>
512 +
513 +16550A UART device uses an oscillator to generate frequencies
514 +(baud base), which decide communication speed. This speed could
515 +be changed by dividing it by a divider. If the divider is
516 +greater than the baud base, speed is set to zero, leading to a
517 +divide by zero error. Add check to avoid it.
518 +
519 +Reported-by: Huawei PSIRT <address@hidden>
520 +Signed-off-by: Prasad J Pandit <address@hidden>
521 +---
522 + hw/char/serial.c | 3 ++-
523 + 1 file changed, 2 insertions(+), 1 deletion(-)
524 +
525 +Update per
526 + -> https://lists.gnu.org/archive/html/qemu-devel/2016-10/msg02400.html
527 +
528 +diff --git a/hw/char/serial.c b/hw/char/serial.c
529 +index 3442f47..eec72b7 100644
530 +--- a/hw/char/serial.c
531 ++++ b/hw/char/serial.c
532 +@@ -153,8 +153,9 @@ static void serial_update_parameters(SerialState *s)
533 + int speed, parity, data_bits, stop_bits, frame_size;
534 + QEMUSerialSetParams ssp;
535 +
536 +- if (s->divider == 0)
537 ++ if (s->divider == 0 || s->divider > s->baudbase) {
538 + return;
539 ++ }
540 +
541 + /* Start bit. */
542 + frame_size = 1;
543 +--
544 +2.5.5
545
546 diff --git a/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8909.patch b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8909.patch
547 new file mode 100644
548 index 00000000..ed6613f
549 --- /dev/null
550 +++ b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8909.patch
551 @@ -0,0 +1,31 @@
552 +From: Prasad J Pandit <address@hidden>
553 +
554 +Intel HDA emulator uses stream of buffers during DMA data
555 +transfers. Each entry has buffer length and buffer pointer
556 +position, which are used to derive bytes to 'copy'. If this
557 +length and buffer pointer were to be same, 'copy' could be
558 +set to zero(0), leading to an infinite loop. Add check to
559 +avoid it.
560 +
561 +Reported-by: Huawei PSIRT <address@hidden>
562 +Signed-off-by: Prasad J Pandit <address@hidden>
563 +---
564 + hw/audio/intel-hda.c | 3 ++-
565 + 1 file changed, 2 insertions(+), 1 deletion(-)
566 +
567 +diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
568 +index cd95340..537face 100644
569 +--- a/hw/audio/intel-hda.c
570 ++++ b/hw/audio/intel-hda.c
571 +@@ -416,7 +416,8 @@ static bool intel_hda_xfer(HDACodecDevice *dev, uint32_t stnr, bool output,
572 + }
573 +
574 + left = len;
575 +- while (left > 0) {
576 ++ s = st->bentries;
577 ++ while (left > 0 && s-- > 0) {
578 + copy = left;
579 + if (copy > st->bsize - st->lpib)
580 + copy = st->bsize - st->lpib;
581 +--
582 +2.7.4
583
584 diff --git a/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8910.patch b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8910.patch
585 new file mode 100644
586 index 00000000..c93f796
587 --- /dev/null
588 +++ b/app-emulation/qemu/files/qemu-2.7.0-CVE-2016-8910.patch
589 @@ -0,0 +1,29 @@
590 +From: Prasad J Pandit <address@hidden>
591 +
592 +RTL8139 ethernet controller in C+ mode supports multiple
593 +descriptor rings, each with maximum of 64 descriptors. While
594 +processing transmit descriptor ring in 'rtl8139_cplus_transmit',
595 +it does not limit the descriptor count and runs forever. Add
596 +check to avoid it.
597 +
598 +Reported-by: Andrew Henderson <address@hidden>
599 +Signed-off-by: Prasad J Pandit <address@hidden>
600 +---
601 + hw/net/rtl8139.c | 2 +-
602 + 1 file changed, 1 insertion(+), 1 deletion(-)
603 +
604 +diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
605 +index 3345bc6..f05e59c 100644
606 +--- a/hw/net/rtl8139.c
607 ++++ b/hw/net/rtl8139.c
608 +@@ -2350,7 +2350,7 @@ static void rtl8139_cplus_transmit(RTL8139State *s)
609 + {
610 + int txcount = 0;
611 +
612 +- while (rtl8139_cplus_transmit_one(s))
613 ++ while (txcount < 64 && rtl8139_cplus_transmit_one(s))
614 + {
615 + ++txcount;
616 + }
617 +--
618 +2.7.4
619
620 diff --git a/app-emulation/qemu/qemu-2.7.0-r5.ebuild b/app-emulation/qemu/qemu-2.7.0-r5.ebuild
621 new file mode 100644
622 index 00000000..cece751
623 --- /dev/null
624 +++ b/app-emulation/qemu/qemu-2.7.0-r5.ebuild
625 @@ -0,0 +1,703 @@
626 +# Copyright 1999-2016 Gentoo Foundation
627 +# Distributed under the terms of the GNU General Public License v2
628 +# $Id$
629 +
630 +EAPI="5"
631 +
632 +PYTHON_COMPAT=( python2_7 )
633 +PYTHON_REQ_USE="ncurses,readline"
634 +
635 +PLOCALES="bg de_DE fr_FR hu it tr zh_CN"
636 +
637 +inherit eutils flag-o-matic linux-info toolchain-funcs multilib python-r1 \
638 + user udev fcaps readme.gentoo-r1 pax-utils l10n
639 +
640 +if [[ ${PV} = *9999* ]]; then
641 + EGIT_REPO_URI="git://git.qemu.org/qemu.git"
642 + inherit git-2
643 + SRC_URI=""
644 +else
645 + SRC_URI="http://wiki.qemu-project.org/download/${P}.tar.bz2"
646 + KEYWORDS="~amd64 ~arm64 ~ppc ~ppc64 ~x86 ~x86-fbsd"
647 +fi
648 +
649 +DESCRIPTION="QEMU + Kernel-based Virtual Machine userland tools"
650 +HOMEPAGE="http://www.qemu.org http://www.linux-kvm.org"
651 +
652 +LICENSE="GPL-2 LGPL-2 BSD-2"
653 +SLOT="0"
654 +IUSE="accessibility +aio alsa bluetooth bzip2 +caps +curl debug +fdt glusterfs \
655 +gnutls gtk gtk2 infiniband iscsi +jpeg \
656 +kernel_linux kernel_FreeBSD lzo ncurses nfs nls numa opengl +pin-upstream-blobs
657 ++png pulseaudio python \
658 +rbd sasl +seccomp sdl sdl2 selinux smartcard snappy spice ssh static static-softmmu
659 +static-user systemtap tci test +threads usb usbredir +uuid vde +vhost-net \
660 +virgl virtfs +vnc vte xattr xen xfs"
661 +
662 +COMMON_TARGETS="aarch64 alpha arm cris i386 m68k microblaze microblazeel mips
663 +mips64 mips64el mipsel or32 ppc ppc64 s390x sh4 sh4eb sparc sparc64 unicore32
664 +x86_64"
665 +IUSE_SOFTMMU_TARGETS="${COMMON_TARGETS} lm32 moxie ppcemb tricore xtensa xtensaeb"
666 +IUSE_USER_TARGETS="${COMMON_TARGETS} armeb mipsn32 mipsn32el ppc64abi32 ppc64le sparc32plus tilegx"
667 +
668 +use_softmmu_targets=$(printf ' qemu_softmmu_targets_%s' ${IUSE_SOFTMMU_TARGETS})
669 +use_user_targets=$(printf ' qemu_user_targets_%s' ${IUSE_USER_TARGETS})
670 +IUSE+=" ${use_softmmu_targets} ${use_user_targets}"
671 +
672 +# Allow no targets to be built so that people can get a tools-only build.
673 +# Block USE flag configurations known to not work.
674 +REQUIRED_USE="${PYTHON_REQUIRED_USE}
675 + gtk2? ( gtk )
676 + qemu_softmmu_targets_arm? ( fdt )
677 + qemu_softmmu_targets_microblaze? ( fdt )
678 + qemu_softmmu_targets_ppc? ( fdt )
679 + qemu_softmmu_targets_ppc64? ( fdt )
680 + sdl2? ( sdl )
681 + static? ( static-softmmu static-user )
682 + static-softmmu? ( !alsa !pulseaudio !bluetooth !opengl !gtk !gtk2 )
683 + virtfs? ( xattr )
684 + vte? ( gtk )"
685 +
686 +# Yep, you need both libcap and libcap-ng since virtfs only uses libcap.
687 +#
688 +# The attr lib isn't always linked in (although the USE flag is always
689 +# respected). This is because qemu supports using the C library's API
690 +# when available rather than always using the extranl library.
691 +#
692 +# Older versions of gnutls are supported, but it's simpler to just require
693 +# the latest versions. This is also why we require nettle.
694 +#
695 +# TODO: Split out tools deps into another var. e.g. bzip2 is only used by
696 +# system binaries and tools, not user binaries.
697 +COMMON_LIB_DEPEND=">=dev-libs/glib-2.0[static-libs(+)]
698 + dev-libs/libpcre[static-libs(+)]
699 + sys-libs/zlib[static-libs(+)]
700 + bzip2? ( app-arch/bzip2[static-libs(+)] )
701 + xattr? ( sys-apps/attr[static-libs(+)] )"
702 +SOFTMMU_LIB_DEPEND="${COMMON_LIB_DEPEND}
703 + >=x11-libs/pixman-0.28.0[static-libs(+)]
704 + accessibility? ( app-accessibility/brltty[static-libs(+)] )
705 + aio? ( dev-libs/libaio[static-libs(+)] )
706 + alsa? ( >=media-libs/alsa-lib-1.0.13 )
707 + bluetooth? ( net-wireless/bluez )
708 + caps? ( sys-libs/libcap-ng[static-libs(+)] )
709 + curl? ( >=net-misc/curl-7.15.4[static-libs(+)] )
710 + fdt? ( >=sys-apps/dtc-1.4.0[static-libs(+)] )
711 + glusterfs? ( >=sys-cluster/glusterfs-3.4.0[static-libs(+)] )
712 + gnutls? (
713 + dev-libs/nettle:=[static-libs(+)]
714 + >=net-libs/gnutls-3.0:=[static-libs(+)]
715 + )
716 + gtk? (
717 + gtk2? (
718 + x11-libs/gtk+:2
719 + vte? ( x11-libs/vte:0 )
720 + )
721 + !gtk2? (
722 + x11-libs/gtk+:3
723 + vte? ( x11-libs/vte:2.90 )
724 + )
725 + )
726 + infiniband? ( sys-fabric/librdmacm:=[static-libs(+)] )
727 + iscsi? ( net-libs/libiscsi )
728 + jpeg? ( virtual/jpeg:0=[static-libs(+)] )
729 + lzo? ( dev-libs/lzo:2[static-libs(+)] )
730 + ncurses? ( sys-libs/ncurses:0=[static-libs(+)] )
731 + nfs? ( >=net-fs/libnfs-1.9.3[static-libs(+)] )
732 + numa? ( sys-process/numactl[static-libs(+)] )
733 + opengl? (
734 + virtual/opengl
735 + media-libs/libepoxy[static-libs(+)]
736 + media-libs/mesa[static-libs(+)]
737 + media-libs/mesa[egl,gles2,gbm]
738 + )
739 + png? ( media-libs/libpng:0=[static-libs(+)] )
740 + pulseaudio? ( media-sound/pulseaudio )
741 + rbd? ( sys-cluster/ceph[static-libs(+)] )
742 + sasl? ( dev-libs/cyrus-sasl[static-libs(+)] )
743 + sdl? (
744 + !sdl2? (
745 + media-libs/libsdl[X]
746 + >=media-libs/libsdl-1.2.11[static-libs(+)]
747 + )
748 + sdl2? (
749 + media-libs/libsdl2[X]
750 + media-libs/libsdl2[static-libs(+)]
751 + )
752 + )
753 + seccomp? ( >=sys-libs/libseccomp-2.1.0[static-libs(+)] )
754 + smartcard? ( >=app-emulation/libcacard-2.5.0[static-libs(+)] )
755 + snappy? ( app-arch/snappy[static-libs(+)] )
756 + spice? (
757 + >=app-emulation/spice-protocol-0.12.3
758 + >=app-emulation/spice-0.12.0[static-libs(+)]
759 + )
760 + ssh? ( >=net-libs/libssh2-1.2.8[static-libs(+)] )
761 + usb? ( >=virtual/libusb-1-r2[static-libs(+)] )
762 + usbredir? ( >=sys-apps/usbredir-0.6[static-libs(+)] )
763 + uuid? ( >=sys-apps/util-linux-2.16.0[static-libs(+)] )
764 + vde? ( net-misc/vde[static-libs(+)] )
765 + virgl? ( media-libs/virglrenderer[static-libs(+)] )
766 + virtfs? ( sys-libs/libcap )
767 + xfs? ( sys-fs/xfsprogs[static-libs(+)] )"
768 +USER_LIB_DEPEND="${COMMON_LIB_DEPEND}"
769 +X86_FIRMWARE_DEPEND="
770 + >=sys-firmware/ipxe-1.0.0_p20130624
771 + pin-upstream-blobs? (
772 + ~sys-firmware/seabios-1.8.2
773 + ~sys-firmware/sgabios-0.1_pre8
774 + ~sys-firmware/vgabios-0.7a
775 + )
776 + !pin-upstream-blobs? (
777 + sys-firmware/seabios
778 + sys-firmware/sgabios
779 + sys-firmware/vgabios
780 + )"
781 +CDEPEND="
782 + !static-softmmu? ( $(printf "%s? ( ${SOFTMMU_LIB_DEPEND//\[static-libs(+)]} ) " ${use_softmmu_targets}) )
783 + !static-user? ( $(printf "%s? ( ${USER_LIB_DEPEND//\[static-libs(+)]} ) " ${use_user_targets}) )
784 + qemu_softmmu_targets_i386? ( ${X86_FIRMWARE_DEPEND} )
785 + qemu_softmmu_targets_x86_64? ( ${X86_FIRMWARE_DEPEND} )
786 + python? ( ${PYTHON_DEPS} )
787 + systemtap? ( dev-util/systemtap )
788 + xen? ( app-emulation/xen-tools:= )"
789 +DEPEND="${CDEPEND}
790 + dev-lang/perl
791 + =dev-lang/python-2*
792 + sys-apps/texinfo
793 + virtual/pkgconfig
794 + kernel_linux? ( >=sys-kernel/linux-headers-2.6.35 )
795 + gtk? ( nls? ( sys-devel/gettext ) )
796 + static-softmmu? ( $(printf "%s? ( ${SOFTMMU_LIB_DEPEND} ) " ${use_softmmu_targets}) )
797 + static-user? ( $(printf "%s? ( ${USER_LIB_DEPEND} ) " ${use_user_targets}) )
798 + test? (
799 + dev-libs/glib[utils]
800 + sys-devel/bc
801 + )"
802 +RDEPEND="${CDEPEND}
803 + selinux? ( sec-policy/selinux-qemu )
804 +"
805 +
806 +STRIP_MASK="/usr/share/qemu/palcode-clipper"
807 +
808 +QA_PREBUILT="
809 + usr/share/qemu/openbios-ppc
810 + usr/share/qemu/openbios-sparc64
811 + usr/share/qemu/openbios-sparc32
812 + usr/share/qemu/palcode-clipper
813 + usr/share/qemu/s390-ccw.img
814 + usr/share/qemu/u-boot.e500
815 +"
816 +
817 +QA_WX_LOAD="usr/bin/qemu-i386
818 + usr/bin/qemu-x86_64
819 + usr/bin/qemu-alpha
820 + usr/bin/qemu-arm
821 + usr/bin/qemu-cris
822 + usr/bin/qemu-m68k
823 + usr/bin/qemu-microblaze
824 + usr/bin/qemu-microblazeel
825 + usr/bin/qemu-mips
826 + usr/bin/qemu-mipsel
827 + usr/bin/qemu-or32
828 + usr/bin/qemu-ppc
829 + usr/bin/qemu-ppc64
830 + usr/bin/qemu-ppc64abi32
831 + usr/bin/qemu-sh4
832 + usr/bin/qemu-sh4eb
833 + usr/bin/qemu-sparc
834 + usr/bin/qemu-sparc64
835 + usr/bin/qemu-armeb
836 + usr/bin/qemu-sparc32plus
837 + usr/bin/qemu-s390x
838 + usr/bin/qemu-unicore32"
839 +
840 +DOC_CONTENTS="If you don't have kvm compiled into the kernel, make sure
841 +you have the kernel module loaded before running kvm. The easiest way to
842 +ensure that the kernel module is loaded is to load it on boot.\n
843 +For AMD CPUs the module is called 'kvm-amd'.\n
844 +For Intel CPUs the module is called 'kvm-intel'.\n
845 +Please review /etc/conf.d/modules for how to load these.\n\n
846 +Make sure your user is in the 'kvm' group\n
847 +Just run 'gpasswd -a <USER> kvm', then have <USER> re-login.\n\n
848 +For brand new installs, the default permissions on /dev/kvm might not let you
849 +access it. You can tell udev to reset ownership/perms:\n
850 +udevadm trigger -c add /dev/kvm"
851 +
852 +qemu_support_kvm() {
853 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386 \
854 + use qemu_softmmu_targets_ppc || use qemu_softmmu_targets_ppc64 \
855 + use qemu_softmmu_targets_s390x; then
856 + return 0
857 + fi
858 +
859 + return 1
860 +}
861 +
862 +pkg_pretend() {
863 + if use kernel_linux && kernel_is lt 2 6 25; then
864 + eerror "This version of KVM requres a host kernel of 2.6.25 or higher."
865 + elif use kernel_linux; then
866 + if ! linux_config_exists; then
867 + eerror "Unable to check your kernel for KVM support"
868 + else
869 + CONFIG_CHECK="~KVM ~TUN ~BRIDGE"
870 + ERROR_KVM="You must enable KVM in your kernel to continue"
871 + ERROR_KVM_AMD="If you have an AMD CPU, you must enable KVM_AMD in"
872 + ERROR_KVM_AMD+=" your kernel configuration."
873 + ERROR_KVM_INTEL="If you have an Intel CPU, you must enable"
874 + ERROR_KVM_INTEL+=" KVM_INTEL in your kernel configuration."
875 + ERROR_TUN="You will need the Universal TUN/TAP driver compiled"
876 + ERROR_TUN+=" into your kernel or loaded as a module to use the"
877 + ERROR_TUN+=" virtual network device if using -net tap."
878 + ERROR_BRIDGE="You will also need support for 802.1d"
879 + ERROR_BRIDGE+=" Ethernet Bridging for some network configurations."
880 + use vhost-net && CONFIG_CHECK+=" ~VHOST_NET"
881 + ERROR_VHOST_NET="You must enable VHOST_NET to have vhost-net"
882 + ERROR_VHOST_NET+=" support"
883 +
884 + if use amd64 || use x86 || use amd64-linux || use x86-linux; then
885 + CONFIG_CHECK+=" ~KVM_AMD ~KVM_INTEL"
886 + fi
887 +
888 + use python && CONFIG_CHECK+=" ~DEBUG_FS"
889 + ERROR_DEBUG_FS="debugFS support required for kvm_stat"
890 +
891 + # Now do the actual checks setup above
892 + check_extra_config
893 + fi
894 + fi
895 +
896 + if grep -qs '/usr/bin/qemu-kvm' "${EROOT}"/etc/libvirt/qemu/*.xml; then
897 + eerror "The kvm/qemu-kvm wrappers no longer exist, but your libvirt"
898 + eerror "instances are still pointing to it. Please update your"
899 + eerror "configs in /etc/libvirt/qemu/ to use the -enable-kvm flag"
900 + eerror "and the right system binary (e.g. qemu-system-x86_64)."
901 + die "update your virt configs to not use qemu-kvm"
902 + fi
903 +}
904 +
905 +pkg_setup() {
906 + enewgroup kvm 78
907 +}
908 +
909 +# Sanity check to make sure target lists are kept up-to-date.
910 +check_targets() {
911 + local var=$1 mak=$2
912 + local detected sorted
913 +
914 + pushd "${S}"/default-configs >/dev/null || die
915 +
916 + # Force C locale until glibc is updated. #564936
917 + detected=$(echo $(printf '%s\n' *-${mak}.mak | sed "s:-${mak}.mak::" | LC_COLLATE=C sort -u))
918 + sorted=$(echo $(printf '%s\n' ${!var} | LC_COLLATE=C sort -u))
919 + if [[ ${sorted} != "${detected}" ]] ; then
920 + eerror "The ebuild needs to be kept in sync."
921 + eerror "${var}: ${sorted}"
922 + eerror "$(printf '%-*s' ${#var} configure): ${detected}"
923 + die "sync ${var} to the list of targets"
924 + fi
925 +
926 + popd >/dev/null
927 +}
928 +
929 +handle_locales() {
930 + # Make sure locale list is kept up-to-date.
931 + local detected sorted
932 + detected=$(echo $(cd po && printf '%s\n' *.po | grep -v messages.po | sed 's:.po$::' | sort -u))
933 + sorted=$(echo $(printf '%s\n' ${PLOCALES} | sort -u))
934 + if [[ ${sorted} != "${detected}" ]] ; then
935 + eerror "The ebuild needs to be kept in sync."
936 + eerror "PLOCALES: ${sorted}"
937 + eerror " po/*.po: ${detected}"
938 + die "sync PLOCALES"
939 + fi
940 +
941 + # Deal with selective install of locales.
942 + if use nls ; then
943 + # Delete locales the user does not want. #577814
944 + rm_loc() { rm po/$1.po || die; }
945 + l10n_for_each_disabled_locale_do rm_loc
946 + else
947 + # Cheap hack to disable gettext .mo generation.
948 + rm -f po/*.po
949 + fi
950 +}
951 +
952 +src_prepare() {
953 + check_targets IUSE_SOFTMMU_TARGETS softmmu
954 + check_targets IUSE_USER_TARGETS linux-user
955 +
956 + # Alter target makefiles to accept CFLAGS set via flag-o
957 + sed -i -r \
958 + -e 's/^(C|OP_C|HELPER_C)FLAGS=/\1FLAGS+=/' \
959 + Makefile Makefile.target || die
960 +
961 + epatch "${FILESDIR}"/${PN}-2.5.0-cflags.patch
962 + epatch "${FILESDIR}"/${PN}-2.5.0-sysmacros.patch
963 +
964 + epatch "${FILESDIR}"/${P}-CVE-2016-6836.patch # bug 591242
965 + epatch "${FILESDIR}"/${P}-CVE-2016-7155.patch # bug 593034
966 + epatch "${FILESDIR}"/${P}-CVE-2016-7156.patch # bug 593036
967 + epatch "${FILESDIR}"/${P}-CVE-2016-7157-1.patch # bug 593038
968 + epatch "${FILESDIR}"/${P}-CVE-2016-7157-2.patch # bug 593038
969 + epatch "${FILESDIR}"/${P}-CVE-2016-7170.patch # bug 593284
970 + epatch "${FILESDIR}"/${P}-CVE-2016-7421.patch # bug 593950
971 + epatch "${FILESDIR}"/${P}-CVE-2016-7422.patch # bug 593956
972 + epatch "${FILESDIR}"/${P}-CVE-2016-7423.patch # bug 594368
973 + epatch "${FILESDIR}"/${P}-CVE-2016-7466.patch # bug 594520
974 + epatch "${FILESDIR}"/${P}-CVE-2016-7907.patch # bug 596048
975 + epatch "${FILESDIR}"/${P}-CVE-2016-7908.patch # bug 596049
976 + epatch "${FILESDIR}"/${P}-CVE-2016-7909.patch # bug 596048
977 + epatch "${FILESDIR}"/${P}-CVE-2016-7994-1.patch # bug 596738
978 + epatch "${FILESDIR}"/${P}-CVE-2016-7994-2.patch # bug 596738
979 + epatch "${FILESDIR}"/${P}-CVE-2016-8576.patch # bug 596752
980 + epatch "${FILESDIR}"/${P}-CVE-2016-8577.patch # bug 596776
981 + epatch "${FILESDIR}"/${P}-CVE-2016-8578.patch # bug 596774
982 + epatch "${FILESDIR}"/${P}-CVE-2016-8668.patch # bug 597110
983 + epatch "${FILESDIR}"/${P}-CVE-2016-8669-1.patch # bug 597108
984 + epatch "${FILESDIR}"/${P}-CVE-2016-8669-2.patch # bug 597108
985 + epatch "${FILESDIR}"/${P}-CVE-2016-8909.patch # bug 598044
986 + epatch "${FILESDIR}"/${P}-CVE-2016-8910.patch # bug 598046
987 +
988 + # Fix ld and objcopy being called directly
989 + tc-export AR LD OBJCOPY
990 +
991 + # Verbose builds
992 + MAKEOPTS+=" V=1"
993 +
994 + epatch_user
995 +
996 + # Run after we've applied all patches.
997 + handle_locales
998 +}
999 +
1000 +##
1001 +# configures qemu based on the build directory and the build type
1002 +# we are using.
1003 +#
1004 +qemu_src_configure() {
1005 + debug-print-function ${FUNCNAME} "$@"
1006 +
1007 + local buildtype=$1
1008 + local builddir="${S}/${buildtype}-build"
1009 + local static_flag="static-${buildtype}"
1010 +
1011 + mkdir "${builddir}"
1012 +
1013 + local conf_opts=(
1014 + --prefix=/usr
1015 + --sysconfdir=/etc
1016 + --libdir=/usr/$(get_libdir)
1017 + --docdir=/usr/share/doc/${PF}/html
1018 + --disable-bsd-user
1019 + --disable-guest-agent
1020 + --disable-strip
1021 + --disable-werror
1022 + # We support gnutls/nettle for crypto operations. It is possible
1023 + # to use gcrypt when gnutls/nettle are disabled (but not when they
1024 + # are enabled), but it's not really worth the hassle. Disable it
1025 + # all the time to avoid automatically detecting it. #568856
1026 + --disable-gcrypt
1027 + --python="${PYTHON}"
1028 + --cc="$(tc-getCC)"
1029 + --cxx="$(tc-getCXX)"
1030 + --host-cc="$(tc-getBUILD_CC)"
1031 + $(use_enable debug debug-info)
1032 + $(use_enable debug debug-tcg)
1033 + --enable-docs
1034 + $(use_enable tci tcg-interpreter)
1035 + $(use_enable xattr attr)
1036 + )
1037 +
1038 + # Disable options not used by user targets as the default configure
1039 + # options will autoprobe and try to link in a bunch of unused junk.
1040 + conf_softmmu() {
1041 + if [[ ${buildtype} == "user" ]] ; then
1042 + echo "--disable-${2:-$1}"
1043 + else
1044 + use_enable "$@"
1045 + fi
1046 + }
1047 + conf_opts+=(
1048 + $(conf_softmmu accessibility brlapi)
1049 + $(conf_softmmu aio linux-aio)
1050 + $(conf_softmmu bzip2)
1051 + $(conf_softmmu bluetooth bluez)
1052 + $(conf_softmmu caps cap-ng)
1053 + $(conf_softmmu curl)
1054 + $(conf_softmmu fdt)
1055 + $(conf_softmmu glusterfs)
1056 + $(conf_softmmu gnutls)
1057 + $(conf_softmmu gnutls nettle)
1058 + $(conf_softmmu gtk)
1059 + $(conf_softmmu infiniband rdma)
1060 + $(conf_softmmu iscsi libiscsi)
1061 + $(conf_softmmu jpeg vnc-jpeg)
1062 + $(conf_softmmu kernel_linux kvm)
1063 + $(conf_softmmu lzo)
1064 + $(conf_softmmu ncurses curses)
1065 + $(conf_softmmu nfs libnfs)
1066 + $(conf_softmmu numa)
1067 + $(conf_softmmu opengl)
1068 + $(conf_softmmu png vnc-png)
1069 + $(conf_softmmu rbd)
1070 + $(conf_softmmu sasl vnc-sasl)
1071 + $(conf_softmmu sdl)
1072 + $(conf_softmmu seccomp)
1073 + $(conf_softmmu smartcard)
1074 + $(conf_softmmu snappy)
1075 + $(conf_softmmu spice)
1076 + $(conf_softmmu ssh libssh2)
1077 + $(conf_softmmu usb libusb)
1078 + $(conf_softmmu usbredir usb-redir)
1079 + $(conf_softmmu uuid)
1080 + $(conf_softmmu vde)
1081 + $(conf_softmmu vhost-net)
1082 + $(conf_softmmu virgl virglrenderer)
1083 + $(conf_softmmu virtfs)
1084 + $(conf_softmmu vnc)
1085 + $(conf_softmmu vte)
1086 + $(conf_softmmu xen)
1087 + $(conf_softmmu xen xen-pci-passthrough)
1088 + $(conf_softmmu xfs xfsctl)
1089 + )
1090 +
1091 + case ${buildtype} in
1092 + user)
1093 + conf_opts+=(
1094 + --enable-linux-user
1095 + --disable-system
1096 + --disable-blobs
1097 + --disable-tools
1098 + )
1099 + ;;
1100 + softmmu)
1101 + # audio options
1102 + local audio_opts="oss"
1103 + use alsa && audio_opts="alsa,${audio_opts}"
1104 + use sdl && audio_opts="sdl,${audio_opts}"
1105 + use pulseaudio && audio_opts="pa,${audio_opts}"
1106 +
1107 + conf_opts+=(
1108 + --disable-linux-user
1109 + --enable-system
1110 + --with-system-pixman
1111 + --audio-drv-list="${audio_opts}"
1112 + )
1113 + use gtk && conf_opts+=( --with-gtkabi=$(usex gtk2 2.0 3.0) )
1114 + use sdl && conf_opts+=( --with-sdlabi=$(usex sdl2 2.0 1.2) )
1115 + ;;
1116 + tools)
1117 + conf_opts+=(
1118 + --disable-linux-user
1119 + --disable-system
1120 + --disable-blobs
1121 + $(use_enable bzip2)
1122 + )
1123 + static_flag="static"
1124 + ;;
1125 + esac
1126 +
1127 + local targets="${buildtype}_targets"
1128 + [[ -n ${targets} ]] && conf_opts+=( --target-list="${!targets}" )
1129 +
1130 + # Add support for SystemTAP
1131 + use systemtap && conf_opts+=( --enable-trace-backend=dtrace )
1132 +
1133 + # We always want to attempt to build with PIE support as it results
1134 + # in a more secure binary. But it doesn't work with static or if
1135 + # the current GCC doesn't have PIE support.
1136 + if use ${static_flag}; then
1137 + conf_opts+=( --static --disable-pie )
1138 + else
1139 + gcc-specs-pie && conf_opts+=( --enable-pie )
1140 + fi
1141 +
1142 + echo "../configure ${conf_opts[*]}"
1143 + cd "${builddir}"
1144 + ../configure "${conf_opts[@]}" || die "configure failed"
1145 +
1146 + # FreeBSD's kernel does not support QEMU assigning/grabbing
1147 + # host USB devices yet
1148 + use kernel_FreeBSD && \
1149 + sed -i -E -e "s|^(HOST_USB=)bsd|\1stub|" "${S}"/config-host.mak
1150 +}
1151 +
1152 +src_configure() {
1153 + local target
1154 +
1155 + python_setup
1156 +
1157 + softmmu_targets= softmmu_bins=()
1158 + user_targets= user_bins=()
1159 +
1160 + for target in ${IUSE_SOFTMMU_TARGETS} ; do
1161 + if use "qemu_softmmu_targets_${target}"; then
1162 + softmmu_targets+=",${target}-softmmu"
1163 + softmmu_bins+=( "qemu-system-${target}" )
1164 + fi
1165 + done
1166 +
1167 + for target in ${IUSE_USER_TARGETS} ; do
1168 + if use "qemu_user_targets_${target}"; then
1169 + user_targets+=",${target}-linux-user"
1170 + user_bins+=( "qemu-${target}" )
1171 + fi
1172 + done
1173 +
1174 + softmmu_targets=${softmmu_targets#,}
1175 + user_targets=${user_targets#,}
1176 +
1177 + [[ -n ${softmmu_targets} ]] && qemu_src_configure "softmmu"
1178 + [[ -n ${user_targets} ]] && qemu_src_configure "user"
1179 + [[ -z ${softmmu_targets}${user_targets} ]] && qemu_src_configure "tools"
1180 +}
1181 +
1182 +src_compile() {
1183 + if [[ -n ${user_targets} ]]; then
1184 + cd "${S}/user-build"
1185 + default
1186 + fi
1187 +
1188 + if [[ -n ${softmmu_targets} ]]; then
1189 + cd "${S}/softmmu-build"
1190 + default
1191 + fi
1192 +
1193 + if [[ -z ${softmmu_targets}${user_targets} ]]; then
1194 + cd "${S}/tools-build"
1195 + default
1196 + fi
1197 +}
1198 +
1199 +src_test() {
1200 + if [[ -n ${softmmu_targets} ]]; then
1201 + cd "${S}/softmmu-build"
1202 + pax-mark m */qemu-system-* #515550
1203 + emake -j1 check
1204 + emake -j1 check-report.html
1205 + fi
1206 +}
1207 +
1208 +qemu_python_install() {
1209 + python_domodule "${S}/scripts/qmp/qmp.py"
1210 +
1211 + python_doscript "${S}/scripts/kvm/vmxcap"
1212 + python_doscript "${S}/scripts/qmp/qmp-shell"
1213 + python_doscript "${S}/scripts/qmp/qemu-ga-client"
1214 +}
1215 +
1216 +src_install() {
1217 + if [[ -n ${user_targets} ]]; then
1218 + cd "${S}/user-build"
1219 + emake DESTDIR="${ED}" install
1220 +
1221 + # Install binfmt handler init script for user targets
1222 + newinitd "${FILESDIR}/qemu-binfmt.initd-r1" qemu-binfmt
1223 + fi
1224 +
1225 + if [[ -n ${softmmu_targets} ]]; then
1226 + cd "${S}/softmmu-build"
1227 + emake DESTDIR="${ED}" install
1228 +
1229 + # This might not exist if the test failed. #512010
1230 + [[ -e check-report.html ]] && dohtml check-report.html
1231 +
1232 + if use kernel_linux; then
1233 + udev_dorules "${FILESDIR}"/65-kvm.rules
1234 + fi
1235 +
1236 + if use python; then
1237 + python_foreach_impl qemu_python_install
1238 + fi
1239 + fi
1240 +
1241 + if [[ -z ${softmmu_targets}${user_targets} ]]; then
1242 + cd "${S}/tools-build"
1243 + emake DESTDIR="${ED}" install
1244 + fi
1245 +
1246 + # Disable mprotect on the qemu binaries as they use JITs to be fast #459348
1247 + pushd "${ED}"/usr/bin >/dev/null
1248 + pax-mark m "${softmmu_bins[@]}" "${user_bins[@]}"
1249 + popd >/dev/null
1250 +
1251 + # Install config file example for qemu-bridge-helper
1252 + insinto "/etc/qemu"
1253 + doins "${FILESDIR}/bridge.conf"
1254 +
1255 + # Remove the docdir placed qmp-commands.txt
1256 + mv "${ED}/usr/share/doc/${PF}/html/qmp-commands.txt" "${S}/docs/" || die
1257 +
1258 + cd "${S}"
1259 + dodoc Changelog MAINTAINERS docs/specs/pci-ids.txt
1260 + newdoc pc-bios/README README.pc-bios
1261 + dodoc docs/qmp-*.txt
1262 +
1263 + if [[ -n ${softmmu_targets} ]]; then
1264 + # Remove SeaBIOS since we're using the SeaBIOS packaged one
1265 + rm "${ED}/usr/share/qemu/bios.bin"
1266 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
1267 + dosym ../seabios/bios.bin /usr/share/qemu/bios.bin
1268 + fi
1269 +
1270 + # Remove vgabios since we're using the vgabios packaged one
1271 + rm "${ED}/usr/share/qemu/vgabios.bin"
1272 + rm "${ED}/usr/share/qemu/vgabios-cirrus.bin"
1273 + rm "${ED}/usr/share/qemu/vgabios-qxl.bin"
1274 + rm "${ED}/usr/share/qemu/vgabios-stdvga.bin"
1275 + rm "${ED}/usr/share/qemu/vgabios-vmware.bin"
1276 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
1277 + dosym ../vgabios/vgabios.bin /usr/share/qemu/vgabios.bin
1278 + dosym ../vgabios/vgabios-cirrus.bin /usr/share/qemu/vgabios-cirrus.bin
1279 + dosym ../vgabios/vgabios-qxl.bin /usr/share/qemu/vgabios-qxl.bin
1280 + dosym ../vgabios/vgabios-stdvga.bin /usr/share/qemu/vgabios-stdvga.bin
1281 + dosym ../vgabios/vgabios-vmware.bin /usr/share/qemu/vgabios-vmware.bin
1282 + fi
1283 +
1284 + # Remove sgabios since we're using the sgabios packaged one
1285 + rm "${ED}/usr/share/qemu/sgabios.bin"
1286 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
1287 + dosym ../sgabios/sgabios.bin /usr/share/qemu/sgabios.bin
1288 + fi
1289 +
1290 + # Remove iPXE since we're using the iPXE packaged one
1291 + rm "${ED}"/usr/share/qemu/pxe-*.rom
1292 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
1293 + dosym ../ipxe/8086100e.rom /usr/share/qemu/pxe-e1000.rom
1294 + dosym ../ipxe/80861209.rom /usr/share/qemu/pxe-eepro100.rom
1295 + dosym ../ipxe/10500940.rom /usr/share/qemu/pxe-ne2k_pci.rom
1296 + dosym ../ipxe/10222000.rom /usr/share/qemu/pxe-pcnet.rom
1297 + dosym ../ipxe/10ec8139.rom /usr/share/qemu/pxe-rtl8139.rom
1298 + dosym ../ipxe/1af41000.rom /usr/share/qemu/pxe-virtio.rom
1299 + fi
1300 + fi
1301 +
1302 + qemu_support_kvm && readme.gentoo_create_doc
1303 +}
1304 +
1305 +pkg_postinst() {
1306 + if qemu_support_kvm; then
1307 + readme.gentoo_print_elog
1308 + fi
1309 +
1310 + if [[ -n ${softmmu_targets} ]] && use kernel_linux; then
1311 + udev_reload
1312 + fi
1313 +
1314 + fcaps cap_net_admin /usr/libexec/qemu-bridge-helper
1315 +}
1316 +
1317 +pkg_info() {
1318 + echo "Using:"
1319 + echo " $(best_version app-emulation/spice-protocol)"
1320 + echo " $(best_version sys-firmware/ipxe)"
1321 + echo " $(best_version sys-firmware/seabios)"
1322 + if has_version 'sys-firmware/seabios[binary]'; then
1323 + echo " USE=binary"
1324 + else
1325 + echo " USE=''"
1326 + fi
1327 + echo " $(best_version sys-firmware/vgabios)"
1328 +}