Commit Graph

1295 Commits

Author SHA1 Message Date
Marc-André Lureau
ef89187eff dispatcher: style update
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-23 11:02:22 +01:00
Marc-André Lureau
bba1bf180a server: remove worker thread creation from dispatcher
Acked-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-10-22 17:06:44 +01:00
Marc-André Lureau
15da68dbde server/dispatcher: move worker enums to dispatcher header
Group enums with their respective struct location.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Fabiano Fidêncio <fabiano@fidencio.org>
2015-10-22 10:05:22 +01:00
Marc-André Lureau
31292412c9 worker: use a single clockid
The stat functions in worker are not generic enough to deserve to be
"non-worker", so just pass the worker instance.
2015-10-21 14:12:30 +01:00
Marc-André Lureau
0facd6fc9e server: rename red_client_cache.h to cache_item.tmpl.c
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-20 14:00:25 +01:00
Christophe Fergeau
e5e3e9eefe Add missing license headers 2015-10-19 14:25:36 +02:00
Christophe Fergeau
c61a37603a syntax-check: Remove unused #include <strings.h> 2015-10-19 14:25:36 +02:00
Christophe Fergeau
c0b2b1fc49 syntax-check: Add missing #include <config.h> 2015-10-19 14:25:36 +02:00
Christophe Fergeau
31eb8eeecb syntax-check: Don't use tabs for indentation 2015-10-19 14:25:36 +02:00
Marc-André Lureau
314dfefca3 worker: use GOnce to surround some global init in dispatcher
Acked-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-10-19 13:11:13 +01:00
Marc-André Lureau
b15527e063 server: move some pixmap cache code in own file
Remove that hideous template header that should really be regular code
since it's specialized and instanciated only for pixmap.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-19 13:08:21 +01:00
snir sheriber
c749853d08 fix spelling mistakes in comments (reseting to resetting & dummym to dummy)
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-19 12:59:12 +01:00
Jeremy White
df0eab862c Update the .gitignore files for the new manual,
for a few newly generated tests, and for the spice-server.h.
2015-10-16 15:48:23 -05:00
Marc-André Lureau
1d7b3ad93b Remove DRAW_ALL
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-16 14:11:01 +01:00
Marc-André Lureau
f93bf94c5c Remove PIPE_DEBUG
Acked-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-10-15 18:30:45 +01:00
Marc-André Lureau
dc1e589916 Remove ACYCLIC_SURFACE_DEBUG
Acked-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-10-15 18:30:41 +01:00
Marc-André Lureau
3dffeb25ed Remove unfinished UPDATE_AREA_BY_TREE
Acked-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-10-15 18:30:38 +01:00
Marc-André Lureau
c1d5181396 server: small move to red_channel
Acked-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-10-15 18:30:34 +01:00
Marc-André Lureau
c61404f102 worker: replace init with red_worker_new
Acked-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-10-15 18:30:30 +01:00
Marc-André Lureau
31a66ae6e7 red_worker: replace some abort()
Acked-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-10-15 18:29:47 +01:00
Frediano Ziglio
e60a3beb3c Simplify pointer computation
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-10-12 14:11:22 +01:00
Frediano Ziglio
6e3547f8b1 Prevent leak if size from red_get_data_chunks don't match in red_get_image
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-06 11:11:11 +01:00
Frediano Ziglio
b3be589ab3 Prevent data_size to be set independently from data
There was not check for data_size field so one could set data to
a small set of data and data_size much bigger than size of data
leading to buffer overflow.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-06 11:11:11 +01:00
Frediano Ziglio
2b6695f122 Avoid race condition copying segments in red_get_path
The guest can attempt to increase the number of segments while
spice-server is reading them.
Make sure we don't copy more then the allocated segments.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-10-06 11:11:11 +01:00
Frediano Ziglio
2693e0497e Make sure we can read QXLPathSeg structures
start pointer points to a QXLPathSeg structure.
Before reading from the structure, make sure the structure is contained
in the memory range checked.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-10-06 11:11:11 +01:00
Frediano Ziglio
a447c4f2ac Fix some possible overflows in red_get_string for 32 bit
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-10-06 11:11:11 +01:00
Frediano Ziglio
7d69184037 Prevent DoS from guest trying to allocate too much data on host for chunks
Limit number of chunks to a given amount to avoid guest trying to
allocate too much memory. Using circular or nested chunks lists
guest could try to allocate huge amounts of memory.
Considering the list can be infinite and guest can change data this
also prevents strange security attacks from guest.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-06 11:11:11 +01:00
Frediano Ziglio
f3605979ce Prevent memory leak if red_get_data_chunks_ptr fails
Free linked list if client tries to do nasty things

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-10-06 11:11:11 +01:00
Frediano Ziglio
3738478ed7 Fix race condition in red_get_data_chunks_ptr
Do not read multiple times data from guest as this can be changed by
other guest vcpus. This causes races and security problems if these
data are used for buffer allocation or checks.

Actually, the 'data' member can't change during read as it is just a
pointer to a fixed array contained in qxl. However, this change will
make it clear that there can be no race condition.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-06 11:11:11 +01:00
Frediano Ziglio
caec52dc77 Fix integer overflow computing glyph_size in red_get_string
If bpp is int the formula can lead to weird overflows. width and height
are uint16_t so the formula is:

  size_t = u16 * (u16 * int + const_int) / const_int;

so it became

  size_t = (int) u16 * ((int) u16 * int + const_int) / const_int;

However the (int) u16 * (int) u16 can then became negative to overflow.
Under 64 bit architectures size_t is 64 and int usually 32 so converting
this negative 32 bit number to a unsigned 64 bit lead to a very big
number as the signed is extended and then converted to unsigned.
Using unsigned arithmetic prevent extending the sign.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-10-06 11:11:11 +01:00
Frediano Ziglio
dfaedec789 Fix race condition in red_get_string
Do not read multiple time an array size that can be changed.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-10-06 11:11:10 +01:00
Frediano Ziglio
9235c84e0f Fix race in red_get_image
Do not read multiple times data from guest as this could be changed
by other vcpu threads.
This causes races and security problems if these data are used for
buffer allocation or checks.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-10-06 11:11:10 +01:00
Frediano Ziglio
3dfd1a0828 Fix race condition on red_get_clip_rects
Do not read multiple time an array size that can be changed.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-10-06 11:11:10 +01:00
Frediano Ziglio
0f58e9da56 Prevent 32 bit integer overflow in bitmap_consistent
The overflow may lead to buffer overflow as the row size computed from
width (bitmap->x) can be bigger than the size in bytes (bitmap->stride).
This can make spice-server accept the invalid sizes.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-10-06 11:11:10 +01:00
Frediano Ziglio
68a742aaa8 Fix buffer reading overflow
Not security risk as just for read.
However, this could be used to attempt integer overflows in the
following lines.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-10-06 11:11:10 +01:00
Frediano Ziglio
1eb93baa3c Check properly surface to be created
Check format is valid.
Check stride is at least the size of required bytes for a row.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-10-06 11:11:10 +01:00
Frediano Ziglio
ac5f64a80a Fix some integer overflow causing large memory allocations
Prevent integer overflow when computing image sizes.
Image index computations are done using 32 bit so this can cause easily
security issues. MAX_DATA_CHUNK is larger than the virtual
card limit, so this is not going to cause change in behaviours.
Comparing size calculation results with MAX_DATA_CHUNK will allow us to
catch overflows.
Prevent guest from allocating large amount of memory.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-06 11:11:10 +01:00
Frediano Ziglio
0205a6ce63 Define a constant to limit data from guest.
This limit will prevent guest trying to do nasty things and DoS to host.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-06 11:11:10 +01:00
Frediano Ziglio
097c638b12 worker: avoid double free or double create of surfaces
A driver can overwrite surface state creating a surface with the same
id of a previous one.
Also can try to destroy surfaces that are not created.
Both requests cause invalid internal states that could lead to crashes
or memory corruptions.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-06 11:07:15 +01:00
Frediano Ziglio
dd558bb833 worker: validate correctly surfaces
Do not just give warning and continue to use an invalid index into
an array.

Resolves: CVE-2015-5260

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-10-06 11:07:15 +01:00
Marc-André Lureau
f2ea57335e worker: make it clear it returns from process when no cmd
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-05 14:45:16 +01:00
Marc-André Lureau
5e80266cb9 server: remove useless includes
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2015-10-02 10:13:45 +01:00
Marc-André Lureau
bb969255c9 worker: count in drawable_new() 2015-09-29 18:59:54 +01:00
Jonathon Jongsma
61d458119e PALLET -> PALETTE
Use the correct spelling for the enumeration
2015-09-29 18:59:54 +01:00
Christophe Fergeau
5eaf659aa3 tests: Fix -Werror=format-zero-length build failure
replay.c: In function 'replay_channel_event':
replay.c:226:16: error: zero-length gnu_printf format string
[-Werror=format-zero-length]
     g_printerr("");
2015-09-29 18:59:54 +01:00
Christophe Fergeau
1aa5185de2 display: Advertise preferred compression cap
The patches adding a way for the client to set its preferred compression
method added a new capability so that the server can indicate support
for this feature. However, spice-server was not setting this capability
on its display channel, which means clients are not going to try to send
'preferred-compression' messages even though the user request it.
2015-09-24 11:06:42 +02:00
Frediano Ziglio
bd6ea0db84 Avoid race conditions reading monitor configs from guest
For security reasons do not assume guest do not change structures it
pass to Qemu.
Guest could change count field while Qemu is copying QXLMonitorsConfig
structure leading to heap corruption.
This patch avoid it reading count only once.

This patch solves CVE-2015-3247.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-09-08 16:09:50 +01:00
Frediano Ziglio
f0acfbc639 replay: fix formatting string
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-09-08 10:16:12 +01:00
Frediano Ziglio
1804b8bb85 improve performances comparing image pixels
This patch contains a bit of small optimizations.
It avoid boolean	 operations which could involve branches replacing
with binary operations (equal/all_ident -> some_differences).
The other optimization avoids the use of ABS. First the way the macro
was used (with a large expression) was not easy to optimize by the
compiler.
Then instead of using ABS a much simpler range check is used so instead
of (ABS(n) >= k) a ((n) <= -k || (n) >= k) is used. This looks small
but modern compilers can translate this not in range check in a couple
of machine instructions (and a single compare).

Using operf on same samples (using spice-server-replay) and trying 2 runs
I got

run             1       2
-------------------------
before    104441   106267
after      92387    91083

So the performance increase is about 13%.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-09-04 11:04:09 +01:00
Frediano Ziglio
39be1c448c avoid to call red_get_streams_timout twice computing timeout
Due to how the MIN macro is defined the function was called twice
unless the compiler could demonstrate that was returning the same
value (which actually is impossible as function as clock_gettime
are not deterministic).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2015-09-03 16:04:27 +01:00