Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: app-emulation/qemu/files/, app-emulation/qemu/
Date: Tue, 08 Dec 2015 03:17:54
Message-Id: 1449544291.32c4e7044c0a00de9d1a10fc8db207c4fa34dbba.vapier@gentoo
1 commit: 32c4e7044c0a00de9d1a10fc8db207c4fa34dbba
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Tue Dec 8 03:11:31 2015 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Tue Dec 8 03:11:31 2015 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=32c4e704
7
8 app-emulation/qemu: add upstream security fixes #566792 #567144
9
10 .../qemu/files/qemu-2.4.1-CVE-2015-7504.patch | 49 ++
11 .../qemu/files/qemu-2.4.1-CVE-2015-7512.patch | 37 ++
12 .../qemu/files/qemu-2.4.1-CVE-2015-8345.patch | 65 +++
13 app-emulation/qemu/qemu-2.4.1-r1.ebuild | 644 +++++++++++++++++++++
14 4 files changed, 795 insertions(+)
15
16 diff --git a/app-emulation/qemu/files/qemu-2.4.1-CVE-2015-7504.patch b/app-emulation/qemu/files/qemu-2.4.1-CVE-2015-7504.patch
17 new file mode 100644
18 index 0000000..e86e0c6
19 --- /dev/null
20 +++ b/app-emulation/qemu/files/qemu-2.4.1-CVE-2015-7504.patch
21 @@ -0,0 +1,49 @@
22 +From 837f21aacf5a714c23ddaadbbc5212f9b661e3f7 Mon Sep 17 00:00:00 2001
23 +From: Prasad J Pandit <pjp@×××××××××××××.org>
24 +Date: Fri, 20 Nov 2015 11:50:31 +0530
25 +Subject: [PATCH] net: pcnet: add check to validate receive data
26 + size(CVE-2015-7504)
27 +
28 +In loopback mode, pcnet_receive routine appends CRC code to the
29 +receive buffer. If the data size given is same as the buffer size,
30 +the appended CRC code overwrites 4 bytes after s->buffer. Added a
31 +check to avoid that.
32 +
33 +Reported by: Qinghao Tang <luodalongde@×××××.com>
34 +Cc: qemu-stable@××××××.org
35 +Reviewed-by: Michael S. Tsirkin <mst@××××××.com>
36 +Signed-off-by: Prasad J Pandit <pjp@×××××××××××××.org>
37 +Signed-off-by: Jason Wang <jasowang@××××××.com>
38 +---
39 + hw/net/pcnet.c | 8 +++++---
40 + 1 file changed, 5 insertions(+), 3 deletions(-)
41 +
42 +diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c
43 +index 0eb3cc4..309c40b 100644
44 +--- a/hw/net/pcnet.c
45 ++++ b/hw/net/pcnet.c
46 +@@ -1084,7 +1084,7 @@ ssize_t pcnet_receive(NetClientState *nc, const uint8_t *buf, size_t size_)
47 + uint32_t fcs = ~0;
48 + uint8_t *p = src;
49 +
50 +- while (p != &src[size-4])
51 ++ while (p != &src[size])
52 + CRC(fcs, *p++);
53 + crc_err = (*(uint32_t *)p != htonl(fcs));
54 + }
55 +@@ -1233,8 +1233,10 @@ static void pcnet_transmit(PCNetState *s)
56 + bcnt = 4096 - GET_FIELD(tmd.length, TMDL, BCNT);
57 +
58 + /* if multi-tmd packet outsizes s->buffer then skip it silently.
59 +- Note: this is not what real hw does */
60 +- if (s->xmit_pos + bcnt > sizeof(s->buffer)) {
61 ++ * Note: this is not what real hw does.
62 ++ * Last four bytes of s->buffer are used to store CRC FCS code.
63 ++ */
64 ++ if (s->xmit_pos + bcnt > sizeof(s->buffer) - 4) {
65 + s->xmit_pos = -1;
66 + goto txdone;
67 + }
68 +--
69 +2.6.2
70 +
71
72 diff --git a/app-emulation/qemu/files/qemu-2.4.1-CVE-2015-7512.patch b/app-emulation/qemu/files/qemu-2.4.1-CVE-2015-7512.patch
73 new file mode 100644
74 index 0000000..4fee9ef
75 --- /dev/null
76 +++ b/app-emulation/qemu/files/qemu-2.4.1-CVE-2015-7512.patch
77 @@ -0,0 +1,37 @@
78 +From 8b98a2f07175d46c3f7217639bd5e03f2ec56343 Mon Sep 17 00:00:00 2001
79 +From: Jason Wang <jasowang@××××××.com>
80 +Date: Mon, 30 Nov 2015 15:00:06 +0800
81 +Subject: [PATCH] pcnet: fix rx buffer overflow(CVE-2015-7512)
82 +
83 +Backends could provide a packet whose length is greater than buffer
84 +size. Check for this and truncate the packet to avoid rx buffer
85 +overflow in this case.
86 +
87 +Cc: Prasad J Pandit <pjp@×××××××××××××.org>
88 +Cc: qemu-stable@××××××.org
89 +Reviewed-by: Michael S. Tsirkin <mst@××××××.com>
90 +Signed-off-by: Jason Wang <jasowang@××××××.com>
91 +---
92 + hw/net/pcnet.c | 6 ++++++
93 + 1 file changed, 6 insertions(+)
94 +
95 +diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c
96 +index 309c40b..1f4a3db 100644
97 +--- a/hw/net/pcnet.c
98 ++++ b/hw/net/pcnet.c
99 +@@ -1064,6 +1064,12 @@ ssize_t pcnet_receive(NetClientState *nc, const uint8_t *buf, size_t size_)
100 + int pktcount = 0;
101 +
102 + if (!s->looptest) {
103 ++ if (size > 4092) {
104 ++#ifdef PCNET_DEBUG_RMD
105 ++ fprintf(stderr, "pcnet: truncates rx packet.\n");
106 ++#endif
107 ++ size = 4092;
108 ++ }
109 + memcpy(src, buf, size);
110 + /* no need to compute the CRC */
111 + src[size] = 0;
112 +--
113 +2.6.2
114 +
115
116 diff --git a/app-emulation/qemu/files/qemu-2.4.1-CVE-2015-8345.patch b/app-emulation/qemu/files/qemu-2.4.1-CVE-2015-8345.patch
117 new file mode 100644
118 index 0000000..f01d9ac
119 --- /dev/null
120 +++ b/app-emulation/qemu/files/qemu-2.4.1-CVE-2015-8345.patch
121 @@ -0,0 +1,65 @@
122 +https://bugs.gentoo.org/566792
123 +
124 +From 00837731d254908a841d69298a4f9f077babaf24 Mon Sep 17 00:00:00 2001
125 +From: Stefan Weil <sw@××××××××.de>
126 +Date: Fri, 20 Nov 2015 08:42:33 +0100
127 +Subject: [PATCH] eepro100: Prevent two endless loops
128 +
129 +http://lists.nongnu.org/archive/html/qemu-devel/2015-11/msg04592.html
130 +shows an example how an endless loop in function action_command can
131 +be achieved.
132 +
133 +During my code review, I noticed a 2nd case which can result in an
134 +endless loop.
135 +
136 +Reported-by: Qinghao Tang <luodalongde@×××××.com>
137 +Signed-off-by: Stefan Weil <sw@××××××××.de>
138 +Signed-off-by: Jason Wang <jasowang@××××××.com>
139 +---
140 + hw/net/eepro100.c | 16 ++++++++++++++++
141 + 1 file changed, 16 insertions(+)
142 +
143 +diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c
144 +index 60333b7..685a478 100644
145 +--- a/hw/net/eepro100.c
146 ++++ b/hw/net/eepro100.c
147 +@@ -774,6 +774,11 @@ static void tx_command(EEPRO100State *s)
148 + #if 0
149 + uint16_t tx_buffer_el = lduw_le_pci_dma(&s->dev, tbd_address + 6);
150 + #endif
151 ++ if (tx_buffer_size == 0) {
152 ++ /* Prevent an endless loop. */
153 ++ logout("loop in %s:%u\n", __FILE__, __LINE__);
154 ++ break;
155 ++ }
156 + tbd_address += 8;
157 + TRACE(RXTX, logout
158 + ("TBD (simplified mode): buffer address 0x%08x, size 0x%04x\n",
159 +@@ -855,6 +860,10 @@ static void set_multicast_list(EEPRO100State *s)
160 +
161 + static void action_command(EEPRO100State *s)
162 + {
163 ++ /* The loop below won't stop if it gets special handcrafted data.
164 ++ Therefore we limit the number of iterations. */
165 ++ unsigned max_loop_count = 16;
166 ++
167 + for (;;) {
168 + bool bit_el;
169 + bool bit_s;
170 +@@ -870,6 +879,13 @@ static void action_command(EEPRO100State *s)
171 + #if 0
172 + bool bit_sf = ((s->tx.command & COMMAND_SF) != 0);
173 + #endif
174 ++
175 ++ if (max_loop_count-- == 0) {
176 ++ /* Prevent an endless loop. */
177 ++ logout("loop in %s:%u\n", __FILE__, __LINE__);
178 ++ break;
179 ++ }
180 ++
181 + s->cu_offset = s->tx.link;
182 + TRACE(OTHER,
183 + logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n",
184 +--
185 +2.6.2
186 +
187
188 diff --git a/app-emulation/qemu/qemu-2.4.1-r1.ebuild b/app-emulation/qemu/qemu-2.4.1-r1.ebuild
189 new file mode 100644
190 index 0000000..6e3ff9a
191 --- /dev/null
192 +++ b/app-emulation/qemu/qemu-2.4.1-r1.ebuild
193 @@ -0,0 +1,644 @@
194 +# Copyright 1999-2015 Gentoo Foundation
195 +# Distributed under the terms of the GNU General Public License v2
196 +# $Id$
197 +
198 +EAPI=5
199 +
200 +PYTHON_COMPAT=( python2_7 )
201 +PYTHON_REQ_USE="ncurses,readline"
202 +
203 +inherit eutils flag-o-matic linux-info toolchain-funcs multilib python-r1 \
204 + user udev fcaps readme.gentoo pax-utils
205 +
206 +BACKPORTS=
207 +
208 +if [[ ${PV} = *9999* ]]; then
209 + EGIT_REPO_URI="git://git.qemu.org/qemu.git"
210 + inherit git-2
211 + SRC_URI=""
212 +else
213 + SRC_URI="http://wiki.qemu-project.org/download/${P}.tar.bz2
214 + ${BACKPORTS:+
215 + https://dev.gentoo.org/~cardoe/distfiles/${P}-${BACKPORTS}.tar.xz}"
216 + KEYWORDS="~amd64 ~ppc ~ppc64 ~x86 ~x86-fbsd"
217 +fi
218 +
219 +DESCRIPTION="QEMU + Kernel-based Virtual Machine userland tools"
220 +HOMEPAGE="http://www.qemu.org http://www.linux-kvm.org"
221 +
222 +LICENSE="GPL-2 LGPL-2 BSD-2"
223 +SLOT="0"
224 +IUSE="accessibility +aio alsa bluetooth +caps +curl debug +fdt glusterfs \
225 +gtk gtk2 infiniband iscsi +jpeg \
226 +kernel_linux kernel_FreeBSD lzo ncurses nfs nls numa opengl +pin-upstream-blobs
227 ++png pulseaudio python \
228 +rbd sasl +seccomp sdl sdl2 selinux smartcard snappy spice ssh static static-softmmu
229 +static-user systemtap tci test +threads tls usb usbredir +uuid vde +vhost-net \
230 +virtfs +vnc vte xattr xen xfs"
231 +
232 +COMMON_TARGETS="aarch64 alpha arm cris i386 m68k microblaze microblazeel mips
233 +mips64 mips64el mipsel or32 ppc ppc64 s390x sh4 sh4eb sparc sparc64 unicore32
234 +x86_64"
235 +IUSE_SOFTMMU_TARGETS="${COMMON_TARGETS} lm32 moxie ppcemb tricore xtensa xtensaeb"
236 +IUSE_USER_TARGETS="${COMMON_TARGETS} armeb mipsn32 mipsn32el ppc64abi32 ppc64le sparc32plus"
237 +
238 +use_softmmu_targets=$(printf ' qemu_softmmu_targets_%s' ${IUSE_SOFTMMU_TARGETS})
239 +use_user_targets=$(printf ' qemu_user_targets_%s' ${IUSE_USER_TARGETS})
240 +IUSE+=" ${use_softmmu_targets} ${use_user_targets}"
241 +
242 +# Allow no targets to be built so that people can get a tools-only build.
243 +# Block USE flag configurations known to not work.
244 +REQUIRED_USE="${PYTHON_REQUIRED_USE}
245 + gtk2? ( gtk )
246 + qemu_softmmu_targets_arm? ( fdt )
247 + qemu_softmmu_targets_microblaze? ( fdt )
248 + qemu_softmmu_targets_ppc? ( fdt )
249 + qemu_softmmu_targets_ppc64? ( fdt )
250 + sdl2? ( sdl )
251 + static? ( static-softmmu static-user )
252 + static-softmmu? ( !alsa !pulseaudio !bluetooth !opengl !gtk !gtk2 )
253 + virtfs? ( xattr )
254 + vte? ( gtk )"
255 +
256 +# Yep, you need both libcap and libcap-ng since virtfs only uses libcap.
257 +#
258 +# The attr lib isn't always linked in (although the USE flag is always
259 +# respected). This is because qemu supports using the C library's API
260 +# when available rather than always using the extranl library.
261 +COMMON_LIB_DEPEND=">=dev-libs/glib-2.0[static-libs(+)]
262 + sys-libs/zlib[static-libs(+)]
263 + xattr? ( sys-apps/attr[static-libs(+)] )"
264 +SOFTMMU_LIB_DEPEND="${COMMON_LIB_DEPEND}
265 + >=x11-libs/pixman-0.28.0[static-libs(+)]
266 + accessibility? ( app-accessibility/brltty[static-libs(+)] )
267 + aio? ( dev-libs/libaio[static-libs(+)] )
268 + alsa? ( >=media-libs/alsa-lib-1.0.13 )
269 + bluetooth? ( net-wireless/bluez )
270 + caps? ( sys-libs/libcap-ng[static-libs(+)] )
271 + curl? ( >=net-misc/curl-7.15.4[static-libs(+)] )
272 + fdt? ( >=sys-apps/dtc-1.4.0[static-libs(+)] )
273 + glusterfs? ( >=sys-cluster/glusterfs-3.4.0[static-libs(+)] )
274 + gtk? (
275 + gtk2? (
276 + x11-libs/gtk+:2
277 + vte? ( x11-libs/vte:0 )
278 + )
279 + !gtk2? (
280 + x11-libs/gtk+:3
281 + vte? ( x11-libs/vte:2.90 )
282 + )
283 + )
284 + infiniband? ( sys-infiniband/librdmacm:=[static-libs(+)] )
285 + iscsi? ( net-libs/libiscsi )
286 + jpeg? ( virtual/jpeg:=[static-libs(+)] )
287 + lzo? ( dev-libs/lzo:2[static-libs(+)] )
288 + ncurses? ( sys-libs/ncurses:0=[static-libs(+)] )
289 + nfs? ( >=net-fs/libnfs-1.9.3[static-libs(+)] )
290 + numa? ( sys-process/numactl[static-libs(+)] )
291 + opengl? (
292 + virtual/opengl
293 + media-libs/libepoxy[static-libs(+)]
294 + media-libs/mesa[static-libs(+)]
295 + media-libs/mesa[egl,gles2]
296 + )
297 + png? ( media-libs/libpng:0=[static-libs(+)] )
298 + pulseaudio? ( media-sound/pulseaudio )
299 + rbd? ( sys-cluster/ceph[static-libs(+)] )
300 + sasl? ( dev-libs/cyrus-sasl[static-libs(+)] )
301 + sdl? (
302 + !sdl2? (
303 + media-libs/libsdl[X]
304 + >=media-libs/libsdl-1.2.11[static-libs(+)]
305 + )
306 + sdl2? (
307 + media-libs/libsdl2[X]
308 + media-libs/libsdl2[static-libs(+)]
309 + )
310 + )
311 + seccomp? ( >=sys-libs/libseccomp-2.1.0[static-libs(+)] )
312 + smartcard? ( dev-libs/nss !app-emulation/libcacard )
313 + snappy? ( app-arch/snappy[static-libs(+)] )
314 + spice? (
315 + >=app-emulation/spice-protocol-0.12.3
316 + >=app-emulation/spice-0.12.0[static-libs(+)]
317 + )
318 + ssh? ( >=net-libs/libssh2-1.2.8[static-libs(+)] )
319 + tls? ( net-libs/gnutls[static-libs(+)] )
320 + usb? ( >=virtual/libusb-1-r2[static-libs(+)] )
321 + usbredir? ( >=sys-apps/usbredir-0.6[static-libs(+)] )
322 + uuid? ( >=sys-apps/util-linux-2.16.0[static-libs(+)] )
323 + vde? ( net-misc/vde[static-libs(+)] )
324 + virtfs? ( sys-libs/libcap )
325 + xfs? ( sys-fs/xfsprogs[static-libs(+)] )"
326 +USER_LIB_DEPEND="${COMMON_LIB_DEPEND}"
327 +X86_FIRMWARE_DEPEND="
328 + >=sys-firmware/ipxe-1.0.0_p20130624
329 + pin-upstream-blobs? (
330 + ~sys-firmware/seabios-1.8.2
331 + ~sys-firmware/sgabios-0.1_pre8
332 + ~sys-firmware/vgabios-0.7a
333 + )
334 + !pin-upstream-blobs? (
335 + sys-firmware/seabios
336 + sys-firmware/sgabios
337 + sys-firmware/vgabios
338 + )"
339 +CDEPEND="
340 + !static-softmmu? ( $(printf "%s? ( ${SOFTMMU_LIB_DEPEND//\[static-libs(+)]} ) " ${use_softmmu_targets}) )
341 + !static-user? ( $(printf "%s? ( ${USER_LIB_DEPEND//\[static-libs(+)]} ) " ${use_user_targets}) )
342 + qemu_softmmu_targets_i386? ( ${X86_FIRMWARE_DEPEND} )
343 + qemu_softmmu_targets_x86_64? ( ${X86_FIRMWARE_DEPEND} )
344 + python? ( ${PYTHON_DEPS} )
345 + systemtap? ( dev-util/systemtap )
346 + xen? ( app-emulation/xen-tools:= )"
347 +DEPEND="${CDEPEND}
348 + dev-lang/perl
349 + =dev-lang/python-2*
350 + sys-apps/texinfo
351 + virtual/pkgconfig
352 + kernel_linux? ( >=sys-kernel/linux-headers-2.6.35 )
353 + gtk? ( nls? ( sys-devel/gettext ) )
354 + static-softmmu? ( $(printf "%s? ( ${SOFTMMU_LIB_DEPEND} ) " ${use_softmmu_targets}) )
355 + static-user? ( $(printf "%s? ( ${USER_LIB_DEPEND} ) " ${use_user_targets}) )
356 + test? (
357 + dev-libs/glib[utils]
358 + sys-devel/bc
359 + )"
360 +RDEPEND="${CDEPEND}
361 + selinux? ( sec-policy/selinux-qemu )
362 +"
363 +
364 +STRIP_MASK="/usr/share/qemu/palcode-clipper"
365 +
366 +QA_PREBUILT="
367 + usr/share/qemu/openbios-ppc
368 + usr/share/qemu/openbios-sparc64
369 + usr/share/qemu/openbios-sparc32
370 + usr/share/qemu/palcode-clipper
371 + usr/share/qemu/s390-ccw.img
372 + usr/share/qemu/u-boot.e500
373 +"
374 +
375 +QA_WX_LOAD="usr/bin/qemu-i386
376 + usr/bin/qemu-x86_64
377 + usr/bin/qemu-alpha
378 + usr/bin/qemu-arm
379 + usr/bin/qemu-cris
380 + usr/bin/qemu-m68k
381 + usr/bin/qemu-microblaze
382 + usr/bin/qemu-microblazeel
383 + usr/bin/qemu-mips
384 + usr/bin/qemu-mipsel
385 + usr/bin/qemu-or32
386 + usr/bin/qemu-ppc
387 + usr/bin/qemu-ppc64
388 + usr/bin/qemu-ppc64abi32
389 + usr/bin/qemu-sh4
390 + usr/bin/qemu-sh4eb
391 + usr/bin/qemu-sparc
392 + usr/bin/qemu-sparc64
393 + usr/bin/qemu-armeb
394 + usr/bin/qemu-sparc32plus
395 + usr/bin/qemu-s390x
396 + usr/bin/qemu-unicore32"
397 +
398 +DOC_CONTENTS="If you don't have kvm compiled into the kernel, make sure
399 +you have the kernel module loaded before running kvm. The easiest way to
400 +ensure that the kernel module is loaded is to load it on boot.\n
401 +For AMD CPUs the module is called 'kvm-amd'\n
402 +For Intel CPUs the module is called 'kvm-intel'\n
403 +Please review /etc/conf.d/modules for how to load these\n\n
404 +Make sure your user is in the 'kvm' group\n
405 +Just run 'gpasswd -a <USER> kvm', then have <USER> re-login."
406 +
407 +qemu_support_kvm() {
408 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386 \
409 + use qemu_softmmu_targets_ppc || use qemu_softmmu_targets_ppc64 \
410 + use qemu_softmmu_targets_s390x; then
411 + return 0
412 + fi
413 +
414 + return 1
415 +}
416 +
417 +pkg_pretend() {
418 + if use kernel_linux && kernel_is lt 2 6 25; then
419 + eerror "This version of KVM requres a host kernel of 2.6.25 or higher."
420 + elif use kernel_linux; then
421 + if ! linux_config_exists; then
422 + eerror "Unable to check your kernel for KVM support"
423 + else
424 + CONFIG_CHECK="~KVM ~TUN ~BRIDGE"
425 + ERROR_KVM="You must enable KVM in your kernel to continue"
426 + ERROR_KVM_AMD="If you have an AMD CPU, you must enable KVM_AMD in"
427 + ERROR_KVM_AMD+=" your kernel configuration."
428 + ERROR_KVM_INTEL="If you have an Intel CPU, you must enable"
429 + ERROR_KVM_INTEL+=" KVM_INTEL in your kernel configuration."
430 + ERROR_TUN="You will need the Universal TUN/TAP driver compiled"
431 + ERROR_TUN+=" into your kernel or loaded as a module to use the"
432 + ERROR_TUN+=" virtual network device if using -net tap."
433 + ERROR_BRIDGE="You will also need support for 802.1d"
434 + ERROR_BRIDGE+=" Ethernet Bridging for some network configurations."
435 + use vhost-net && CONFIG_CHECK+=" ~VHOST_NET"
436 + ERROR_VHOST_NET="You must enable VHOST_NET to have vhost-net"
437 + ERROR_VHOST_NET+=" support"
438 +
439 + if use amd64 || use x86 || use amd64-linux || use x86-linux; then
440 + CONFIG_CHECK+=" ~KVM_AMD ~KVM_INTEL"
441 + fi
442 +
443 + use python && CONFIG_CHECK+=" ~DEBUG_FS"
444 + ERROR_DEBUG_FS="debugFS support required for kvm_stat"
445 +
446 + # Now do the actual checks setup above
447 + check_extra_config
448 + fi
449 + fi
450 +
451 + if grep -qs '/usr/bin/qemu-kvm' "${EROOT}"/etc/libvirt/qemu/*.xml; then
452 + eerror "The kvm/qemu-kvm wrappers no longer exist, but your libvirt"
453 + eerror "instances are still pointing to it. Please update your"
454 + eerror "configs in /etc/libvirt/qemu/ to use the -enable-kvm flag"
455 + eerror "and the right system binary (e.g. qemu-system-x86_64)."
456 + die "update your virt configs to not use qemu-kvm"
457 + fi
458 +}
459 +
460 +pkg_setup() {
461 + enewgroup kvm 78
462 +}
463 +
464 +# Sanity check to make sure target lists are kept up-to-date.
465 +check_targets() {
466 + local var=$1 mak=$2
467 + local detected sorted
468 +
469 + pushd "${S}"/default-configs >/dev/null || die
470 +
471 + # Force C locale until glibc is updated. #564936
472 + detected=$(echo $(printf '%s\n' *-${mak}.mak | sed "s:-${mak}.mak::" | LC_COLLATE=C sort -u))
473 + sorted=$(echo $(printf '%s\n' ${!var} | LC_COLLATE=C sort -u))
474 + if [[ ${sorted} != "${detected}" ]] ; then
475 + eerror "The ebuild needs to be kept in sync."
476 + eerror "${var}: ${sorted}"
477 + eerror "$(printf '%-*s' ${#var} configure): ${detected}"
478 + die "sync ${var} to the list of targets"
479 + fi
480 +
481 + popd >/dev/null
482 +}
483 +
484 +src_prepare() {
485 + check_targets IUSE_SOFTMMU_TARGETS softmmu
486 + check_targets IUSE_USER_TARGETS linux-user
487 +
488 + # Alter target makefiles to accept CFLAGS set via flag-o
489 + sed -i -r \
490 + -e 's/^(C|OP_C|HELPER_C)FLAGS=/\1FLAGS+=/' \
491 + Makefile Makefile.target || die
492 +
493 + # Cheap hack to disable gettext .mo generation.
494 + use nls || rm -f po/*.po
495 +
496 + epatch "${FILESDIR}"/qemu-1.7.0-cflags.patch
497 + epatch "${FILESDIR}"/${PN}-2.4.1-CVE-2015-{7504,7512}.patch #567144
498 + epatch "${FILESDIR}"/${PN}-2.4.1-CVE-2015-8345.patch #566792
499 + epatch "${FILESDIR}"/${PN}-2.4-mips-* #563162
500 + [[ -n ${BACKPORTS} ]] && \
501 + EPATCH_FORCE=yes EPATCH_SUFFIX="patch" EPATCH_SOURCE="${S}/patches" \
502 + epatch
503 +
504 + # Fix ld and objcopy being called directly
505 + tc-export AR LD OBJCOPY
506 +
507 + # Verbose builds
508 + MAKEOPTS+=" V=1"
509 +
510 + epatch_user
511 +}
512 +
513 +##
514 +# configures qemu based on the build directory and the build type
515 +# we are using.
516 +#
517 +qemu_src_configure() {
518 + debug-print-function ${FUNCNAME} "$@"
519 +
520 + local buildtype=$1
521 + local builddir="${S}/${buildtype}-build"
522 + local static_flag="static-${buildtype}"
523 +
524 + mkdir "${builddir}"
525 +
526 + local conf_opts=(
527 + --prefix=/usr
528 + --sysconfdir=/etc
529 + --libdir=/usr/$(get_libdir)
530 + --docdir=/usr/share/doc/${PF}/html
531 + --disable-bsd-user
532 + --disable-guest-agent
533 + --disable-strip
534 + --disable-werror
535 + --python="${PYTHON}"
536 + --cc="$(tc-getCC)"
537 + --cxx="$(tc-getCXX)"
538 + --host-cc="$(tc-getBUILD_CC)"
539 + $(use_enable debug debug-info)
540 + $(use_enable debug debug-tcg)
541 + --enable-docs
542 + $(use_enable tci tcg-interpreter)
543 + $(use_enable xattr attr)
544 + )
545 +
546 + # Disable options not used by user targets as the default configure
547 + # options will autoprobe and try to link in a bunch of unused junk.
548 + conf_softmmu() {
549 + if [[ ${buildtype} == "user" ]] ; then
550 + echo "--disable-${2:-$1}"
551 + else
552 + use_enable "$@"
553 + fi
554 + }
555 + conf_opts+=(
556 + $(conf_softmmu accessibility brlapi)
557 + $(conf_softmmu aio linux-aio)
558 + $(conf_softmmu bluetooth bluez)
559 + $(conf_softmmu caps cap-ng)
560 + $(conf_softmmu curl)
561 + $(conf_softmmu fdt)
562 + $(conf_softmmu glusterfs)
563 + $(conf_softmmu gtk)
564 + $(conf_softmmu infiniband rdma)
565 + $(conf_softmmu iscsi libiscsi)
566 + $(conf_softmmu jpeg vnc-jpeg)
567 + $(conf_softmmu kernel_linux kvm)
568 + $(conf_softmmu lzo)
569 + $(conf_softmmu ncurses curses)
570 + $(conf_softmmu nfs libnfs)
571 + $(conf_softmmu numa)
572 + $(conf_softmmu opengl)
573 + $(conf_softmmu png vnc-png)
574 + $(conf_softmmu rbd)
575 + $(conf_softmmu sasl vnc-sasl)
576 + $(conf_softmmu sdl)
577 + $(conf_softmmu seccomp)
578 + $(conf_softmmu smartcard smartcard-nss)
579 + $(conf_softmmu snappy)
580 + $(conf_softmmu spice)
581 + $(conf_softmmu ssh libssh2)
582 + $(conf_softmmu tls vnc-tls)
583 + $(conf_softmmu usb libusb)
584 + $(conf_softmmu usbredir usb-redir)
585 + $(conf_softmmu uuid)
586 + $(conf_softmmu vde)
587 + $(conf_softmmu vhost-net)
588 + $(conf_softmmu virtfs)
589 + $(conf_softmmu vnc)
590 + $(conf_softmmu vte)
591 + $(conf_softmmu xen)
592 + $(conf_softmmu xen xen-pci-passthrough)
593 + $(conf_softmmu xfs xfsctl)
594 + )
595 +
596 + case ${buildtype} in
597 + user)
598 + conf_opts+=(
599 + --enable-linux-user
600 + --disable-system
601 + --disable-blobs
602 + --disable-tools
603 + )
604 + ;;
605 + softmmu)
606 + # audio options
607 + local audio_opts="oss"
608 + use alsa && audio_opts="alsa,${audio_opts}"
609 + use sdl && audio_opts="sdl,${audio_opts}"
610 + use pulseaudio && audio_opts="pa,${audio_opts}"
611 +
612 + conf_opts+=(
613 + --disable-linux-user
614 + --enable-system
615 + --with-system-pixman
616 + --audio-drv-list="${audio_opts}"
617 + )
618 + use gtk && conf_opts+=( --with-gtkabi=$(usex gtk2 2.0 3.0) )
619 + use sdl && conf_opts+=( --with-sdlabi=$(usex sdl2 2.0 1.2) )
620 + ;;
621 + tools)
622 + conf_opts+=(
623 + --disable-linux-user
624 + --disable-system
625 + --disable-blobs
626 + )
627 + static_flag="static"
628 + ;;
629 + esac
630 +
631 + local targets="${buildtype}_targets"
632 + [[ -n ${targets} ]] && conf_opts+=( --target-list="${!targets}" )
633 +
634 + # Add support for SystemTAP
635 + use systemtap && conf_opts+=( --enable-trace-backend=dtrace )
636 +
637 + # We always want to attempt to build with PIE support as it results
638 + # in a more secure binary. But it doesn't work with static or if
639 + # the current GCC doesn't have PIE support.
640 + if use ${static_flag}; then
641 + conf_opts+=( --static --disable-pie )
642 + else
643 + gcc-specs-pie && conf_opts+=( --enable-pie )
644 + fi
645 +
646 + echo "../configure ${conf_opts[*]}"
647 + cd "${builddir}"
648 + ../configure "${conf_opts[@]}" || die "configure failed"
649 +
650 + # FreeBSD's kernel does not support QEMU assigning/grabbing
651 + # host USB devices yet
652 + use kernel_FreeBSD && \
653 + sed -i -E -e "s|^(HOST_USB=)bsd|\1stub|" "${S}"/config-host.mak
654 +}
655 +
656 +src_configure() {
657 + local target
658 +
659 + python_setup
660 +
661 + softmmu_targets= softmmu_bins=()
662 + user_targets= user_bins=()
663 +
664 + for target in ${IUSE_SOFTMMU_TARGETS} ; do
665 + if use "qemu_softmmu_targets_${target}"; then
666 + softmmu_targets+=",${target}-softmmu"
667 + softmmu_bins+=( "qemu-system-${target}" )
668 + fi
669 + done
670 +
671 + for target in ${IUSE_USER_TARGETS} ; do
672 + if use "qemu_user_targets_${target}"; then
673 + user_targets+=",${target}-linux-user"
674 + user_bins+=( "qemu-${target}" )
675 + fi
676 + done
677 +
678 + softmmu_targets=${softmmu_targets#,}
679 + user_targets=${user_targets#,}
680 +
681 + [[ -n ${softmmu_targets} ]] && qemu_src_configure "softmmu"
682 + [[ -n ${user_targets} ]] && qemu_src_configure "user"
683 + [[ -z ${softmmu_targets}${user_targets} ]] && qemu_src_configure "tools"
684 +}
685 +
686 +src_compile() {
687 + if [[ -n ${user_targets} ]]; then
688 + cd "${S}/user-build"
689 + default
690 + fi
691 +
692 + if [[ -n ${softmmu_targets} ]]; then
693 + cd "${S}/softmmu-build"
694 + default
695 + fi
696 +
697 + if [[ -z ${softmmu_targets}${user_targets} ]]; then
698 + cd "${S}/tools-build"
699 + default
700 + fi
701 +}
702 +
703 +src_test() {
704 + if [[ -n ${softmmu_targets} ]]; then
705 + cd "${S}/softmmu-build"
706 + pax-mark m */qemu-system-* #515550
707 + emake -j1 check
708 + emake -j1 check-report.html
709 + fi
710 +}
711 +
712 +qemu_python_install() {
713 + python_domodule "${S}/scripts/qmp/qmp.py"
714 +
715 + python_doscript "${S}/scripts/kvm/kvm_stat"
716 + python_doscript "${S}/scripts/kvm/vmxcap"
717 + python_doscript "${S}/scripts/qmp/qmp-shell"
718 + python_doscript "${S}/scripts/qmp/qemu-ga-client"
719 +}
720 +
721 +src_install() {
722 + if [[ -n ${user_targets} ]]; then
723 + cd "${S}/user-build"
724 + emake DESTDIR="${ED}" install
725 +
726 + # Install binfmt handler init script for user targets
727 + newinitd "${FILESDIR}/qemu-binfmt.initd-r1" qemu-binfmt
728 + fi
729 +
730 + if [[ -n ${softmmu_targets} ]]; then
731 + cd "${S}/softmmu-build"
732 + emake DESTDIR="${ED}" install
733 +
734 + # This might not exist if the test failed. #512010
735 + [[ -e check-report.html ]] && dohtml check-report.html
736 +
737 + if use kernel_linux; then
738 + udev_dorules "${FILESDIR}"/65-kvm.rules
739 + fi
740 +
741 + if use python; then
742 + python_foreach_impl qemu_python_install
743 + fi
744 + fi
745 +
746 + if [[ -z ${softmmu_targets}${user_targets} ]]; then
747 + cd "${S}/tools-build"
748 + emake DESTDIR="${ED}" install
749 + fi
750 +
751 + # Disable mprotect on the qemu binaries as they use JITs to be fast #459348
752 + pushd "${ED}"/usr/bin >/dev/null
753 + pax-mark m "${softmmu_bins[@]}" "${user_bins[@]}"
754 + popd >/dev/null
755 +
756 + # Install config file example for qemu-bridge-helper
757 + insinto "/etc/qemu"
758 + doins "${FILESDIR}/bridge.conf"
759 +
760 + # Remove the docdir placed qmp-commands.txt
761 + mv "${ED}/usr/share/doc/${PF}/html/qmp-commands.txt" "${S}/docs/qmp/"
762 +
763 + cd "${S}"
764 + dodoc Changelog MAINTAINERS docs/specs/pci-ids.txt
765 + newdoc pc-bios/README README.pc-bios
766 + dodoc docs/qmp/*.txt
767 +
768 + if [[ -n ${softmmu_targets} ]]; then
769 + # Remove SeaBIOS since we're using the SeaBIOS packaged one
770 + rm "${ED}/usr/share/qemu/bios.bin"
771 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
772 + dosym ../seabios/bios.bin /usr/share/qemu/bios.bin
773 + fi
774 +
775 + # Remove vgabios since we're using the vgabios packaged one
776 + rm "${ED}/usr/share/qemu/vgabios.bin"
777 + rm "${ED}/usr/share/qemu/vgabios-cirrus.bin"
778 + rm "${ED}/usr/share/qemu/vgabios-qxl.bin"
779 + rm "${ED}/usr/share/qemu/vgabios-stdvga.bin"
780 + rm "${ED}/usr/share/qemu/vgabios-vmware.bin"
781 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
782 + dosym ../vgabios/vgabios.bin /usr/share/qemu/vgabios.bin
783 + dosym ../vgabios/vgabios-cirrus.bin /usr/share/qemu/vgabios-cirrus.bin
784 + dosym ../vgabios/vgabios-qxl.bin /usr/share/qemu/vgabios-qxl.bin
785 + dosym ../vgabios/vgabios-stdvga.bin /usr/share/qemu/vgabios-stdvga.bin
786 + dosym ../vgabios/vgabios-vmware.bin /usr/share/qemu/vgabios-vmware.bin
787 + fi
788 +
789 + # Remove sgabios since we're using the sgabios packaged one
790 + rm "${ED}/usr/share/qemu/sgabios.bin"
791 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
792 + dosym ../sgabios/sgabios.bin /usr/share/qemu/sgabios.bin
793 + fi
794 +
795 + # Remove iPXE since we're using the iPXE packaged one
796 + rm "${ED}"/usr/share/qemu/pxe-*.rom
797 + if use qemu_softmmu_targets_x86_64 || use qemu_softmmu_targets_i386; then
798 + dosym ../ipxe/8086100e.rom /usr/share/qemu/pxe-e1000.rom
799 + dosym ../ipxe/80861209.rom /usr/share/qemu/pxe-eepro100.rom
800 + dosym ../ipxe/10500940.rom /usr/share/qemu/pxe-ne2k_pci.rom
801 + dosym ../ipxe/10222000.rom /usr/share/qemu/pxe-pcnet.rom
802 + dosym ../ipxe/10ec8139.rom /usr/share/qemu/pxe-rtl8139.rom
803 + dosym ../ipxe/1af41000.rom /usr/share/qemu/pxe-virtio.rom
804 + fi
805 + fi
806 +
807 + qemu_support_kvm && readme.gentoo_create_doc
808 +}
809 +
810 +pkg_postinst() {
811 + if qemu_support_kvm; then
812 + readme.gentoo_print_elog
813 + fi
814 +
815 + if [[ -n ${softmmu_targets} ]] && use kernel_linux; then
816 + udev_reload
817 + fi
818 +
819 + fcaps cap_net_admin /usr/libexec/qemu-bridge-helper
820 + if use virtfs && [ -n "${softmmu_targets}" ]; then
821 + local virtfs_caps="cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_setgid,cap_mknod,cap_setuid"
822 + fcaps ${virtfs_caps} /usr/bin/virtfs-proxy-helper
823 + fi
824 +}
825 +
826 +pkg_info() {
827 + echo "Using:"
828 + echo " $(best_version app-emulation/spice-protocol)"
829 + echo " $(best_version sys-firmware/ipxe)"
830 + echo " $(best_version sys-firmware/seabios)"
831 + if has_version 'sys-firmware/seabios[binary]'; then
832 + echo " USE=binary"
833 + else
834 + echo " USE=''"
835 + fi
836 + echo " $(best_version sys-firmware/vgabios)"
837 +}