Commit Graph

2507 Commits

Author SHA1 Message Date
Christophe Fergeau
c8f8ea2224 test: Add test_destroy()
This allows to chain several test cases by using
test_new()/test_destroy().

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2017-03-01 18:00:27 +01:00
Frediano Ziglio
f66b7bffc7 tests: Add basic spice_server_init()/spice_server_destroy()
This can be used for very basic leak checks.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-03-01 16:06:57 +00:00
Frediano Ziglio
a6f7aeb5d8 reds: Free remaining configuration
Free security, migration, sasl and name stuff.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-03-01 16:06:51 +00:00
Frediano Ziglio
67b1513f87 display-channel: Clean more stuff on finalize
Release surfaces, cache and monitor configurations.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-28 23:10:31 +00:00
Frediano Ziglio
e4d06191ee stream: Remove region leak
clip_in_draw_dest was not freed correctly.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-28 23:05:39 +00:00
Frediano Ziglio
0b39aecb26 reds: Check that we do not free the wrong agent device
Do not assume the device passed as an argument to
spice_server_char_device_remove_interface() is the same as the current
Reds::vdagent instance. This commit adds a check that this is the case,
and returns early if not.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-28 16:35:49 +00:00
Frediano Ziglio
0d76ad8b5b Remove reds_stream_set_info_flag
Encapsulate into reds_stream_set_channel.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-28 14:20:52 +00:00
Frediano Ziglio
47ba429a8f spicevmc: Use spice_new instead of spice_malloc
spice_new is a bit more safe as return a properly typed pointer.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-28 14:17:56 +00:00
Frediano Ziglio
9855eebd2f sound: Avoid unused IOV_MAX definition
The usage was removed with commit 7ea1f2c133
("sound: Use RedChannelClient to receive/send data").

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2017-02-28 14:15:56 +00:00
Christophe de Dinechin
be727eb822 Remove X == TRUE tests for non-boolean values
Using X == TRUE is fragile, since the input value is a uint8_t. It would be
surprising if the value was set to 2 or 0xFF and the test failed.

Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-27 12:00:52 +00:00
Frediano Ziglio
73e6d88b20 Fix minor inconsistencies with declaration and definition
Declaration used gboolean while definition used int.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2017-02-16 10:28:52 +00:00
Frediano Ziglio
4838f317a9 rcc: Make some functions/macros private
Some constants/macros/function prototypes are defined in
red-channel-client.h while they are only used by red-channel-client.c.
This commit moves them to the .c file to make them private.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-15 16:49:50 +00:00
Frediano Ziglio
10654d34a4 rcc: Remove unused RedChannelClient::{is_connected,disconnect} vfuncs
RedChannelClient is responsible for talking to the client so it knows
if is connected or not.
These vfuncs where used by DummyChannel used by SoundChannel.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-15 16:49:34 +00:00
Frediano Ziglio
fb4fe2d832 rcc: Use class name in comment
red_channel seems a variable name.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-15 16:49:26 +00:00
Frediano Ziglio
9724381afa Make RedChannel::config_socket() optional
Most channels don't need to do specific settings for the client socket
so avoid the need to do this setting making easier to setup the client
channnel.

Some improvements and commit subject suggested by Christophe Fergeau.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-15 12:40:38 +00:00
Frediano Ziglio
01c25074dc Do not set TCP_NODELAY flag twice
TCP_NODELAY flag is set by default for all connection inside
reds.c so there's no need to set again for the single
client channel.

Note that there are still some calls to setsockopt to change this
option.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-15 12:38:30 +00:00
Frediano Ziglio
e8643204aa Clear "msg" pointers after releasing
Avoid possible dangling pointers.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-15 11:59:10 +00:00
Christophe Fergeau
c02ae9835e gstreamer: Add #ifdef around zero_copy()
Since c3d237 "gstreamer: Avoid memory copy if strides are different" is
only needed when zero copy is disabled. This moves the function
definition to an already existing #ifdef block.

Acked-by: Pavel Grunt <pgrunt@redhat.com>
2017-02-15 11:57:59 +00:00
Christophe Fergeau
f5494cfa9b test-playback: Pass proper types to spice_server_add_interface
This is a revert of b76e561d.
For a SpicePlaybackInstance, the base interface must be a
SpicePlaybackInterface instance, not a SpiceBaseInterface instance, or
spice-server code will end up reading out of bounds.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-15 12:13:55 +01:00
Christophe Fergeau
1afa86c3ee test-display-base: Pass proper types to spice_server_add_interface
This is a revert of 93b4f4050^ and 93b4f4050.
For a SpiceCharDeviceInstance, the base interface must be a
SpiceCharDeviceInterface instance, not a SpiceBaseInterface instance, or
spice-server code will end up reading out of bounds.

vmc_state/vmc_write/vmc_read implementations also have to be provided.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-15 12:13:55 +01:00
Christophe Fergeau
14b2f053ab test-vdagent: Pass proper types to spice_server_add_interface
This is a revert of 93b4f4050^ and 93b4f4050.
For a SpiceCharDeviceInstance, the base interface must be a
SpiceCharDeviceInterface instance, not a SpiceBaseInterface instance, or
spice-server code will end up reading out of bounds.

vmc_state/vmc_write/vmc_read implementations also have to be provided.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-15 12:13:55 +01:00
Christophe Fergeau
e87d0a3a84 gstreamer: Remove unused function
rate_control_is_active() is static and not used in gstreamer-encoder.c

Not needed since 97fcad82eb.

Acked-by: Pavel Grunt <pgrunt@redhat.com>
2017-02-15 10:50:27 +00:00
Frediano Ziglio
5a922af9e6 spicevmc: Add some statistics
Allows to see compressed/uncompressed ratio

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-15 10:16:16 +00:00
Frediano Ziglio
ce06958fb8 Improve statistic code interface
Use new structures and functions to implement the statistics code.
Use inline functions instead of macros for increased type-safety.
If statistics are disabled, the structures and functions become
empty. This confines the configuration-specific #defines to the
statistics implementation itself and avoids the need for #defines in
the calling functions. This greatly reduces the chance of accidentally
breaking the build for one configuration or the other. The reds option
was removed from stat_inc_counter() as it was not used.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-15 10:13:48 +00:00
Frediano Ziglio
469b94eb4e Do not set not blocking flag twice
Non blocking flag is set for all connection inside reds.c so
there's no need to set again for the single client channel.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-15 10:08:24 +00:00
Frediano Ziglio
f603f17317 red-channel-client: Pass array size to red_channel_client_prepare_out_msg
Do not make it assume vec contains IOV_MAX elements.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-15 10:02:27 +00:00
Frediano Ziglio
317457221d red-channel-client: Remove vec field from OutgoingHandler
This was always set to vec_buf.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-15 10:02:22 +00:00
Christophe Fergeau
3ef913a388 rcc: Rename {Outgoing,Incoming}Handler
They no longer contain any vfuncs, so calling them "handler" does not
make a lot of sense. This commit renames them to
OutgoingMessageBuffer/IncomingMessageBuffer.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-15 08:48:01 +01:00
Christophe Fergeau
65501eb13c rcc: Remove red-channel-client-private.h
Nothing outside of RedChannelClient needs access to data contained in
RedChannelClientPrivate, so we can move all the type definitions to the
.c file to make it fully opaque rather than relying on a private header.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-15 08:47:52 +01:00
Christophe Fergeau
31a5182bd2 rcc: Move SpiceDataHeaderOpaque to red-channel-client-private.h
It's only used by red-channel-client.c

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-15 08:47:52 +01:00
Christophe Fergeau
d4938694e2 rcc: Replace 'opaque' arg with typed RedChannelClient
The methods previously used by OutgoingHandlerInterface and
IncomingHandlerInterface are no longer used as generic callbacks,
but are directly called from RedChannelClient code. We can be explicit
about the type of their first argument (RedChannelClient *) rather than
using a generic void * pointer.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-15 08:47:52 +01:00
Christophe Fergeau
7ffc7ed303 rcc: Pass RedChannelClient to red_peer_handle_outgoing()
There is only one implementation of OutgoingHandler which relies
OutgoingHandler::opaque being a RedChannelClient. This commit makes this
explicit in order to get rid of the OutgoingHandler::opaque data member.

This renames red_peer_handle_outgoing() to
red_channel_client_handle_outgoing() as the method is now very much tied
to RedChannelClient.

If we want to keep some genericity, we could return error codes from
red_channel_client_handle_outgoing() and handle RedChannelClient
disconnection/... from the caller rather than directly in the
_handle_outgoing() method. This would probably allow to move the
data reading logic to reds-stream.c

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-15 08:47:52 +01:00
Christophe Fergeau
d6126bf495 rcc: Pass RedChannelClient to red_peer_handle_incoming()
There is only one implementation of IncomingHandler which relies
IncomingHandler::opaque to be a RedChannlClient. This commit makes this
explicit. This allows to get rid of the IncomingHandler::opaque data
member.

This renames red_peer_handle_incoming() to
red_channel_client_handle_incoming() as the method is now very much tied
to RedChannelClient.

If we want to keep some genericity, we could return error codes from
red_channel_client_handle_incoming() and handle RedChannelClient
disconnection/... from the caller rather than directly in the
_handle_incoming() method. This would probably allow to move the
data reading logic to reds-stream.c

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-15 08:47:52 +01:00
Christophe Fergeau
f93fe59c21 channel: Remove IncomingHandlerInterface
This commit removes what remains of IncomingHandlerInterface. The
remaining function pointers were pointing to RedChannel vfuncs.
Moreover the IncomingHandlerInterface abstraction is unused, ie the
codebase only has a single implementation for it, so we can directly
call the relevant methods and make them static instead.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-15 08:47:52 +01:00
Christophe Fergeau
99641c6874 channel: More removal of IncomingHandlerInterface vfuncs
This commit removes IncomingHandlerInterface::on_error and
IncomingHandlerInterface::on_input. As with previous commits, these
vfuncs are always calling the method, and RedChannel::init sets them to
point to RedChannelClient methods, which RedChannelClient is then going
to call indirectly through the IncomingHandlerInterface instance.

This commit changes this to direct calls to the corresponding methods.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-15 08:47:52 +01:00
Christophe Fergeau
725c5fd323 channel: Remove IncomingHandlerInterface::{alloc,release}_msg_buf
Similarly to the previous commits, this removes an indirection level,
IncomingHandlerInterface stores pointers to
alloc_recv_buf/release_recv_buf vfuncs, but these are always set to
RedChannel::alloc_recv_buf/RedChannel::release_recv_buf, which are also
vfuncs which can be overridden if needed. This commit removes the
indirection and directly calls the relevant methods.

These vfuncs really should be in RedChannelClient rather than
RedChannel.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-15 08:47:52 +01:00
Christophe Fergeau
c166cf3f24 channel: Remove OutgoingHandlerInterface
RedChannel uses OutgoingHandlerInterface to provide constant pointers to
RedChannelClient methods. This OutgoingHandlerInterface structure is
then used in RedChannelClient to indirectly call these methods.

The OutgoingHandlerInterface abstraction is unused, ie the codebase
only has a single implementation for it, so we can directly call the
relevant methods and make them static instead.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <figlio@redhat.com>
2017-02-15 08:47:52 +01:00
Christophe Fergeau
a5471ea9b2 channel: Rework red_channel_on_output a bit
Have the RedChannelClient callback call into a RedChannel callback
rather than doing the opposite. This will be useful in some subsequent
refactoring of this code.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-15 08:47:52 +01:00
Christophe Fergeau
03ab893412 channel: Remove RedChannel::handle_parsed
red_channel_client_parse() currently does roughly:

if (klass->parser) {
    parsed = klass->parser(msg, msg_size, &parsed_size);
    klass->handle_parsed(rcc, parsed_size, msg_type, parsed);
} else {
    klass->handle_message(rcc, msg_type, msg, msg_size);
}

The handle_parsed implementation expects a void * 'parsed' argument,
which will then be cast to the correct type. There is not really a need
to provide distinct handle_parsed/handle_message vfuncs, instead we can
say that if a RedChannel subclass provides a 'parser' vfunc, then it's
'handle_message' vfunc will be called with the parsed message, otherwise
it will be called with unparsed data (ie what handle_message currently
expects).

This makes the code slightly easier to follow as messages will always be
handled by the same vfunc.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-15 08:47:52 +01:00
Frediano Ziglio
b8f4b3338b smartcard: Remove an unnecessary wrapper function
smartcard_channel_client_pipe_add_push was just calling
red_channel_client_pipe_add_push without any cast or other
changes.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-14 18:07:54 +00:00
Christophe Fergeau
4c2817a562 channel: Remove unused vfunc typedefs from header
They became unused more than 5 years ago in commit f84dfe

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-13 16:41:01 +00:00
Christophe Fergeau
e9461ec904 Move variables to inner block in red_peer_handle_incoming()
This makes the code slightly more readable as this means less local
variables to keep track of when taking a high level view of that code.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-10 16:32:56 +01:00
Frediano Ziglio
cb84a6c2ed replay: Avoid double free of primary surface
read_binary() attaches 'mem' to the SpiceReplay::allocated list.

On failure, SpiceReplay::allocated and its content are freed by
spice_replay_free().

SpiceReplay::primary_mem is also freed, which causes a double free
as replay_handle_create_primary() added 'mem' both to
SpiceReplay::primary_mem and SpiceReplay::allocated.

This commit avoids this by ensuring SpiceReplay::primary_mem is not
kept in the SpiceReplay::allocated list.

Note that this double free can happen only on currupted or wrong
record images.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-08 20:53:44 +00:00
Jonathon Jongsma
11629023c4 DisplayChannel: add documentation for Ring types
The Surface and Display channels each have a 'current_list' Ring, and
Surface also has a 'current' Ring. these names are confusing, so at
minimum, add a comment indicating the type of object they hold. The
DisplayChannel::current_list already had a comment, but it was
incorrect.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-06 16:19:04 -06:00
Jonathon Jongsma
43f62e46ca Shadow: remove unused 'owner' field
This field is set but is never read. The only usage of this field was
removed in 3dffeb25ed

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-02-06 10:12:15 +00:00
Frediano Ziglio
a44a735cda replay: Support TLS in replay utility
Allows to test encrypted connections.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-06 10:06:09 +00:00
Frediano Ziglio
1d3e26c0ee main-channel: Prevent overflow reading messages from client
Caller is supposed the function return a buffer able to store
size bytes.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-06 09:13:11 +00:00
Frediano Ziglio
e16eee1d8b Prevent integer overflows in capability checks
The limits for capabilities are specified using 32 bit unsigned integers.
This could cause possible integer overflows causing buffer overflows.
For instance the sum of num_common_caps and num_caps can be 0 avoiding
additional checks.
As the link message is now capped to 4096 and the capabilities are
contained in the link message limit the capabilities to 1024
(capabilities are expressed in number of uint32_t items).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-06 09:13:08 +00:00
Frediano Ziglio
ec124b982a Prevent possible DoS attempts during protocol handshake
The limit for link message is specified using a 32 bit unsigned integer.
This could cause possible DoS due to excessive memory allocations and
some possible crashes.
For instance a value >= 2^31 causes a spice_assert to be triggered in
async_read_handler (reds-stream.c) due to an integer overflow at this
line:

   int n = async->end - async->now;

This could be easily triggered with a program like

  #!/usr/bin/env python

  import socket
  import time
  from struct import pack

  server = '127.0.0.1'
  port = 5900

  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.connect((server, port))
  data = pack('<4sIII', 'REDQ', 2, 2, 0xaaaaaaaa)
  s.send(data)

  time.sleep(1)

without requiring any authentication (the same can be done
with TLS).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-06 09:13:05 +00:00
Frediano Ziglio
cd82c9f698 sound: Use default message handler if possible
red_channel_client_handle_message can handle base messages
so reuse it.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-03 18:14:46 +00:00