]> xenbits.xensource.com Git - qemu-xen-traditional.git/log
qemu-xen-traditional.git
8 years agocirrus/vnc: zap drop bitblit support from console code. stable-4.5
Gerd Hoffmann [Thu, 9 Mar 2017 11:14:55 +0000 (11:14 +0000)]
cirrus/vnc: zap drop bitblit support from console code.

There is a special code path (dpy_gfx_copy) to allow graphic emulation
notify user interface code about bitblit operations carryed out by
guests.  It is supported by cirrus and vnc server.  The intended purpose
is to optimize display scrolls and just send over the scroll op instead
of a full display update.

This is rarely used these days though because modern guests simply don't
use the cirrus blitter any more.  Any linux guest using the cirrus drm
driver doesn't.  Any windows guest newer than winxp doesn't ship with a
cirrus driver any more and thus uses the cirrus as simple framebuffer.

So this code tends to bitrot and bugs can go unnoticed for a long time.
See for example commit "3e10c3e vnc: fix qemu crash because of SIGSEGV"
which fixes a bug lingering in the code for almost a year, added by
commit "c7628bf vnc: only alloc server surface with clients connected".

Also the vnc server will throttle the frame rate in case it figures the
network can't keep up (send buffers are full).  This doesn't work with
dpy_gfx_copy, for any copy operation sent to the vnc client we have to
send all outstanding updates beforehand, otherwise the vnc client might
run the client side blit on outdated data and thereby corrupt the
display.  So this dpy_gfx_copy "optimization" might even make things
worse on slow network links.

Lets kill it once for all.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
These changes (dropping dpy_copy and all its references and
implementations) reimplemented for qemu-xen-traditional.

This is XSA-211.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Conflicts:
hw/cirrus_vga.c

8 years agocirrus: add blit_is_unsafe call to cirrus_bitblt_cputovideo
Gerd Hoffmann [Wed, 22 Feb 2017 16:25:19 +0000 (16:25 +0000)]
cirrus: add blit_is_unsafe call to cirrus_bitblt_cputovideo

CIRRUS_BLTMODE_MEMSYSSRC blits do NOT check blit destination
and blit width, at all.  Oops.  Fix it.

Security impact: high.

The missing blit destination check allows to write to host memory.
Basically same as CVE-2014-8106 for the other blit variants.

The missing blit width check allows to overflow cirrus_bltbuf,
with the attractive target cirrus_srcptr (current cirrus_bltbuf write
position) being located right after cirrus_bltbuf in CirrusVGAState.

Due to cirrus emulation writing cirrus_bltbuf bytewise the attacker
hasn't full control over cirrus_srcptr though, only one byte can be
changed.  Once the first byte has been modified further writes land
elsewhere.

[ This is CVE-2017-2620 / XSA-209  - Ian Jackson ]

Fixed compilation by removing extra parameter to blit_is_unsafe. -iwj

Reported-by: Gerd Hoffmann <ghoffman@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
(cherry picked from commit 83256b312acfddda34d96e9bba30e93387481091)
(cherry picked from commit b77d58b59ff0688e4aeb933450d07716ca0fb1f2)
(cherry picked from commit 0d5d265f1b81019bff48d2b666032041253f89e9)
(cherry picked from commit b7e9d3976ba48f277da6004311f5025b07a884ea)

8 years agocirrus: fix oob access issue (CVE-2017-2615)
Li Qiang [Mon, 13 Feb 2017 15:22:15 +0000 (15:22 +0000)]
cirrus: fix oob access issue (CVE-2017-2615)

When doing bitblt copy in backward mode, we should minus the
blt width first just like the adding in the forward mode. This
can avoid the oob access of the front of vga's vram.

This is XSA-208.

upstream-commit-id: 62d4c6bd5263bb8413a06c80144fc678df6dfb64

Signed-off-by: Li Qiang <liqiang6-s@360.cn>
{ kraxel: with backward blits (negative pitch) addr is the topmost
          address, so check it as-is against vram size ]

[ This is CVE-2017-2615 / XSA-208  - Ian Jackson ]

Cc: qemu-stable@nongnu.org
Cc: P J P <ppandit@redhat.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Wolfgang Bumiller <w.bumiller@proxmox.com>
Fixes: d3532a0db02296e687711b8cdc7791924efccea0 (CVE-2014-8106)
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-id: 1485938101-26602-1-git-send-email-kraxel@redhat.com
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
(cherry picked from commit c4018bc4d638918b3f8fb49dd3b379abb5658ee1)
(cherry picked from commit a1d57bb66d5f7e3a86e47c01431c823e217b23ab)
(cherry picked from commit a20cf3a6edd051f2f2eb734a7bcda6c6246740ff)
(cherry picked from commit d0360192b805d13353b0bb100fe0cf927a2861e7)

8 years agoqemu: ioport_read, ioport_write: be defensive about 32-bit addresses
Ian Jackson [Mon, 14 Nov 2016 17:19:46 +0000 (17:19 +0000)]
qemu: ioport_read, ioport_write: be defensive about 32-bit addresses

On x86, ioport addresses are 16-bit.  That these functions take 32-bit
arguments is a mistake.  Changing the argument type to 16-bit will
discard the top bits of any erroneous values from elsewhere in qemu.

Also, check just before use that the value is in range.  (This turns
an ill-advised change to MAX_IOPORTS into a possible guest crash
rather than a privilege escalation vulnerability.)

And, in the Xen ioreq processor, clamp incoming ioport addresses to
16-bit values.  Xen will never write >16-bit values but the guest may
have access to the ioreq ring.  We want to defend the rest of the qemu
code from wrong values.

This is XSA-199.

Reported-by: yanghongke <yanghongke@huawei.com>
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
(cherry picked from commit b669e922b37b8957248798a5eb7aa96a666cd3fe)
(cherry picked from commit 095261a9ad5c31b9ed431f8382e8aa223089c85b)
(cherry picked from commit 18858e28bb6bae83ddcf413995b2e68c4c7ae03d)
(cherry picked from commit a7fd3717d99944530b04130f050e83402e64afed)

8 years agoxen: fix ioreq handling
Jan Beulich [Tue, 29 Nov 2016 18:38:24 +0000 (18:38 +0000)]
xen: fix ioreq handling

Avoid double fetches and bounds check size to avoid overflowing
internal variables.

This is XSA-197.

Reported-by: yanghongke <yanghongke@huawei.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Ian Jackson <ian.jackson@eu.citrix.com>
8 years agovirtio: error out if guest exceeds virtqueue size
P J P [Tue, 26 Jul 2016 14:31:59 +0000 (15:31 +0100)]
virtio: error out if guest exceeds virtqueue size

A broken or malicious guest can submit more requests than the virtqueue
size permits.

The guest can submit requests without bothering to wait for completion
and is therefore not bound by virtqueue size.  This requires reusing
vring descriptors in more than one request, which is incorrect but
possible.  Processing a request allocates a VirtQueueElement and
therefore causes unbounded memory allocation controlled by the guest.

Exit with an error if the guest provides more requests than the
virtqueue size permits.  This bounds memory allocation and makes the
buggy guest visible to the user.

Reported-by: Zhenhao Hong <zhenhaohong@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit c4e0d84d3c92923fdbc7fa922638d54e5e834753)
(cherry picked from commit 81111451256fd2f77c361fe65fa591743dbf04db)
(cherry picked from commit cff044b5c8bf51d9c9f3f9439671ed378857928a)

8 years agomain loop: Big hammer to fix logfile disk DoS in Xen setups xen-4.5.5
Ian Jackson [Thu, 19 May 2016 18:38:35 +0000 (19:38 +0100)]
main loop: Big hammer to fix logfile disk DoS in Xen setups

Each time round the main loop, we now fstat stderr.  If it is too big,
we dup2 /dev/null onto it.  This is not a very pretty patch but it is
very simple, easy to see that it's correct, and has a low risk of
collateral damage.

There is no limit by default but can be adjusted by setting a new
environment variable.

This is part of CVE-2014-3672.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Tested-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Set the default to 0 so that it won't affect non-xen installation. The
limit will be set by Xen toolstack.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
(ad-hoc cherry-pick from 44a072f0de0d57c95c2212bbce02888832b7b74f)
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
(cherry picked from commit 6e20809727261599e8527c456eb078c0e89139a1)
(cherry picked from commit 698d6d6f8d095edadb0c23612b552a89dd3eee4c)
(cherry picked from commit 29b39dac29529b9989e4f597adb354f7879b6f63)

8 years agoFix build with newer version of GNUTLS
Wei Liu [Thu, 5 May 2016 10:14:44 +0000 (11:14 +0100)]
Fix build with newer version of GNUTLS

gnutls_kx_set_priority, gnutls_certificate_type_set_priority and
gnutls_protocol_set_priority were deprecated and eventually removed in
GNUTLS 3.4. Application should use gnutls_priority_set_direct instead
per [0].

gnutls_anon_server_credentials was deprecated at some point. Application
should use gnutls_anon_server_credentials_t instead.

Provide compatibility layer for QEMU traditional. This commit is in fact
backport of two upstream QEMU commits:
1. f40d55081667a716312b9a8b6e13835c4074f56b
2. 7d2a929feba319c18603e324b1750830d6c8b7a1

[0] https://www.gnutls.org/manual/html_node/Upgrading-from-previous-versions.html

Signed-off-by: Sjoer van der Ploeg <sfjuocekr@gmail.com>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Tested-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
(cherry picked from commit df553c056104e3dd8a2bd2e72539a57c4c085bae)
(cherry picked from commit cb629cb5fe8553c357cc6d0ef069ebcd9eb27676)

8 years agortl8139: check TCP Data Offset field
Stefan Hajnoczi [Wed, 15 Jul 2015 17:17:04 +0000 (18:17 +0100)]
rtl8139: check TCP Data Offset field

The TCP Data Offset field contains the length of the header.  Make sure
it is valid and does not exceed the IP data length.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
[Backport to qemu-xen-tradition]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agortl8139: skip offload on short TCP header
Stefan Hajnoczi [Wed, 15 Jul 2015 17:17:03 +0000 (18:17 +0100)]
rtl8139: skip offload on short TCP header

TCP Large Segment Offload accesses the TCP header in the packet.  If the
packet is too short we must not attempt to access header fields:

  tcp_header *p_tcp_hdr = (tcp_header*)(eth_payload_data + hlen);
  int tcp_hlen = TCP_HEADER_DATA_OFFSET(p_tcp_hdr);

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
[Backport to qemu-xen-tradition]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agortl8139: check IP Total Length field
Stefan Hajnoczi [Wed, 15 Jul 2015 17:17:02 +0000 (18:17 +0100)]
rtl8139: check IP Total Length field

The IP Total Length field includes the IP header and data.  Make sure it
is valid and does not exceed the Ethernet payload size.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
[Backport to qemu-xen-tradition]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agortl8139: check IP Header Length field
Stefan Hajnoczi [Wed, 15 Jul 2015 17:17:01 +0000 (18:17 +0100)]
rtl8139: check IP Header Length field

The IP Header Length field was only checked in the IP checksum case, but
is used in other cases too.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
[Backport to qemu-xen-tradition]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agortl8139: skip offload on short Ethernet/IP header
Stefan Hajnoczi [Wed, 15 Jul 2015 17:17:00 +0000 (18:17 +0100)]
rtl8139: skip offload on short Ethernet/IP header

Transmit offload features access Ethernet and IP headers the packet.  If
the packet is too short we must not attempt to access header fields:

  int proto = be16_to_cpu(*(uint16_t *)(saved_buffer + 12));
  ...
  eth_payload_data = saved_buffer + ETH_HLEN;
  ...
  ip = (ip_header*)eth_payload_data;
  if (IP_HEADER_VERSION(ip) != IP_HEADER_VERSION_4) {

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
[Backport to qemu-xen-tradition]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agortl8139: drop tautologous if (ip) {...} statement
Stefan Hajnoczi [Wed, 15 Jul 2015 17:16:59 +0000 (18:16 +0100)]
rtl8139: drop tautologous if (ip) {...} statement

The previous patch stopped using the ip pointer as an indicator that the
IP header is present.  When we reach the if (ip) {...} statement we know
ip is always non-NULL.

Remove the if statement to reduce nesting.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
[Backport to qemu-xen-tradition]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agortl8139: avoid nested ifs in IP header parsing
Stefan Hajnoczi [Wed, 15 Jul 2015 17:16:58 +0000 (18:16 +0100)]
rtl8139: avoid nested ifs in IP header parsing

Transmit offload needs to parse packet headers.  If header fields have
unexpected values the offload processing is skipped.

The code currently uses nested ifs because there is relatively little
input validation.  The next patches will add missing input validation
and a goto label is more appropriate to avoid deep if statement nesting.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
[Backport to qemu-xen-tradition]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agovga: make sure vga register setup for vbe stays intact (CVE-2016-3712).
Gerd Hoffmann [Tue, 26 Apr 2016 12:48:06 +0000 (14:48 +0200)]
vga: make sure vga register setup for vbe stays intact (CVE-2016-3712).

Call vbe_update_vgaregs() when the guest touches GFX, SEQ or CRT
registers, to make sure the vga registers will always have the
values needed by vbe mode.  This makes sure the sanity checks
applied by vbe_fixup_regs() are effective.

Without this guests can muck with shift_control, can turn on planar
vga modes or text mode emulation while VBE is active, making qemu
take code paths meant for CGA compatibility, but with the very
large display widths and heigts settable using VBE registers.

Which is good for one or another buffer overflow.  Not that
critical as they typically read overflows happening somewhere
in the display code.  So guests can DoS by crashing qemu with a
segfault, but it is probably not possible to break out of the VM.

Fixes: CVE-2016-3712
Reported-by: Zuozhi Fzz <zuozhi.fzz@alibaba-inc.com>
Reported-by: P J P <ppandit@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
[Backport to qemu-xen-tradition]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agovga: update vga register setup on vbe changes
Gerd Hoffmann [Tue, 26 Apr 2016 13:39:22 +0000 (15:39 +0200)]
vga: update vga register setup on vbe changes

Call the new vbe_update_vgaregs() function on vbe configuration
changes, to make sure vga registers are up-to-date.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
[Backport to qemu-xen-tradition]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agovga: factor out vga register setup
Gerd Hoffmann [Tue, 26 Apr 2016 13:24:18 +0000 (15:24 +0200)]
vga: factor out vga register setup

When enabling vbe mode qemu will setup a bunch of vga registers to make
sure the vga emulation operates in correct mode for a linear
framebuffer.  Move that code to a separate function so we can call it
from other places too.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
[Backport to qemu-xen-tradition]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agovga: add vbe_enabled() helper
Gerd Hoffmann [Tue, 26 Apr 2016 12:11:34 +0000 (14:11 +0200)]
vga: add vbe_enabled() helper

Makes code a bit easier to read.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
[Backport to qemu-xen-tradition]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agovga: fix banked access bounds checking (CVE-2016-3710)
Gerd Hoffmann [Tue, 26 Apr 2016 06:49:10 +0000 (08:49 +0200)]
vga: fix banked access bounds checking (CVE-2016-3710)

vga allows banked access to video memory using the window at 0xa00000
and it supports a different access modes with different address
calculations.

The VBE bochs extentions support banked access too, using the
VBE_DISPI_INDEX_BANK register.  The code tries to take the different
address calculations into account and applies different limits to
VBE_DISPI_INDEX_BANK depending on the current access mode.

Which is probably effective in stopping misprogramming by accident.
But from a security point of view completely useless as an attacker
can easily change access modes after setting the bank register.

Drop the bogus check, add range checks to vga_mem_{readb,writeb}
instead.

Fixes: CVE-2016-3710
Reported-by: Qinghao Tang <luodalongde@gmail.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
[Backport to qemu-xen-tradition]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agoCVE-2014-3615: vbe: rework sanity checks
Andrew Cooper [Sun, 22 Feb 2015 19:21:08 +0000 (19:21 +0000)]
CVE-2014-3615: vbe: rework sanity checks

Backport of qemu-upstream:
 * c1b886c45dc70f247300f549dce9833f3fa2def5

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agoCVE-2014-7815: vnc: sanitize bits_per_pixel from the client
Andrew Cooper [Sat, 21 Feb 2015 19:21:11 +0000 (19:21 +0000)]
CVE-2014-7815: vnc: sanitize bits_per_pixel from the client

Backport of qemu-upstream:
 * e6908bfe8e07f2b452e78e677da1b45b1c0f6829

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agoCVE-2014-8106: cirrus: fix blit region check
Andrew Cooper [Sat, 21 Feb 2015 17:16:42 +0000 (17:16 +0000)]
CVE-2014-8106: cirrus: fix blit region check

Backport of qemu-upstream:
 * bf25983345ca44aec3dd92c57142be45452bd38a
 * d3532a0db02296e687711b8cdc7791924efccea0

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
8 years agousb-linux.c: fix buffer overflow
Jim Paris [Wed, 22 Apr 2015 11:29:21 +0000 (12:29 +0100)]
usb-linux.c: fix buffer overflow

In usb-linux.c:usb_host_handle_control, we pass a 1024-byte buffer and
length to the kernel.  However, the length was provided by the caller
of dev->handle_packet, and is not checked, so the kernel might provide
too much data and overflow our buffer.

For example, hw/usb-uhci.c could set the length to 2047.
hw/usb-ohci.c looks like it might go up to 4096 or 8192.

This causes a qemu crash, as reported here:
  http://www.mail-archive.com/kvm@vger.kernel.org/msg18447.html

This patch increases the usb-linux.c buffer size to 2048 to fix the
specific device reported, and adds a check to avoid the overflow in
any case.

Signed-off-by: Jim Paris <jim@jtan.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
9 years agoMSI-X: avoid array overrun upon MSI-X table writes xen-4.5.3
Jan Beulich [Mon, 4 Jan 2016 15:34:29 +0000 (15:34 +0000)]
MSI-X: avoid array overrun upon MSI-X table writes

pt_msix_init() allocates msix->msix_entry[] to just cover
msix->total_entries entries. While pci_msix_readl() resorts to reading
physical memory for out of bounds reads, pci_msix_writel() so far
simply accessed/corrupted unrelated memory.

pt_iomem_map()'s call to cpu_register_physical_memory() registers a
page granular region, which is necessary as the Pending Bit Array may
share space with the MSI-X table (but nothing else is allowed to). This
also explains why pci_msix_readl() actually honors out of bounds reads,
but pci_msi_writel() doesn't need to.

This is XSA-164.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
(cherry picked from commit 569eac99e8ddccd15fe78e8a3af5622afe780e3b)
(cherry picked from commit 7457f4beae2583a106a4176949514e81248fc22d)

9 years agoblkif: Avoid double access to src->nr_segments
Stefano Stabellini [Fri, 20 Nov 2015 15:56:00 +0000 (10:56 -0500)]
blkif: Avoid double access to src->nr_segments

src is stored in shared memory and src->nr_segments is dereferenced
twice at the end of the function.  If a compiler decides to compile this
into two separate memory accesses then the size limitation could be
bypassed.

Fix it by removing the double access to src->nr_segments.

This is part of XSA-155.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
9 years agoxenfb: avoid reading twice the same fields from the shared page
Stefano Stabellini [Fri, 20 Nov 2015 15:37:08 +0000 (10:37 -0500)]
xenfb: avoid reading twice the same fields from the shared page

Reading twice the same field could give the guest an attack of
opportunity. In the case of event->type, gcc could compile the switch
statement into a jump table, effectively ending up reading the type
field multiple times.

This is part of XSA-155.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
9 years agonet: pcnet: add check to validate receive data size(CVE-2015-7504)
Ian Jackson [Wed, 9 Dec 2015 11:47:35 +0000 (11:47 +0000)]
net: pcnet: add check to validate receive data size(CVE-2015-7504)

In loopback mode, pcnet_receive routine appends CRC code to the
receive buffer. If the data size given is same as the buffer size,
the appended CRC code overwrites 4 bytes after s->buffer. Added a
check to avoid that.

This is XSA-162.

Reported-by: Qinghao Tang <luodalongde@gmail.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
(cherry picked from commit 91c15bfaec1764ce2896a393eabee1183afe1130)
(cherry picked from commit aaaf657c8f6106da6d7e97ad0d08ed291cc895c7)

9 years agovnc: limit client_cut_text msg payload size xen-4.5.2
Peter Lieven [Mon, 30 Jun 2014 08:07:54 +0000 (10:07 +0200)]
vnc: limit client_cut_text msg payload size

currently a malicious client could define a payload
size of 2^32 - 1 bytes and send up to that size of
data to the vnc server. The server would allocated
that amount of memory which could easily create an
out of memory condition.

This patch limits the payload size to 1MB max.

Please note that client_cut_text messages are currently
silently ignored.

Signed-off-by: Peter Lieven <pl@kamp.de>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Above is f9a70e79391f in qemu upstream.

Cherry picked onto in qemu-xen-4.6-testing and qemu-xen-unstable:

Conflicts:
ui/vnc.c
Dropped { } style changes.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Above is 2b5684137e81 in qemu-xen-4.6-testing and qemu-xen-unstable,
now being cherry picked onto qemu-xen-4.5-testing.  Also need
1c8d43cbdf0f, its fixup patch:

We do not have `error_report'.  Use fprintf to stderr, like the rest
of the file.

Fix commit message to refer to vnc.c, not ui/vnc.c.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
9 years agoide: Clear DRQ after handling all expected accesses
Kevin Wolf [Wed, 3 Jun 2015 12:41:27 +0000 (14:41 +0200)]
ide: Clear DRQ after handling all expected accesses

This is additional hardening against an end_transfer_func that fails to
clear the DRQ status bit. The bit must be unset as soon as the PIO
transfer has completed, so it's better to do this in a central place
instead of duplicating the code in all commands (and forgetting it in
some).

[ This is XSA-138 / CVE-2015-5154. ]

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 7f057440b31da38196e3398fd1b618fc36ad97d6)

9 years agoide: Check array bounds before writing to io_buffer (CVE-2015-5154)
Kevin Wolf [Wed, 3 Jun 2015 12:13:31 +0000 (14:13 +0200)]
ide: Check array bounds before writing to io_buffer (CVE-2015-5154)

If the end_transfer_func of a command is called because enough data has
been read or written for the current PIO transfer, and it fails to
correctly call the command completion functions, the DRQ bit in the
status register and s->end_transfer_func may remain set. This allows the
guest to access further bytes in s->io_buffer beyond s->data_end, and
eventually overflowing the io_buffer.

One case where this currently happens is emulation of the ATAPI command
START STOP UNIT.

This patch fixes the problem by adding explicit array bounds checks
before accessing the buffer instead of relying on end_transfer_func to
function correctly.

[ This is XSA-138 / CVE-2015-5154. ]

Cc: qemu-stable@nongnu.org
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit d18ac5938d38ed9a9d51e380a2baf8343468f65d)

9 years agopcnet: force the buffer access to be in bounds during tx
Petr Matousek [Sun, 24 May 2015 08:53:44 +0000 (10:53 +0200)]
pcnet: force the buffer access to be in bounds during tx

4096 is the maximum length per TMD and it is also currently the size of
the relay buffer pcnet driver uses for sending the packet data to QEMU
for further processing. With packet spanning multiple TMDs it can
happen that the overall packet size will be bigger than sizeof(buffer),
which results in memory corruption.

Fix this by only allowing to queue maximum sizeof(buffer) bytes.

This is CVE-2015-3209.

Signed-off-by: Petr Matousek <pmatouse@redhat.com>
Reported-by: Matt Tait <matttait@google.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years agopcnet: fix Negative array index read
Gonglei [Tue, 23 Jun 2015 10:21:49 +0000 (11:21 +0100)]
pcnet: fix Negative array index read

s->xmit_pos maybe assigned to a negative value (-1),
but in this branch variable s->xmit_pos as an index to
array s->buffer. Let's add a check for s->xmit_pos.

upstream-commit-id: 7b50d00911ddd6d56a766ac5671e47304c20a21b

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9 years ago... by default. Add a per-device "permissive" mode similar to pciback's xen-4.5.1
Jan Beulich [Tue, 9 Jun 2015 15:32:24 +0000 (16:32 +0100)]
... by default. Add a per-device "permissive" mode similar to pciback's
to allow restoring previous behavior (and hence break security again,
i.e. should be used only for trusted guests).

This is part of XSA-131.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>)
9 years agoSince the next patch will turn all not explicitly described fields
Jan Beulich [Tue, 9 Jun 2015 15:32:24 +0000 (16:32 +0100)]
Since the next patch will turn all not explicitly described fields
read-only by default, those fields that have guest writable bits need
to be given explicit descriptors.

This is a preparatory patch for XSA-131.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
9 years agoThe adjustments are solely to make the subsequent patches work right
Jan Beulich [Tue, 9 Jun 2015 15:32:24 +0000 (16:32 +0100)]
The adjustments are solely to make the subsequent patches work right
(and hence make the patch set consistent), namely if permissive mode
(introduced by the last patch) gets used (as both reserved registers
and reserved fields must be similarly protected from guest access in
default mode, but the guest should be allowed access to them in
permissive mode).

This is a preparatory patch for XSA-131.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
9 years agoxen_pt_emu_reg_pcie[]'s PCI_EXP_DEVCAP needs to cover all bits as read-
Jan Beulich [Tue, 9 Jun 2015 15:32:24 +0000 (16:32 +0100)]
xen_pt_emu_reg_pcie[]'s PCI_EXP_DEVCAP needs to cover all bits as read-
only to avoid unintended write-back (just a precaution, the field ought
to be read-only in hardware).

This is a preparatory patch for XSA-131.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
9 years agoThis is just to avoid having to adjust that calculation later in
Jan Beulich [Tue, 9 Jun 2015 15:32:24 +0000 (16:32 +0100)]
This is just to avoid having to adjust that calculation later in
multiple places.

Note that including ->ro_mask in get_throughable_mask()'s calculation
is only an apparent (i.e. benign) behavioral change: For r/o fields it
doesn't matter > whether they get passed through - either the same flag
is also set in emu_mask (then there's no change at all) or the field is
r/o in hardware (and hence a write won't change it anyway).

This is a preparatory patch for XSA-131.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
9 years agoxen_pt_pmcsr_reg_write() needs an adjustment to deal with the RW1C
Jan Beulich [Tue, 9 Jun 2015 15:32:24 +0000 (16:32 +0100)]
xen_pt_pmcsr_reg_write() needs an adjustment to deal with the RW1C
nature of the not passed through bit 15 (PCI_PM_CTRL_PME_STATUS).

This is a preparatory patch for XSA-131.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
9 years agoThere's no point in xen_pt_pmcsr_reg_{read,write}() each ORing
Jan Beulich [Tue, 9 Jun 2015 15:32:24 +0000 (16:32 +0100)]
There's no point in xen_pt_pmcsr_reg_{read,write}() each ORing
PCI_PM_CTRL_STATE_MASK and PCI_PM_CTRL_NO_SOFT_RESET into a local
emu_mask variable - we can have the same effect by setting the field
descriptor's emu_mask member suitably right away. Note that
xen_pt_pmcsr_reg_write() is being retained in order to allow later
patches to be less intrusive.

This is a preparatory patch for XSA-131.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
9 years agoWithout this the actual XSA-131 fix would cause the enable bit to not
Jan Beulich [Tue, 9 Jun 2015 15:32:24 +0000 (16:32 +0100)]
Without this the actual XSA-131 fix would cause the enable bit to not
get set anymore (due to the write back getting suppressed there based
on the OR of emu_mask, ro_mask, and res_mask).

Note that the fiddling with the enable bit shouldn't really be done by
qemu, but making this work right (via libxc and the hypervisor) will
require more extensive changes, which can be postponed until after the
security issue got addressed.

This is a preparatory patch for XSA-131.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
9 years ago... to avoid allowing the guest to cause the control domain's disk to
Jan Beulich [Tue, 9 Jun 2015 15:32:19 +0000 (16:32 +0100)]
... to avoid allowing the guest to cause the control domain's disk to
fill.

This is XSA-130.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
9 years agoIt's being used by the hypervisor. For now simply mimic a device not
Jan Beulich [Tue, 9 Jun 2015 15:32:00 +0000 (16:32 +0100)]
It's being used by the hypervisor. For now simply mimic a device not
capable of masking, and fully emulate any accesses a guest may issue
nevertheless as simple reads/writes without side effects.

This is XSA-129.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
9 years agoThe old logic didn't work as intended when an access spanned multiple
Jan Beulich [Tue, 9 Jun 2015 15:31:57 +0000 (16:31 +0100)]
The old logic didn't work as intended when an access spanned multiple
fields (for example a 32-bit access to the location of the MSI Message
Data field with the high 16 bits not being covered by any known field).
Remove it and derive which fields not to write to from the accessed
fields' emulation masks: When they're all ones, there's no point in
doing any host write.

This fixes a secondary issue at once: We obviously shouldn't make any
host write attempt when already the host read failed.

This is XSA-128.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
9 years agofdc: force the fifo access to be in bounds of the allocated buffer xen-4.5.1-rc2
Petr Matousek [Wed, 6 May 2015 07:48:59 +0000 (09:48 +0200)]
fdc: force the fifo access to be in bounds of the allocated buffer

During processing of certain commands such as FD_CMD_READ_ID and
FD_CMD_DRIVE_SPECIFICATION_COMMAND the fifo memory access could
get out of bounds leading to memory corruption with values coming
from the guest.

Fix this by making sure that the index is always bounded by the
allocated memory.

This is XSA-133 / CVE-2015-3456.

Signed-off-by: Petr Matousek <pmatouse@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
(cherry picked from commit 4de1422ea306832b6ef2cba34e9febb73dd139a7)

10 years agoxen: limit guest control of PCI command register xen-4.5.1-rc1
Jan Beulich [Tue, 31 Mar 2015 15:27:45 +0000 (16:27 +0100)]
xen: limit guest control of PCI command register

Otherwise the guest can abuse that control to cause e.g. PCIe
Unsupported Request responses (by disabling memory and/or I/O decoding
and subsequently causing [CPU side] accesses to the respective address
ranges), which (depending on system configuration) may be fatal to the
host.

This is CVE-2015-2756 / XSA-126.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
(cherry picked from commit ab42b4408cb4fc4f869d73218e3d2034e6f5e8ac)

10 years agocirrus: fix an uninitialized variable
Jan Beulich [Mon, 2 Feb 2015 16:49:59 +0000 (16:49 +0000)]
cirrus: fix an uninitialized variable

Noticed by paying attention to a compiler warning (reported for the
only caller of the function modified, vga_ioport_read()).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
(cherry picked from commit a4b276b4ce49c8d70dd841ff885b900ec652b994)

10 years agoqemu-xen-trad: Switch to $(LIBEXEC_BIN) from $(LIBEXEC) xen-4.5.0 xen-4.5.0-rc1
Ian Campbell [Mon, 6 Oct 2014 15:24:46 +0000 (16:24 +0100)]
qemu-xen-trad: Switch to $(LIBEXEC_BIN) from $(LIBEXEC)

The meaning of LIBEXEC in the Xen build system has been made to
follow the more conventional meaning.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
10 years agoqemu-xen-trad: -I tools/libxc/include and tools/xenstore/include
Stefano Stabellini [Fri, 1 Aug 2014 15:32:18 +0000 (16:32 +0100)]
qemu-xen-trad: -I tools/libxc/include and tools/xenstore/include

The public libxc and xenstore headers have been moved to
tools/libxc/include and tools/xenstore/include respectively: change the
Makefiles accordingly.

10 years agoqemu-xen-trad: free all the pirqs for msi/msix when driver unloads
Zhenzhong Duan [Tue, 8 Apr 2014 16:50:06 +0000 (16:50 +0000)]
qemu-xen-trad: free all the pirqs for msi/msix when driver unloads

Pirqs are not freed when driver unloads, then new pirqs are allocated when
driver reloads. This could exhaust pirqs if do it in a loop.

This patch fixes the bug by freeing pirqs when ENABLE bit is cleared in
msi/msix control reg.

There is also other way of fixing it such as reuse pirqs between driver reload,
but this way is better.
Xen-devel: http://marc.info/?l=xen-devel&m=136800120304275&w=2

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
[ This is the qemu-xen-trad version of qemu-xen-upstream
  1d4fd4f0e2fc5dcae0c60e00cc9af95f52988050 -iwj ]

11 years agoqemu-traditional: Fix build warnings on Wheezy xen-4.4.0 xen-4.4.0-rc2 xen-4.4.0-rc3 xen-4.4.0-rc4 xen-4.4.0-rc5 xen-4.4.0-rc6
Andrew Cooper [Wed, 18 Dec 2013 15:25:14 +0000 (15:25 +0000)]
qemu-traditional: Fix build warnings on Wheezy

  CC    i386-dm/eepro100.o
hw/eepro100.c: In function â€˜eepro100_read4’:
hw/eepro100.c:1232:5: warning: â€˜val’ may be used uninitialized in this function [-Wmaybe-uninitialized]
hw/eepro100.c: In function â€˜eepro100_read2’:
hw/eepro100.c:1202:5: warning: â€˜val’ may be used uninitialized in this function [-Wmaybe-uninitialized]
hw/eepro100.c: In function â€˜eepro100_read1’:
hw/eepro100.c:1179:5: warning: â€˜val’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Use ~0 to match the behaviour of real hardware.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
11 years agoxen_disk: fix memory leak xen-4.4.0-rc1
Matthew Daley [Wed, 4 Dec 2013 02:16:18 +0000 (15:16 +1300)]
xen_disk: fix memory leak

On ioreq_release the full ioreq was memset to 0, losing all the data
and memory allocations inside the QEMUIOVector, which leads to a
memory leak. Create a new function to specifically reset ioreq.

Reported-by: Maik Wessler <maik.wessler@yahoo.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Backport to qemu-xen-traditional.

Signed-off-by: Matthew Daley <mattd@bugfuzz.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
11 years agohw/piix4acpi: Make writes to ACPI_DBG_IO_ADDR actually work.
Konrad Rzeszutek Wilk [Mon, 11 Nov 2013 18:42:56 +0000 (13:42 -0500)]
hw/piix4acpi: Make writes to ACPI_DBG_IO_ADDR actually work.

The ACPI AML code has little snippets where it uses two
memory locations to stash debug information when doing PCI
hotplug, such as:

Device (S20)
{
    Name (_ADR, 0x00040000)
    Name (_SUN, 0x04)
    Method (_EJ0, 1, NotSerialized)
    {
Store (0x20, \_GPE.DPT1)
Store (0x88, \_GPE.DPT2)
Store (One, \_GPE.PH20)
    }

    Method (_STA, 0, NotSerialized)
    {
Store (0x20, \_GPE.DPT1)
Store (0x89, \_GPE.DPT2)
    }
}

and DPT1 (and DPT2) is defined as:

OperationRegion ( DG1, SystemIO, 0xb044, 0x04 )
Field ( DG1, ByteAcc, NoLock, Preserve ) {
    DPT1, 8, DPT2, 8
}

But unfortunately when we do the writes they are done
as byte writes, not as 4-byte writes (long). Hence
any debug values are never show in QEMU.

This fixes it so that we can see them in the log file.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
11 years agoqemu-traditional: do not strip binaries during make install
Olaf Hering [Tue, 15 Oct 2013 09:42:26 +0000 (11:42 +0200)]
qemu-traditional: do not strip binaries during make install

It is wrong to strip code during make install, unless explicit
requested. Introduce a new variable INSTALL_PROG and use it along with
an optional STRIP_OPT where currently install -s -m 755 is used.
This is what upstream qemu offers in version 1.6.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
11 years agoqemu-xen-traditional: allow build without blktap1
Ian Campbell [Wed, 31 Jul 2013 15:16:16 +0000 (16:16 +0100)]
qemu-xen-traditional: allow build without blktap1

I intend this to become optional at the xen build level so it needs to become
optional here. Until the matching Xen patch is applied and exports
CONFIG_BLKTAP1=y|n there should be no change.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
11 years agopassthrough: Correctly expose PCH ISA bridge for IGD passthrough
G.R [Thu, 25 Jul 2013 08:11:55 +0000 (08:11 +0000)]
passthrough: Correctly expose PCH ISA bridge for IGD passthrough

The i915 driver probes chip version through PCH ISA bridge device / vendor ID.
Previously, the PCH ISA bridge is exposed as PCI-PCI bridge in qemu-xen-trad,
which breaks the assumption of the driver. This change fixes the issue by
correctly exposing the ISA bridge to domU.

Signed-off-by: Rui Guo <firemeteor@users.sourceforge.net>
Tested-by: Rui Guo <firemeteor@users.sourceforge.net>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Jan Beulich <JBeulich@suse.com>
11 years agoqemu-xen-traditional: disable docs xen-4.3.0
Ian Jackson [Mon, 17 Jun 2013 16:39:51 +0000 (17:39 +0100)]
qemu-xen-traditional: disable docs

Perl 5.18 is unhappy with the qemu-xen-traditional documents, giving
this error:
  qemu.pod around line 91: Non-ASCII character seen before =encoding in
  'Schuetz.'. Assuming UTF-8 POD document had syntax errors at /usr/bin/core_pe\
rl/pod2man line 71.
  make[3]: *** [qemu.1] Error 255

We do not want these docs.  They are not really relevant to Xen users.
So instead of backporting the utf-8 fix from qemu upstream
(3179d694a8dcaa091131e3db644d445c0130713e), we just disable the docs
build.

We do this in xen-hooks.mak because qemu-xen-traditional's configure
script lacks the ability to explicitly disable the docs build.

(The docs build for upstream-based qemu-xen was already disabled by
xen.git#a0d110801d701c43e7b8c73dbd6b2444a10a7cdb)

Reported-by: jacek burghardt <jaceksburghardt@gmail.com>
Acked-by: George Dunlap <george.dunlap@eu.citrix.com> (re 4.3 release)
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
11 years agoSigned-off-by: Olaf Hering <olaf@aepfle.de>
Ian Jackson [Tue, 21 May 2013 13:57:23 +0000 (14:57 +0100)]
Signed-off-by: Olaf Hering <olaf@aepfle.de>
CC: Eric Shelton <eshelton@pobox.com>
CC: Matt Wilson <msw@amazon.com>
CC: Stefano Stabellini <Stefano.Stabellini@eu.citrix.com>
Acked-by: George Dunlap <george.dunlap@eu> (for 4.3 release)
11 years agopiix4acpi, xen, hotplug: Fix race with ACPI AML code and hotplug.
Konrad Rzeszutek Wilk [Tue, 14 May 2013 17:48:49 +0000 (18:48 +0100)]
piix4acpi, xen, hotplug: Fix race with ACPI AML code and hotplug.

This is a race so the amount varies but on a 4PCPU box
I seem to get only ~14 out of 16 vCPUs I want to online.

The issue at hand is that QEMU xenstore.c hotplug code changes
the vCPU array and triggers an ACPI SCI for each vCPU
online/offline change. That means we modify the array of vCPUs
as the guests ACPI AML code is reading it - resulting in
the guest reading the data only once and not changing the
CPU states appropiately.

The fix is to seperate the vCPU array changes from the ACPI SCI
notification. The code now will enumerate all of the vCPUs
and change the vCPU array if there is a need for a change.
If a change did occur then only _one_ ACPI SCI pulse is sent
to the guest. The vCPU array at that point has the online/offline
modified to what the user wanted to have.

Specifically, if a user provided this command:
 xl vcpu-set latest 16

(guest config has vcpus=1, maxvcpus=32) QEMU and the guest
(in this case Linux) would do:

QEMU:                                           Guest OS:
-xenstore_process_vcpu_set_event
 -> Gets an XenBus notification for CPU1
 -> Updates the gpe_state.cpus_state bitfield.
        -> Pulses the ACPI SCI
                                                - ACPI SCI kicks in

 -> Gets an XenBus notification for CPU2
 -> Updates the gpe_state.cpus_state bitfield.
        -> Pulses the ACPI SCI

 -> Gets an XenBus notification for CPU3
 -> Updates the gpe_state.cpus_state bitfield.
        -> Pulses the ACPI SCI
   ...
                                                 - Method(PRST) invoked

 -> Gets an XenBus notification for CPU12
 -> Updates the gpe_state.cpus_state bitfield.
        -> Pulses the ACPI SCI
                                                  - reads AF00 for CPU state
                                                    [gets 0xff]
                                                  - reads AF02 [gets 0x7f]

 -> Gets an XenBus notification for CPU13
 -> Updates the gpe_state.cpus_state bitfield.
        -> Pulses the ACPI SCI

        .. until VCPU 16
                                                 - Method PRST updates
                                                   PR01 through 13 FLG
                                                   entry.
                                                 - PR01->PR13 _MAD
                                                   invoked.

                                                 - Brings up 13 CPUs.

While QEMU updates the rest of the cpus_state bitfields the ACPI AML
only does the CPU hotplug on those it had read.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: George Dunlap <george.dunlap@eu.citrix.com> (for 4.3 release)
11 years agopiix4acpi, xen: Clarify that the qemu_set_irq calls just do an IRQ pulse.
Konrad Rzeszutek Wilk [Tue, 14 May 2013 17:48:48 +0000 (18:48 +0100)]
piix4acpi, xen: Clarify that the qemu_set_irq calls just do an IRQ pulse.

The "qemu_cpu_notify" raises and lowers the ACPI SCI line when the
vCPU state has changed.

Instead of doing the two functions, just use one function that
describes exactly what it does.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: George Dunlap <george.dunlap@eu.citrix.com> (for 4.3 release)
11 years agopiix4acpi, xen, vcpu hotplug: Split the notification from the changes.
Konrad Rzeszutek Wilk [Tue, 14 May 2013 17:48:47 +0000 (18:48 +0100)]
piix4acpi, xen, vcpu hotplug: Split the notification from the changes.

This is a prepatory patch that splits the notification
of an vCPU change from the actual changes to the vCPU array.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: George Dunlap <george.dunlap@eu.citrix.com> (for 4.3 release)
12 years agoxen: Disable use of O_DIRECT by default as it results in crashes. xen-4.3.0-rc1
Alex Bligh [Fri, 15 Mar 2013 18:25:15 +0000 (18:25 +0000)]
xen: Disable use of O_DIRECT by default as it results in crashes.

Due to what is almost certainly a kernel bug, writes with O_DIRECT may
continue to reference the page after the write has been marked as
completed, particularly in the case of TCP retransmit. In other
scenarios, this "merely" risks data corruption on the write, but with
Xen pages from domU are only transiently mapped into dom0's memory,
resulting in kernel panics when they are subsequently accessed.

This brings PV devices in line with emulated devices.  Removing
O_DIRECT is safe as barrier operations are now correctly passed
through.

See:
  http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html
for more details.

Signed-off-by: Alex Bligh <alex@alex.org.uk>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Backported to qemu-xen-unstable,
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
12 years agoRevert "passthrough: Correctly expose PCH ISA bridge for IGD passthrough"
Ian Jackson [Mon, 25 Feb 2013 16:44:20 +0000 (16:44 +0000)]
Revert "passthrough: Correctly expose PCH ISA bridge for IGD passthrough"

This reverts commit bd9e97271db5edc07e3e0d45bdf6ccd5a9bba3de.

Revert-requested-by: Jan Beulich <JBeulich@suse.com>
12 years agopassthrough: Correctly expose PCH ISA bridge for IGD passthrough
Ian Jackson [Fri, 22 Feb 2013 18:04:40 +0000 (18:04 +0000)]
passthrough: Correctly expose PCH ISA bridge for IGD passthrough

Fix IGD passthrough logic to properly expose PCH ISA bridge (instead
of exposing as pci-pci bridge). The i915 driver require this to
correctly detect the PCH version and enable version specific code
path.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Timothy Guo <firemeteor@users.sourceforge.net>
12 years agoqemu-xen-trad/pt_msi_disable: do not clear all MSI flags
Stefano Stabellini [Mon, 10 Dec 2012 12:43:33 +0000 (12:43 +0000)]
qemu-xen-trad/pt_msi_disable: do not clear all MSI flags

"qemu-xen-trad: fix msi_translate with PV event delivery" added a
pt_msi_disable() call into pt_msgctrl_reg_write, clearing the MSI flags
as a consequence. MSIs get enabled again soon after by calling
pt_msi_setup.

However the MSI flags are only setup once in the pt_msgctrl_reg_init
function, so from the QEMU point of view the device has lost some
important properties, like for example PCI_MSI_FLAGS_64BIT.

This patch fixes the bug by clearing only the MSI
enabled/mapped/initialized flags in pt_msi_disable.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Tested-by: G.R. <firemeteor@users.sourceforge.net>
Xen-devel: http://marc.info/?l=xen-devel&m=135489879503075

12 years agocpu_ioreq_pio, cpu_ioreq_move: introduce read_phys_req_item, write_phys_reqm
Ian Jackson [Wed, 20 Feb 2013 15:40:13 +0000 (15:40 +0000)]
cpu_ioreq_pio, cpu_ioreq_move: introduce read_phys_req_item, write_phys_reqm

The current code compare i (int) with req->count (uint32_t) in a for
loop, risking an infinite loop if req->count is >INT_MAX.  It also
does the multiplication of req->size in a too-small type, leading to
integer overflows.

Turn read_physical and write_physical into two different helper
functions, read_phys_req_item and write_phys_req_item, that take care
of adding or subtracting offset depending on sign.

This removes the formulaic multiplication to a single place where the
integer overflows can be dealt with by casting to wide-enough unsigned
types.

Reported-By: Dongxiao Xu <dongxiao.xu@intel.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Tested-by: Dongxiao Xu <dongxiao.xu@intel.com>
12 years agoe1000: fix compile warning introduced by security fix, and debugging
Ian Jackson [Thu, 17 Jan 2013 15:52:16 +0000 (15:52 +0000)]
e1000: fix compile warning introduced by security fix, and debugging

e33f918c19e393900b95a2bb6b10668dfe96a8f2, the fix for XSA-41,
and its cherry picks in 4.2 and 4.1 introduced this compiler warning:
  hw/e1000.c:641: warning: 'return' with a value, in function returning void

In upstream qemu (where this change came from), e1000_receive returns
a value used by queueing machinery to decide whether to try
resubmitting the packet later.  Returning "size" means that the packet
has been dealt with and should not be retried.

In this old branch (aka qemu-xen-traditional), this machinery is
absent and e1000_receive returns void.  Fix the return statement.

Also add a debugging statement along the lines of the others in this
function.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
12 years agoe1000: Discard oversized packets based on SBP|LPE
Michael Contreras [Wed, 5 Dec 2012 18:31:30 +0000 (13:31 -0500)]
e1000: Discard oversized packets based on SBP|LPE

Discard packets longer than 16384 when !SBP to match the hardware behavior.

Signed-off-by: Michael Contreras <michael@inetric.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit 2c0331f4f7d241995452b99afaf0aab00493334a)
[ This is a security vulnerablity, XSA-41 / CVE-2012-6075 (2nd patch). ]

12 years agoe1000: Discard packets that are too long if !SBP and !LPE
Michael Contreras [Mon, 3 Dec 2012 04:11:22 +0000 (20:11 -0800)]
e1000: Discard packets that are too long if !SBP and !LPE

The e1000_receive function for the e1000 needs to discard packets longer than
1522 bytes if the SBP and LPE flags are disabled. The linux driver assumes
this behavior and allocates memory based on this assumption.

Signed-off-by: Michael Contreras <michael@inetric.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
[ This is a security vulnerability, CVE-2012-6075 / XSA-41. ]

12 years agoqemu-stubdom: prevent useless medium change
Roger Pau Monne [Thu, 6 Dec 2012 12:35:58 +0000 (12:35 +0000)]
qemu-stubdom: prevent useless medium change

qemu-stubdom was stripping the prefix from the "params" xenstore
key in xenstore_parse_domain_config, which was then saved stripped in
a variable. In xenstore_process_event we compare the "param" from
xenstore (not stripped) with the stripped "param" saved in the
variable, which leads to a medium change (even if there isn't any),
since we are comparing something like aio:/path/to/file with
/path/to/file. This only happens one time, since
xenstore_parse_domain_config is the only place where we strip the
prefix. The result of this bug is the following:

xs_read_watch() -> /local/domain/0/backend/qdisk/19/5632/params hdc
close(7)
close blk: backend=/local/domain/0/backend/qdisk/19/5632
node=/local/domain/19/device/vbd/5632
(XEN) HVM18: HVM Loader
(XEN) HVM18: Detected Xen v4.3-unstable
(XEN) HVM18: Xenbus rings @0xfeffc000, event channel 4
(XEN) HVM18: System requested ROMBIOS
(XEN) HVM18: CPU speed is 2400 MHz
(XEN) irq.c:270: Dom18 PCI link 0 changed 0 -> 5
(XEN) HVM18: PCI-ISA link 0 routed to IRQ5
(XEN) irq.c:270: Dom18 PCI link 1 changed 0 -> 10
(XEN) HVM18: PCI-ISA link 1 routed to IRQ10
(XEN) irq.c:270: Dom18 PCI link 2 changed 0 -> 11
(XEN) HVM18: PCI-ISA link 2 routed to IRQ11
(XEN) irq.c:270: Dom18 PCI link 3 changed 0 -> 5
(XEN) HVM18: PCI-ISA link 3 routed to IRQ5
(XEN) HVM18: pci dev 01:3 INTA->IRQ10
(XEN) HVM18: pci dev 03:0 INTA->IRQ5
(XEN) HVM18: pci dev 04:0 INTA->IRQ5
(XEN) HVM18: pci dev 02:0 bar 10 size lx: 02000000
(XEN) HVM18: pci dev 03:0 bar 14 size lx: 01000000
(XEN) HVM18: pci dev 02:0 bar 14 size lx: 00001000
(XEN) HVM18: pci dev 03:0 bar 10 size lx: 00000100
(XEN) HVM18: pci dev 04:0 bar 10 size lx: 00000100
(XEN) HVM18: pci dev 04:0 bar 14 size lx: 00000100
(XEN) HVM18: pci dev 01:1 bar 20 size lx: 00000010
(XEN) HVM18: Multiprocessor initialisation:
(XEN) HVM18:  - CPU0 ... 36-bit phys ... fixed MTRRs ... var MTRRs [2/8] ... done.
(XEN) HVM18:  - CPU1 ... 36-bit phys ... fixed MTRRs ... var MTRRs [2/8] ... done.
(XEN) HVM18: Testing HVM environment:
(XEN) HVM18:  - REP INSB across page boundaries ... passed
(XEN) HVM18:  - GS base MSRs and SWAPGS ... passed
(XEN) HVM18: Passed 2 of 2 tests
(XEN) HVM18: Writing SMBIOS tables ...
(XEN) HVM18: Loading ROMBIOS ...
(XEN) HVM18: 9660 bytes of ROMBIOS high-memory extensions:
(XEN) HVM18:   Relocating to 0xfc001000-0xfc0035bc ... done
(XEN) HVM18: Creating MP tables ...
(XEN) HVM18: Loading Cirrus VGABIOS ...
(XEN) HVM18: Loading PCI Option ROM ...
(XEN) HVM18:  - Manufacturer: http://ipxe.org
(XEN) HVM18:  - Product name: iPXE
(XEN) HVM18: Option ROMs:
(XEN) HVM18:  c0000-c8fff: VGA BIOS
(XEN) HVM18:  c9000-d8fff: Etherboot ROM
(XEN) HVM18: Loading ACPI ...
(XEN) HVM18: vm86 TSS at fc00f680
(XEN) HVM18: BIOS map:
(XEN) HVM18:  f0000-fffff: Main BIOS
(XEN) HVM18: E820 table:
(XEN) HVM18:  [00]: 00000000:00000000 - 00000000:0009e000: RAM
(XEN) HVM18:  [01]: 00000000:0009e000 - 00000000:000a0000: RESERVED
(XEN) HVM18:  HOLE: 00000000:000a0000 - 00000000:000e0000
(XEN) HVM18:  [02]: 00000000:000e0000 - 00000000:00100000: RESERVED
(XEN) HVM18:  [03]: 00000000:00100000 - 00000000:3f800000: RAM
(XEN) HVM18:  HOLE: 00000000:3f800000 - 00000000:fc000000
(XEN) HVM18:  [04]: 00000000:fc000000 - 00000001:00000000: RESERVED
(XEN) HVM18: Invoking ROMBIOS ...
(XEN) HVM18: $Revision: 1.221 $ $Date: 2008/12/07 17:32:29 $
(XEN) stdvga.c:147:d18 entering stdvga and caching modes
(XEN) HVM18: VGABios $Id: vgabios.c,v 1.67 2008/01/27 09:44:12 vruppert Exp $
(XEN) HVM18: Bochs BIOS - build: 06/23/99
(XEN) HVM18: $Revision: 1.221 $ $Date: 2008/12/07 17:32:29 $
(XEN) HVM18: Options: apmbios pcibios eltorito PMM
(XEN) HVM18:
(XEN) HVM18: ata0-0: PCHS=16383/16/63 translation=lba LCHS=1024/255/63
(XEN) HVM18: ata0 master: QEMU HARDDISK ATA-7 Hard-Disk (10240 MBytes)
(XEN) HVM18: IDE time out
(XEN) HVM18: ata1 master: QEMU DVD-ROM ATAPI-4 CD-Rom/DVD-Rom
(XEN) HVM18: IDE time out
(XEN) HVM18:
(XEN) HVM18:
(XEN) HVM18:
(XEN) HVM18: Press F12 for boot menu.
(XEN) HVM18:
(XEN) HVM18: Booting from CD-Rom...
(XEN) HVM18: ata_is_ready returned 1
(XEN) HVM18: CDROM boot failure code : 0003
(XEN) HVM18: Boot from CD-Rom failed: could not read the boot disk
(XEN) HVM18:
(XEN) HVM18:
(XEN) HVM18: No bootable device.
(XEN) HVM18: Powering off in 30 seconds.
******************* BLKFRONT for /local/domain/19/device/vbd/5632 **********

backend at /local/domain/0/backend/qdisk/19/5632
Failed to read
/local/domain/0/backend/qdisk/19/5632/feature-flush-cache.
284420 sectors of 512 bytes
**************************
blk_open(/local/domain/19/device/vbd/5632) -> 7

As seen in this trace, the medium change happens just when the
guest is booting, which leads to the guest not being able to boot
because the BIOS is not able to access the device.

This is a regression from Xen 4.1, which is able to boot from "file:/"
based backends when using stubdomains.

[ By inspection, this patch does not change the flow for the
  non-stubdom case. -iwj]

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
12 years agoDisable qemu monitor by default. The qemu monitor is an overly xen-4.2.0 xen-4.2.0-rc4 xen-4.2.0-rc5 xen-4.2.1-rc1
Ian Jackson [Thu, 6 Sep 2012 16:05:30 +0000 (17:05 +0100)]
Disable qemu monitor by default.  The qemu monitor is an overly
powerful feature which must be protected from untrusted (guest)
administrators.

Neither xl nor xend expect qemu to produce this monitor unless it is
explicitly requested.

This is a security problem, XSA-19.  Previously it was CVE-2007-0998
in Red Hat but we haven't dealt with it in upstream.  We hope to have
a new CVE for it here but we don't have one yet.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
12 years agoconsole: bounds check whenever changing the cursor due to an escape code
Ian Campbell [Wed, 5 Sep 2012 11:31:40 +0000 (12:31 +0100)]
console: bounds check whenever changing the cursor due to an escape code

This is XSA-17 / CVE-2012-3515

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
12 years agoqemu-xen-trad: fix msi_translate with PV event delivery
Stefano Stabellini [Thu, 30 Aug 2012 15:11:32 +0000 (16:11 +0100)]
qemu-xen-trad: fix msi_translate with PV event delivery

When switching from msitranslate to straight msi we need to make sure
that we respect PV event delivery for the msi if the guest asked for it:

- completely disable MSI on the device in pt_disable_msi_translate;
- then enable MSI again (pt_msi_setup), mapping the correct pirq to it.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Tested-by: Rolu <rolu@roce.org>
12 years agoRevert "qemu-xen-traditional: use O_DIRECT to open disk images for IDE" xen-4.2.0-rc3
Ian Jackson [Tue, 14 Aug 2012 14:57:49 +0000 (15:57 +0100)]
Revert "qemu-xen-traditional: use O_DIRECT to open disk images for IDE"

This reverts commit 1307e42a4b3c1102d75401bc0cffb4eb6c9b7a38.

In fact after a lengthy discussion, we came up with the conclusion
that WRITEBACK is OK for IDE.
See: http://marc.info/?l=xen-devel&m=133311527009773

Therefore revert this which was committed in error.

12 years agomapcache: Fix invalidate if memory requested was not bucket aligned xen-4.2.0-rc2
Frediano Ziglio [Tue, 7 Aug 2012 17:17:27 +0000 (18:17 +0100)]
mapcache: Fix invalidate if memory requested was not bucket aligned

When memory is mapped in qemu_map_cache with lock != 0 a reverse mapping
is created pointing to the virtual address of location requested.
The cached mapped entry is saved in last_address_vaddr with the memory
location of the base virtual address (without bucket offset).
However when this entry is invalidated the virtual address saved in the
reverse mapping is used. This cause that the mapping is freed but the
last_address_vaddr is not reset.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
12 years agoqemu-traditional: fix no-return-in-nonvoid-function xen-4.2.0-rc1
Olaf Hering [Mon, 23 Jul 2012 16:56:13 +0000 (17:56 +0100)]
qemu-traditional: fix no-return-in-nonvoid-function

rpm post-build-checks found a few issues in qemu-xen-traditional and
marks them as errors.

I: Program returns random data in a function
E: xen no-return-in-nonvoid-function savevm.c:215
E: xen no-return-in-nonvoid-function /usr/src/packages/BUILD/xen-4.2.25602/non-dbg/stubdom/ioemu/xenfbfront.c:361

Signed-off-by: Olaf Hering <olaf@aepfle.de>
12 years agopassthrough: fix off-by-one in PCI config space register index check
Jan Beulich [Fri, 29 Jun 2012 16:06:25 +0000 (17:06 +0100)]
passthrough: fix off-by-one in PCI config space register index check

Register 255 (0xff) is still valid to be accessed.

Reported-by: Rolu <rolu@roce.org>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
12 years agoxendisk: set maximum number of grants to be used
Jan Beulich [Fri, 29 Jun 2012 15:58:05 +0000 (16:58 +0100)]
xendisk: set maximum number of grants to be used

Legacy (non-pvops) gntdev drivers may require this to be done when the
number of grants intended to be used simultaneously exceeds a certain
driver specific default limit.

upstream-commit: 64c27e5b1fdb6d94bdc0bda3b1869d7383a35c65

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
12 years agoxendisk: properly update stats in ioreq_release()
Jan Beulich [Fri, 29 Jun 2012 15:47:34 +0000 (16:47 +0100)]
xendisk: properly update stats in ioreq_release()

While for the "normal" case (called from blk_send_response_all())
decrementing requests_finished is correct, doing so in the parse error
case is wrong; requests_inflight needs to be decremented instead.

upstream-commit: ed5477664369c1e9de23b0e7e8f16a418573bd2a

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
12 years agoqemu-traditional: disable msitranslate by default
Stefano Stabellini [Thu, 28 Jun 2012 14:44:50 +0000 (15:44 +0100)]
qemu-traditional: disable msitranslate by default

msitranslate is known to cause problems with some device drivers,
because it sets the real device in MSI mode while making the guest think
is actually in legacy interrupts mode. Some drivers are able to spot this
inconsistency and break (Nvidia drivers for example).

Disable the option by default.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: George Dunlap <george.dunlap@eu.citrix.com>
12 years agoqemu-xen-trad: fix sys-queue.h usage on BSD systems
Roger Pau Monne [Thu, 7 Jun 2012 18:44:01 +0000 (19:44 +0100)]
qemu-xen-trad: fix sys-queue.h usage on BSD systems

BSD systems already have a sys/queue.h file, which has more macros
than the one Qemu uses, and some header files depend on having that
macros defined (sys/disk.h for example). Disable sys-queue.h on BSD
systems and include the native one.

This is not a backport because the original patch is too dificult to
backport, it's commit 72cf2d4f0e181d0d3a3122e04129c58a95da713e.

Doing a diff -bB shows that the Qemu version is just a stripped
version of the original NetBSD header, with many macros removed, but
no new ones added.

Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
12 years agoqemu-xen-trad/block: get right partition size
Adam Hamsik [Thu, 7 Jun 2012 18:36:26 +0000 (19:36 +0100)]
qemu-xen-trad/block: get right partition size

use the correct way to get the size of a disk device or partition

This this a backport of d1f6fd8d1400ab356aee776b1ecc3ed1e89dbeaa.

From: Adam Hamsik <haad@netbsd.org>
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Backport-requested-by: Roger Pau Monne <roger.pau@citrix.com>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
12 years agoqemu-xen-trad/block: use a character device if a block device is given
Christoph Egger [Thu, 7 Jun 2012 18:35:28 +0000 (19:35 +0100)]
qemu-xen-trad/block: use a character device if a block device is given

On NetBSD a userland process is better with the character device
interface. In addition, a block device can't be opened twice; if a Xen
backend opens it, qemu can't and vice-versa.

This is a backport of 1de1ae0a7d956b3c87712bf2c09d277f99873f4c.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Backport-requested-by: Roger Pau Monne <roger.pau@citrix.com>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
12 years agoxenstore: Use <xenstore.h>
Ian Jackson [Mon, 14 May 2012 16:05:48 +0000 (17:05 +0100)]
xenstore: Use <xenstore.h>

<xs.h> is going away.

This change needs to be made in lockstep with xen-unstable.hg, which
will be done by a change to the QEMU_TAG in the xen-unstable.hg
changeset.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
12 years agopassthrough: Intel GPU passthrough, fix OpRegion mapping
Jean Guyader [Fri, 11 May 2012 11:40:42 +0000 (12:40 +0100)]
passthrough: Intel GPU passthrough, fix OpRegion mapping

The OpRegion shouldn't be mapped 1:1 because the address in the host
can't be used in the guest directly.

This patch traps read and write access to the opregion of the Intel
GPU config space (offset 0xfc).

To work correctly this patch needs a change in hvmloader.

HVMloader will allocate 2 pages for the OpRegion and write this address
on the config space of the Intel GPU. Qemu will trap and map the host
OpRegion to the guest. Any write to this offset after that won't have
any effect. Any read of this config space offset will return the address
in the guest.

Signed-off-by: Jean Guyader <jean.guyader@eu.citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
13 years agotimers: use INT64_MAX as max expiration
Yang Zhang [Tue, 3 Apr 2012 14:44:48 +0000 (15:44 +0100)]
timers: use INT64_MAX as max expiration

Currently, the max expiration time is 2147483647ns(INT32_MAX ns). This
is enough when guest is busy, but when guest is idle, the next timer
will be later than INT32_MAX ns. And those meaningless alarm will harm
the pkg C-state.

PS: Since the overflow will not happen with the expression((delta /
1000) + (delta % 1000 > 0 ? 1 : 0)), so i also removed the comments"
To avoid problems with overflow limit this to 2^32."

Signed-off-by: Yang Zhang <yang.z.zhang@Intel.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
13 years agoxen: introduce an event channel for buffered io event notifications
Stefano Stabellini [Tue, 3 Apr 2012 14:42:39 +0000 (15:42 +0100)]
xen: introduce an event channel for buffered io event notifications

Use the newly [November 2011] introduced HVM_PARAM_BUFIOREQ_EVTCHN to
receive notifications for buffered io events.  After the first
notification is received leave the event channel masked and setup a
timer to process the rest of the batch.  Once we have completed
processing the batch, unmask the event channel and delete the timer.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
13 years agoqemu-xen-traditional: QDISK fixes
Stefano Stabellini [Mon, 2 Apr 2012 16:55:05 +0000 (17:55 +0100)]
qemu-xen-traditional: QDISK fixes

- if ioreq->postsync call bdrv_flush when the operation is actually
  completed;
- do not increment aio_inflight when not submitting any operations.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
13 years agoqemu-xen-traditional: use O_DIRECT to open disk images with QDISK
Stefano Stabellini [Mon, 2 Apr 2012 16:54:36 +0000 (17:54 +0100)]
qemu-xen-traditional: use O_DIRECT to open disk images with QDISK

Also enable batch_maps, use_aio and disable syncwrite.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
13 years agoqemu-xen-traditional: use O_DIRECT to open disk images for IDE
Stefano Stabellini [Mon, 2 Apr 2012 16:54:08 +0000 (17:54 +0100)]
qemu-xen-traditional: use O_DIRECT to open disk images for IDE

[ Major performance fix. -iwj ]

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
13 years agoqemu-traditional/passthrough: adjust MSI-X device cleanup (bug 1809)
Jan Beulich [Mon, 2 Apr 2012 16:35:36 +0000 (17:35 +0100)]
qemu-traditional/passthrough: adjust MSI-X device cleanup (bug 1809)

To address http://bugzilla.xen.org/bugzilla/show_bug.cgi?id=1809,
pt_unregister_regions() also needs to use the newly introduced
_pt_iomem_helper() instead of calling xc_domain_memory_mapping()
directly, to take into consideration the hole created for the MSI-X
table.

For this to work, two calls in unregister_real_device() need to be
swapped, since otherwise we'd have

unregister_real_device()
  -> pt_config_delete()
    -> pt_msix_delete() (frees [and fails to clear] ->msix)
  -> pt_unregister_regions()
    -> _pt_iomem_helper() (with the patch below)
      -> has_msix_mapping() (uses ->msix)

And to be certain to prevent (catch) further/future use-after-free
instances, let's also clear dev->msix in pt_msix_delete().

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Tested-by: Yongjie Ren <yongjie.ren@intel.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
13 years agoqemu-xen: ignore console disconnect events for console/0
Stefano Stabellini [Thu, 1 Mar 2012 18:58:27 +0000 (18:58 +0000)]
qemu-xen: ignore console disconnect events for console/0

The first console has a different location compared to other PV devices
(console, rather than device/console/0) and doesn't obey the xenstore
state protocol. We already special case the first console in con_init
and con_initialise, we should also do it in con_disconnect.

This patch should be applied to 4.1 too.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
13 years agoIntel GPU passthrough: Host bridge config space
Jean Guyader [Mon, 20 Feb 2012 16:21:47 +0000 (16:21 +0000)]
Intel GPU passthrough: Host bridge config space

Expose more host bridge config space value to make the driver happy
for all the different revisions of the device.

Signed-off-by: Jean Guyader <jean.guyader@eu.citrix.com>
13 years agoqemu: Don't access /proc/bus/pci unless graphics pass-thru is enabled
George Dunlap [Mon, 13 Feb 2012 17:00:13 +0000 (17:00 +0000)]
qemu: Don't access /proc/bus/pci unless graphics pass-thru is enabled

A recent changeset introduced a bug whereby an initialization function
that reads /proc/bus/pci is called from graphics set-up functions even
if pass-through graphics are not enabled.  If qemu is run without
permission to this file, this causes qemu to fail during
initialization.

This patch re-works the functions so that the initialization happens
only if we actually need to do the pci host read or write.  It also
makes failures call abort().

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
13 years agoqemu-dm: fix unregister_iomem()
Jan Beulich [Tue, 7 Feb 2012 18:42:56 +0000 (18:42 +0000)]
qemu-dm: fix unregister_iomem()

This function (introduced quite a long time ago in
e7911109f4321e9ba0cc56a253b653600aa46bea - "disable qemu PCI
devices in HVM domains") appears to be completely broken, causing
the regression reported in
http://bugzilla.xensource.com/bugzilla/show_bug.cgi?id=1805 (due to
the newly added caller of it in
56d7747a3cf811910c4cf865e1ebcb8b82502005 - "qemu: clean up
MSI-X table handling"). It's unclear how the function can ever have
fulfilled its purpose: the value returned by iomem_index() is *not* an
index into mmio[].

Additionally, fix two problems:
- unregister_iomem() must not clear mmio[].start, otherwise
  cpu_register_physical_memory() won't be able to re-use the previous
  slot, thus causing a leak
- cpu_unregister_io_memory() must not check mmio[].size, otherwise it
  won't properly clean up entries (temporarily) squashed through
  unregister_iomem()

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Tested-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Tested-by: Yongjie Ren <yongjie.ren@intel.com>
13 years agoe1000: bounds packet size against buffer size
Ian Campbell [Thu, 2 Feb 2012 13:47:06 +0000 (13:47 +0000)]
e1000: bounds packet size against buffer size

Otherwise we can write beyond the buffer and corrupt memory.  This is tracked
as CVE-2012-0029.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
(Backported from qemu upstream 65f82df0d7a71ce1b10cd4c5ab08888d176ac840
 by Ian Campbell.)

Signed-off-by: Ian Campbell <Ian.Campbell@citrix.com>
13 years agoblock-vbd: update to new mini-os wait queue API (new linked list API)
Ian Campbell [Tue, 31 Jan 2012 15:42:38 +0000 (15:42 +0000)]
block-vbd: update to new mini-os wait queue API (new linked list API)

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
13 years agoqemu-xen: adjust MSI-X related log messages
Jan Beulich [Thu, 5 Jan 2012 17:16:46 +0000 (17:16 +0000)]
qemu-xen: adjust MSI-X related log messages

Several of these messages we coded using line continuation within a
string literal. This is generally not recommended and also lead to odd
sequences of many blanks in the middle of the messages.

The message indicating a discarded write due to MSI-X already being
enabled doesn't need to be issued when a write doesn't actually modify
the current value. Adjust the surrounding logic accordingly, and
eliminate some redundancy as well as the sometimes unnecessary access
to the physical MSI-X table.

Finally, adjust the wording of a few messages to be more precise and/or
more useful.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
13 years agoqemu-xen: fix sequence of operations in pt_msix_init()
Jan Beulich [Thu, 5 Jan 2012 17:15:46 +0000 (17:15 +0000)]
qemu-xen: fix sequence of operations in pt_msix_init()

Checking the return value of mmap() must be done before adjusting the
value, otherwise failure may not be detected.

Closing the file handle, on the other hand, can be done before checking
the return value.

Finally, printing the errno value without knowing whether the previous
function actually failed is bogus (and superfluous since a subsequent
message prints the strerror() representaton anyway).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
13 years agoqemu: clean up MSI-X table handling
Ian Jackson [Thu, 22 Dec 2011 14:46:31 +0000 (14:46 +0000)]
qemu: clean up MSI-X table handling

This patch does cleaning up of QEMU MSI handling. The fixes are:
1. Changes made to MSI-X table mapping handling to eliminate the small
windows in which guest could have access to physical MSI-X table.
2. MSI-X table is mapped as read-only to QEMU, as masking of MSI-X is
already in Xen now.
3. For registers that coexists inside the MSI-X table (this could be
only PBA I think), value read from physical page would be returned.

Signed-off-by: Shan Haitao <maillists.shan@gmail.com>
Consolidated duplicate code into _pt_iomem_helper(). Fixed formatting.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Haitao Shan <haitao.shan@intel.com>
Acked-by: Stefano Stabellini <Stefano.Stabellini@eu.citrix.com>