Commit Graph

1082 Commits

Author SHA1 Message Date
David Jaša
4fc9ba5f27 Use TLS version 1.0 or better
When creating a TLS socket, both spice-server and spice-gtk currently
call SSL_CTX_new(TLSv1_method()). The TLSv1_method() function set the
protocol version to TLS 1.0 exclusively. The correct way to support
multiple protocol versions is to call SSLv23_method() in spite of its
scary name. This method will enable all SSL/TLS protocol versions. The
protocol suite may be further narrowed down by setting respective
SSL_OP_NO_<version_code> options of SSL context.  This possibility is
used in this patch in order to block use of SSLv3 that is enabled by
default in openssl for client sockets as of now but spice has never used
it.
2013-12-12 10:39:11 +01:00
Christophe Fergeau
f4f033a09c Remove empty red_time.c 2013-12-11 16:45:59 +01:00
Christophe Fergeau
1b77a2c073 Add red_time.h to Makefile.am
This file was added in bc50ff076 a few months ago, but is not listed
in Makefile.am, and thus not part of tarballs. However, it's being included
from other C files, so not having it causes compilation breakage.
2013-12-11 16:45:50 +01:00
Christophe Fergeau
8af6190096 Fix buffer overflow when decrypting client SPICE ticket
reds_handle_ticket uses a fixed size 'password' buffer for the decrypted
password whose size is SPICE_MAX_PASSWORD_LENGTH. However,
RSA_private_decrypt which we call for the decryption expects the
destination buffer to be at least RSA_size(link->tiTicketing.rsa)
bytes long. On my spice-server build, SPICE_MAX_PASSWORD_LENGTH
is 60 while RSA_size() is 128, so we end up overflowing 'password'
when using long passwords (this was reproduced using the string:
'fullscreen=1proxy=#enter proxy here; e.g spice_proxy = http://[proxy]:[port]'
as a password).

When the overflow occurs, QEMU dies with:
*** stack smashing detected ***: qemu-system-x86_64 terminated

This commit ensures we use a corectly sized 'password' buffer,
and that it's correctly nul-terminated so that we can use strcmp
instead of strncmp. To keep using strncmp, we'd need to figure out
which one of 'password' and 'taTicket.password' is the smaller buffer,
and use that size.

This fixes rhbz#999839
2013-10-30 10:40:50 +01:00
Christophe Fergeau
ef9a8bf053 Remove tunneling support
It's depending on an unmaintained package (slirp), and I don't
think anyone uses that code. It's not tested upstream nor in fedora,
so let's remove it.
2013-10-28 11:12:27 +01:00
Christophe Fergeau
1b6ced7dda Silence gcc false positive with -Wuninitialized
Some versions of gcc warn about:
red_channel.c: In function 'red_channel_client_wait_outgoing_item':
red_channel.c:2331: error: 'end_time' may be used uninitialized in this function [-Wuninitialized]
red_channel.c: In function 'red_channel_client_wait_pipe_item_sent':
red_channel.c:2363: error: 'end_time' may be used uninitialized in this function [-Wuninitialized]
red_channel.c: In function 'red_channel_wait_all_sent':
red_channel.c:2401: error: 'end_time' may be used uninitialized in this function [-Wuninitialized]

This is a false positive as end_time is unitialized when timeout is -1, and
we will only try to use end_time if timeout is not -1.

This commit initializes end_time to UINT64_MAX to avoid that warning. As
the test involving end_time will never be reached, we ensure it's always
TRUE so that it would be a noop even if it was reached.
2013-10-28 11:12:20 +01:00
Axel Lin
56e7876d8f red_tunnel_worker: Fix build error due to missing monitor_latency argument
Fix missing monitor_latency argument in red_channel_client_create call.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
2013-10-18 15:12:50 +02:00
Christophe Fergeau
ceb672bf85 Use hardened linker flags if available
This commit reuse several macros from libvirt to test for
support for "-Wl,-z -Wl,relro", "-Wl,-z -Wl,now" and
"-Wl,--no-copy-dt-needed-entries", and use them if available.
2013-10-10 11:17:52 +02:00
Christophe Fergeau
c9ea4538e2 Fix PlaybackeCommand typo 2013-10-09 19:03:37 +02:00
Marc-André Lureau
6e92dcbbba reds: remove dead code 2013-10-08 19:57:00 +02:00
Christophe Fergeau
edfb16a55d reds: Fix 'asyc' typo 2013-10-08 19:07:44 +02:00
Christophe Fergeau
df96538e1f Fix 'recive' typo throughout the code base
'receive' was mispelt 'recive' in multiple places.
2013-10-08 19:07:42 +02:00
Christophe Fergeau
394fd0e6b7 Namespace RECEIVE_BUF_SIZE 2013-10-08 19:07:41 +02:00
Marc-André Lureau
b18d867b31 server: handle red_get_surface_cmd() error explicitely
Don't ignore red_get_surface_cmd() error, and explicitely interrupt and
free cmd before processing.
2013-10-07 16:33:21 +02:00
Marc-André Lureau
1f12fa72cc server: plug some leaks on error
Plug what looks like memory leaks, that could be potentially be
triggered by a misbehaving guest.
2013-10-07 16:33:21 +02:00
Marc-André Lureau
3bb7db9c5d server: inputs s/relase/release 2013-10-07 16:33:20 +02:00
Marc-André Lureau
2d28da3c17 server: release all pressed keys on client disconnect
Releasing modifiers keys unconditionally on disconnect leads to
unexpected guest wakeups. To improve the situation, the server can
release only the pressed keys, which will prevent the wakeup in most
cases.

Furthermore, it's not sufficient to release only the modifiers keys.
Any key should be released on client disconnect to avoid sticky key
press across connections.

https://bugzilla.redhat.com/show_bug.cgi?id=871240
2013-10-07 16:33:20 +02:00
Marc-André Lureau
fe0941fb02 server: mark deprecated symbols 2013-10-07 16:33:20 +02:00
Marc-André Lureau
e93b2bb188 server/tests: avoid using deprecated symbols 2013-10-07 16:33:20 +02:00
Marc-André Lureau
1d18b7e98a server: set dispatcher before calling attache_worker
This allows to call spice_qxl_add_memslot during attache_worker(), like
done in the tests.
2013-10-07 16:33:20 +02:00
Marc-André Lureau
30783c8e59 server: remove memslot unused functions 2013-10-01 16:23:59 +02:00
Marc-André Lureau
9a485b64ea server: remove unused fill_rects_clip
Unused since 62d0c076eb.
2013-09-30 13:58:47 +02:00
Yonit Halperin
90a4761249 red_worker: disconnect the channel instead of shutdown in case of a blocking method failure
rhbz#1004443

The methods that trigger waitings on the client pipe require that
the waiting will succeed in order to continue, or otherwise, that
all the living pipe items will be released (e.g., when
we must destroy a surface, we need that all its related pipe items will
be released). Shutdown of the socket will eventually trigger
red_channel_client_disconnect (*), which will empty the pipe. However,
if the blocking method failed, we need to empty the pipe synchronously.
It is not safe(**) to call red_channel_client_disconnect from ChannelCbs
, but all the blocking calls in red_worker are done from callbacks that
are triggered from the device.
To summarize, calling red_channel_client_disconnect instead of calling
red_channel_client_shutdown will immediately release all the pipe items that are
held by the channel client (by calling red_channel_client_pipe_clear).
If red_clear_surface_drawables_from_pipe timeouts,
red_channel_client_disconnect will make sure that the surface we wish to
release is not referenced by any pipe-item.

(*) After a shutdown of a socket, we expect that later, when
red_peer_handle_incoming is called, it will encounter a socket
error and will call the channel's on_error callback which calls
red_channel_client_disconnect.

(**) I believe it was not safe before commit 2d2121a170 (before adding ref
count to ChannelClient). However, I think it might still be unsafe, because
red_channel_client_disconnect sets rcc->stream to NULL, and rcc->stream
may be referred later inside a red_channel_client method unsafely. So instead
of checking if (stream != NULL) after calling callbacks, we try to avoid
calling red_channel_client_disconnect from callbacks.
2013-09-26 13:58:43 -04:00
Yonit Halperin
bcf9e64f13 red_channel: cleanup of red_channel_client blocking methods
(1) receive timeout as a parameter.
(2) add a return value and pass the handling
    of failures to the calling routine.
2013-09-26 10:48:40 -04:00
Yonit Halperin
6c2ff9864d red_worker: cleanup red_clear_surface_drawables_from_pipes
(1) merge 'force' and 'wait_for_outgoing_item' to one parameter.
    'wait_for_outgoing_item' is a derivative of 'force'.
(2) move the call to red_wait_outgoing_item to red_clear_surface_drawables_from_pipe
2013-09-26 10:48:40 -04:00
Marc-André Lureau
ced4f1adfd build-sys: fix some automake warning
client/Makefile.am:199: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
server/tests/Makefile.am:3: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
2013-09-17 19:41:27 +02:00
Christophe Fergeau
7989644092 red_parse_qxl: Change spice_error() to spice_warning()
After eb09c25c, red_parse_qxl.c still has some spice_error() which
will kill the server even though the code is trying to return an error
when the spice_error() is hit.
This commit replaces these occurrences with a spice_warning() which
will not kill spice-server.
2013-09-02 18:13:04 +02:00
Uri Lublin
eb09c25c62 server: bitmap_consistent: replace spice_error with spice_warning
bitmap_consistent should return true or false.
Currently it aborts instead of returning false, due to spice_error.
Replacing spice_error with spice_warning, provides information and returns
false, as expected.

This fixes Fedora bz#997932
2013-09-02 13:31:20 +03:00
Yonit Halperin
d0a1346fda red_worker: fix call to dump_bitmap (too many args) 2013-08-22 16:12:07 -04:00
Yonit Halperin
93b88a73f3 spice_bitmap_utils: fix dump_bitmap 2013-08-22 16:09:26 -04:00
Yonit Halperin
ed1f70c6d1 main_channel: monitoring client connection status
rhbz#994175

Start monitoring if the client connection is alive after completing
the bit-rate test.
2013-08-14 13:36:30 -04:00
Yonit Halperin
c8b808bb82 red_channel: add option to monitor whether a channel client is alive
rhbz#994175

When a client connection is closed surprisingly (i.e., without a FIN
segment), we cannot identify it by a socket error (which is the only
way by which we identified disconnections so far).
This patch allows a channel client to periodically check the state of
the connection and identify surprise disconnections.
2013-08-14 13:35:10 -04:00
Yonit Halperin
d1e7142a0f red_channel: add on_input callback for tracing incoming bytes
The callback will be used in the next patch.
2013-08-14 11:08:17 -04:00
Yonit Halperin
c1c08c2898 spice_timer_queue: don't call timers repeatedly
For channels that don't run as part of the main loop, we use
spice_timer_queue, while for the other channels we use
qemu timers support. The callbacks for setting timers are supplied to
red_channel via SpiceCoreInterface, and their behavior should be
consistent. qemu timers are called only once per each call to
timer_start. This patch assigns the same behaviour to spice_timer_queue.
2013-08-14 11:07:17 -04:00
Alon Levy
ee382109a6 server: split spice_image_cache from red_worker 2013-08-14 12:08:04 +03:00
Alon Levy
1bbce9ba05 server/red_worker: s/image_cache_eaging/image_cache_aging/ 2013-08-14 12:08:04 +03:00
Alon Levy
7241cc9544 server: move surface_format_to_image_type to spice_bitmap_utils 2013-08-14 12:08:04 +03:00
Alon Levy
9b8ff04284 server: s/red_wait_all_sent/red_channel_wait_all_sent/ 2013-08-14 12:08:04 +03:00
Alon Levy
bc50ff0767 server: move three functions to red_channel
Three blocking functions, one was split to leave the display channel
specific referencing of the DrawablePipeItem being sent inside
red_worker, but the rest (most) of the timeout logic was moved to
red_channel, including the associated constants.

Moved functions:
red_channel_client_wait_pipe_item_sent
red_wait_outgoing_item
red_wait_all_sent

Introduces red_time.h & red_time.c for a small helper function dealing
with time.h
2013-08-14 12:08:04 +03:00
Alon Levy
fe38ddf724 server: move bit set/clear utilities out of red_worker.h 2013-08-14 12:08:04 +03:00
Alon Levy
376264b009 server: move dump_bitmap to separate file 2013-08-14 12:08:04 +03:00
Alon Levy
ff672924ca server/red_worker.c:red_process_drawable: rename item to drawable 2013-08-14 12:08:04 +03:00
Alon Levy
3a25c20704 server/red_worker.c:red_process_drawable: rename drawable to red_drawable 2013-08-14 12:08:04 +03:00
Alon Levy
478a1906b0 red_worker: mark DRAW_ALL as broken
setting DRAW_ALL define doesn't produce correct rendering. Using
update_area instead of red_draw_qxl_drawable will work but it shouldn't
be required. This is not work I intend to do right now, so marking it
for anyone looking at this in the future.
2013-08-14 12:07:50 +03:00
Yonit Halperin
6ced0f6985 red_worker: decrease the timeout when flushing commands and waiting for the client.
150 seconds is way too long period for holding the guest driver and
waiting for a response for the client. This timeout was 15 seconds, but
when off-screen surfaces ware introduced it was arbitrarily multiplied by
10.
Other existing related bugs emphasize why it is important to decrease
the timeout:
(1) 994211 - the qxl driver waits for an async-io reponse for 60 seconds
    and after that, it switches to sync-io mode. Not only that the
    driver might use invalid data (since it didn't wait for the query to
    complete), falling back to sync-io mode introduces other errors.
(2) 994175 - spice server sometimes doesn't recognize that the client
             has disconnected.
(3) There might be cache inconsistency between the client and the server,
and then the display channel waits indefinitely for a cache item (e.g., bug
977998)

This patch changes the timeout to 30 seconds. I tested it under wifi +emulating 2.5Mbps network,
together with playing video on the guest and changing resolutions in a loop. The timeout didn't expired
during my tests.

This bug is related to rhbz#964136 (but from rhbz#964136 info it is still not
clear why the client wasn't responsive).
2013-08-06 14:28:34 -04:00
Yonit Halperin
c2e46b926e log: improve debug information related to client disconnection 2013-07-29 11:35:17 -04:00
Yonit Halperin
02f44c137d snd_worker/snd_disconnect_channel: don't call snd_channel_put if the channel has already been disconnected
The snd channels has one reference as long as their socket is active.
The playback channel has an additional reference for each frame that is
currently filled by the sound device.
Once the channel is disconnected (the socket has been freed and the
first reference is released) snd_disconnect_channel shouldn't release
a reference again.
2013-07-29 11:35:17 -04:00
Yonit Halperin
134b7f310d snd_worker: fix memory leak of PlaybackChannel
When the sequence of calls bellow occurs, the PlaybackChannel
is not released (snd_channel_put is not called for the
samples that refer to the channel).

    spice_server_playback_get_buffer
    snd_channel_disconnect
    spice_server_playback_put_samples
2013-07-29 11:35:17 -04:00
Yonit Halperin
46c2ce8f1a reds: s/red_client_disconnect/red_channel_client_shutdown inside callbacks
When we want to disconnect the main channel from a callback, it is
safer to use red_channel_client_shutdown, instead of directly
destroying the client. It is also more consistent with how other
channels treat errors.
red_channel_client_shutdown will trigger socket error in the main channel.
Then, main_channel_client_on_disconnect will be called,
and eventually, main_dispatcher_client_disconnect.

I didn't replace calls to reds_disconnect/reds_client_disconnect in
places where those calls were safe && that might need immediate client
disconnection.
2013-07-29 11:35:17 -04:00
Yonit Halperin
8490f83e1f decouple disconnection of the main channel from client destruction
Fixes rhbz#918169

Some channels make direct calls to reds/main_channel routines. If
these routines try to read/write to the socket, and they get socket
error, main_channel_client_on_disconnect is called, and triggers
red_client_destroy. In order to prevent accessing expired references
to RedClient, RedChannelClient, or other objects (inside the original call, after
red_client_destroy has been called) I made the call to
red_client_destroy asynchronous with respect to main_channel_client_on_disconnect.
I added MAIN_DISPATCHER_CLIENT_DISCONNECT to main_dispatcher.
main_channel_client_on_disconnect pushes this msg to the dispatcher,
instead of calling directly to reds_client_disconnect.

The patch uses RedClient ref-count in order to handle a case where
reds_client_disconnect is called directly (e.g., when a new client connects while
another one is connected), while there is already CLIENT_DISCONNECT msg
pending in the main_dispatcher.

Examples:
(1) snd_worker.c

    snd_disconnect_channel()
        channel->cleanup() //snd_playback_cleanup
            reds_enable_mm_timer()
                .
                .
                main_channel_push_multi_media_time()...socket_error
                    .
                    .
                    red_client_destory()
                        .
                        .
                        snd_disconnect_channel()
                            channel->cleanup()
                                celt051_encoder_destroy()
            celt051_encoder_destory() // double release

Note that this bug could have been solved by changing the order of
calls: e.g., channel->stream = NULL before calling cleanup, and
some other changes + reference counting. However, I found other
places in the code with similar problems, and I looked for a general
solution, at least till we redesign red_channel to handle reference
counting more consistently.

(2) inputs_channel.c

    inputs_connect()
        main_channel_client_push_notify()...socket_error
                .
                .
            red_client_destory()
                .
                .
        red_channel_client_create() // refers to client which is already destroyed

(3) reds.c

    reds_handle_main_link()
       main_channel_push_init() ...socket error
                .
                .
            red_client_destory()
                .
                .
       main_channel_client_start_net_test(mcc) // refers to mcc which is already destroyed

    This can explain the assert in rhbz#964136, comment #1 (but not the hang that occurred before).
2013-07-29 11:35:17 -04:00