spice/server
Uri Lublin 0c1f5b00e7 char-device: spice_char_device_write_to_device: protect against recursion
This fixes Spice's smart card support and is related to
commit 697f3214fd.

Reported-by: Swapna Krishnan <skrishna@redhat.com>

Recursion is now possible starting with spice_char_device_write_to_device
going through spice_char_device_wakeup (after going through qemu),
calling again to spice_char_device_write_to_device.

The protecting code is the same as the one protecting the read path.

This function call loop makes the program to abort with the following messages:

  usb-ccid: chardev: unexpected message of type 3000000
  qemu: qemu_mutex_lock: Resource deadlock avoided

Backtrace:

(gdb) bt
* #0  0x00007ffff3fc78c7 in raise () from /lib64/libc.so.6
* #1  0x00007ffff3fc952a in abort () from /lib64/libc.so.6
* #2  0x0000555555969a95 in error_exit (err=35,
*     msg=0x5555559f8c90 <__func__.5119> "qemu_mutex_lock")
*     at util/qemu-thread-posix.c:48
* #3  0x0000555555969b82 in qemu_mutex_lock (mutex=0x5555562c4d60)
*     at util/qemu-thread-posix.c:79
* #4  0x0000555555714771 in qemu_chr_fe_write (s=0x5555562c4d60,
*     buf=0x7fffffffd2a0 "", len=12) at qemu-char.c:219
* #5  0x000055555586be49 in ccid_card_vscard_send_msg (s=0x5555565c5f80,
*     type=VSC_Error, reader_id=0, payload=0x7fffffffd2e0 "", length=4)
*     at hw/usb/ccid-card-passthru.c:75
* #6  0x000055555586bf00 in ccid_card_vscard_send_error (s=0x5555565c5f80,
*     reader_id=0, code=VSC_GENERAL_ERROR) at
*     hw/usb/ccid-card-passthru.c:91
* #7  0x000055555586c559 in ccid_card_vscard_handle_message (
*     card=0x5555565c5f80, scr_msg_header=0x5555565c6008)
*     at hw/usb/ccid-card-passthru.c:254
* #8  0x000055555586c72f in ccid_card_vscard_read (opaque=0x5555565c5f80,
*     buf=0x5555565034b0 "", size=12) at hw/usb/ccid-card-passthru.c:289
* #9  0x00005555557149db in qemu_chr_be_write (s=0x5555562c4d60,
*     buf=0x5555565034b0 "", len=12) at qemu-char.c:305
* #10 0x000055555571cde5 in vmc_write (sin=0x5555562c4e78,
*     buf=0x5555565034b0 "", len=12) at spice-qemu-char.c:41
* #11 0x00007ffff4fa86aa in spice_char_device_write_to_device (
*     dev=0x55555657f210) at char_device.c:462
* #12 0x00007ffff4fa9b48 in spice_char_device_wakeup (dev=0x55555657f210)
*     at char_device.c:862
* #13 0x00007ffff4ff7658 in spice_server_char_device_wakeup
*     (sin=0x5555562c4e78) at reds.c:2955
* #14 0x000055555571d1d2 in spice_chr_write (chr=0x5555562c4d60,
*     buf=0x7fffffffd560 "", len=12) at spice-qemu-char.c:189
* #15 0x0000555555714789 in qemu_chr_fe_write (s=0x5555562c4d60,
*     buf=0x7fffffffd560 "", len=12) at qemu-char.c:220
* #16 0x000055555586be49 in ccid_card_vscard_send_msg (s=0x5555565c5f80,
*     type=VSC_Error, reader_id=0, payload=0x7fffffffd5a0 "", length=4)
*     at hw/usb/ccid-card-passthru.c:75
* #17 0x000055555586bf00 in ccid_card_vscard_send_error
* (s=0x5555565c5f80,
*     reader_id=0, code=VSC_SUCCESS) at hw/usb/ccid-card-passthru.c:91
* #18 0x000055555586c4fc in ccid_card_vscard_handle_message (
*     card=0x5555565c5f80, scr_msg_header=0x5555565c6008)
*     at hw/usb/ccid-card-passthru.c:242
* #19 0x000055555586c72f in ccid_card_vscard_read (opaque=0x5555565c5f80,
*     buf=0x5555565034b0 "", size=12) at hw/usb/ccid-card-passthru.c:289
* #20 0x00005555557149db in qemu_chr_be_write (s=0x5555562c4d60,
*     buf=0x5555565034b0 "", len=12) at qemu-char.c:305
* #21 0x000055555571cde5 in vmc_write (sin=0x5555562c4e78,
*     buf=0x5555565034b0 "", len=12) at spice-qemu-char.c:41
* #22 0x00007ffff4fa86aa in spice_char_device_write_to_device (
*     dev=0x55555657f210) at char_device.c:462
* #23 0x00007ffff4fa8d37 in spice_char_device_write_buffer_add (
*     dev=0x55555657f210, write_buf=0x555556501f70) at char_device.c:597
* #24 0x00007ffff501142d in smartcard_channel_write_to_reader (
*     write_buf=0x555556501f70) at smartcard.c:669
* #25 0x00007ffff501034c in smartcard_char_device_notify_reader_add (
*     st=0x55555657ef00) at smartcard.c:335
* #26 0x00007ffff50112b3 in smartcard_add_reader (scc=0x555556493ee0,
*     name=0x5555565023cc "E-Gate 0 0") at smartcard.c:642
* #27 0x00007ffff50118d2 in smartcard_channel_handle_message (
*     rcc=0x555556493ee0, type=101, size=22, msg=0x5555565023c0 "\003")
*     at smartcard.c:757
* #28 0x00007ffff4fbc168 in red_peer_handle_incoming
*     (stream=0x555556588250, handler=0x555556497ff0) at red_channel.c:308
* #29 0x00007ffff4fbc231 in red_channel_client_receive
*     (rcc=0x555556493ee0) at red_channel.c:326
* #30 0x00007ffff4fc0019 in red_channel_client_event (fd=59, event=1,
*     data=0x555556493ee0) at red_channel.c:1574
* #31 0x00005555558b6076 in watch_read (opaque=0x5555565002f0)
*     at ui/spice-core.c:101
* #32 0x00005555558e8d48 in qemu_iohandler_poll (pollfds=0x5555562b7630,
*     ret=2) at iohandler.c:143
* #33 0x00005555558e89a4 in main_loop_wait (nonblocking=0) at
* main-loop.c:495
* #34 0x00005555557219b0 in main_loop () at vl.c:1794
* #35 0x0000555555729257 in main (argc=40, argv=0x7fffffffddc8,
*     envp=0x7fffffffdf10) at vl.c:4350
2015-02-08 13:13:46 +02:00
..
tests build-sys: fix out-of-tree build of tests 2014-11-29 15:32:44 +01:00
.gitignore gitignore: add generated_*, vim temps, pyc 2010-11-08 16:06:55 +02:00
agent-msg-filter.c server: Add support for filtering out agent file-xfer msgs (rhbz#961848) 2013-06-06 16:07:30 +02:00
agent-msg-filter.h server: Add support for filtering out agent file-xfer msgs (rhbz#961848) 2013-06-06 16:07:30 +02:00
char_device.c char-device: spice_char_device_write_to_device: protect against recursion 2015-02-08 13:13:46 +02:00
char_device.h syntax-check: s/the the/the/ in a comment 2013-07-16 23:37:28 +03:00
demarshallers.h Remove trailing blank lines 2012-01-13 18:11:59 +02:00
dispatcher.c Don't do arithmetic on void * type, use uint8_t instead 2012-04-25 09:40:18 +01:00
dispatcher.h dispatcher.h: fix - s/#define MAIN_DISPATCHER_H/#define DISPATCHER_H 2013-04-22 16:30:54 -04:00
glz_encode_match_tmpl.c add #include <config.h> to all source files 2011-05-03 14:44:10 +02:00
glz_encode_tmpl.c Remove trailing whitespace from end of lines 2012-01-13 18:11:59 +02:00
glz_encoder_config.h Fix multiple printf format problems 2012-04-25 09:42:11 +01:00
glz_encoder_dictionary_protected.h server: s/max_encdoers/max_encoders/ 2012-08-30 17:08:09 +03:00
glz_encoder_dictionary.c server: s/max_encdoers/max_encoders/ 2012-08-30 17:08:09 +03:00
glz_encoder_dictionary.h Remove trailing blank lines 2012-01-13 18:11:59 +02:00
glz_encoder.c Remove trailing blank lines 2012-01-13 18:11:59 +02:00
glz_encoder.h Use the spice-common submodule 2012-03-25 18:59:10 +02:00
inputs_channel.c inputs: Remove unneeded variable 2014-12-15 12:02:24 +01:00
inputs_channel.h Remove trailing blank lines 2012-01-13 18:11:59 +02:00
jpeg_encoder.c Use the spice-common logging functions 2012-03-25 19:00:00 +02:00
jpeg_encoder.h Remove trailing whitespace from end of lines 2012-01-13 18:11:59 +02:00
lz4_encoder.c LZ4: Send the original format with the compressed data 2015-02-03 10:39:16 +01:00
lz4_encoder.h LZ4: Send the original format with the compressed data 2015-02-03 10:39:16 +01:00
main_channel.c main_channel: monitoring client connection status 2013-08-14 13:36:30 -04:00
main_channel.h Namespace RECEIVE_BUF_SIZE 2013-10-08 19:07:41 +02:00
main_dispatcher.c decouple disconnection of the main channel from client destruction 2013-07-29 11:35:17 -04:00
main_dispatcher.h decouple disconnection of the main channel from client destruction 2013-07-29 11:35:17 -04:00
Makefile.am Remove spice-experimental 2015-01-15 18:34:26 +01:00
migration_protocol.h enable seamless migration and set migration protocol version 2012-08-27 09:13:14 +03:00
mjpeg_encoder.c Fix assert in mjpeg_encoder_adjust_params_to_bit_rate() 2014-05-30 13:45:02 -05:00
mjpeg_encoder.h mjpeg_encoder: add mjpeg_encoder_get_stats 2013-06-24 15:23:34 -04:00
red_bitmap_utils.h Remove trailing blank lines 2012-01-13 18:11:59 +02:00
red_channel.c Do not perform network tests on UNIX socket 2015-01-15 18:29:36 +01:00
red_channel.h Add const to test_capability first argument 2014-11-24 17:37:17 +01:00
red_client_cache.h Use the spice-common logging functions 2012-03-25 19:00:00 +02:00
red_client_shared_cache.h Use the spice-common logging functions 2012-03-25 19:00:00 +02:00
red_common.h Move SPICE_GNUC_VISIBLE to red_common.h 2014-01-20 12:15:41 +01:00
red_dispatcher.c Remove guest side video time-stamping 2014-11-27 14:27:41 +01:00
red_dispatcher.h server: set dispatcher before calling attache_worker 2013-10-07 16:33:20 +02:00
red_memslots.c server: remove memslot unused functions 2013-10-01 16:23:59 +02:00
red_memslots.h server: remove memslot unused functions 2013-10-01 16:23:59 +02:00
red_parse_qxl.c Fix indentation in red_get_opaque_ptr 2014-09-18 14:06:55 +02:00
red_parse_qxl.h Add support for QXLComposite to spice server 2012-08-24 13:44:42 -04:00
red_time.h server: move three functions to red_channel 2013-08-14 12:08:04 +03:00
red_worker.c LZ4: Send the original format with the compressed data 2015-02-03 10:39:16 +01:00
red_worker.h server: move bit set/clear utilities out of red_worker.h 2013-08-14 12:08:04 +03:00
reds_gl_canvas.c Remove unused SPICE_CANVAS_INTERNAL 2014-12-03 18:32:04 +01:00
reds_gl_canvas.h Remove unused SPICE_CANVAS_INTERNAL 2014-12-03 18:32:04 +01:00
reds_stream.c reds-stream: add reds_stream_get_family() function 2015-01-15 18:29:36 +01:00
reds_stream.h reds-stream: add reds_stream_get_family() function 2015-01-15 18:29:36 +01:00
reds_sw_canvas.c Remove unused SPICE_CANVAS_INTERNAL 2014-12-03 18:32:04 +01:00
reds_sw_canvas.h Remove unused SPICE_CANVAS_INTERNAL 2014-12-03 18:32:04 +01:00
reds-private.h Rename mm_timer/mm_time 2014-11-27 14:32:37 +01:00
reds.c Remove spice-experimental 2015-01-15 18:34:26 +01:00
reds.h Rename mm_timer/mm_time 2014-11-27 14:32:37 +01:00
smartcard.c red_channel: monitor connection latency using MSG_PING 2013-04-22 16:30:54 -04:00
smartcard.h Remove spice-experimental 2015-01-15 18:34:26 +01:00
snd_worker.c Rename mm_timer/mm_time 2014-11-27 14:32:37 +01:00
snd_worker.h snd_worker: support sending SPICE_MSG_PLAYBACK_LATENCY 2013-04-22 16:30:54 -04:00
spice_bitmap_utils.c server: Don't dump the bitmap when the format is invalid 2014-09-12 18:00:30 +02:00
spice_bitmap_utils.h server: move surface_format_to_image_type to spice_bitmap_utils 2013-08-14 12:08:04 +03:00
spice_image_cache.c server: split spice_image_cache from red_worker 2013-08-14 12:08:04 +03:00
spice_image_cache.h server: split spice_image_cache from red_worker 2013-08-14 12:08:04 +03:00
spice_server_utils.h server: move bit set/clear utilities out of red_worker.h 2013-08-14 12:08:04 +03:00
spice_timer_queue.c Don't truncate large 'now' values in _spice_timer_set 2014-03-20 11:34:49 +01:00
spice_timer_queue.h server: spice_timer_queue 2013-04-22 16:30:54 -04:00
spice-audio.h Split spice.h 2014-11-27 14:27:18 +01:00
spice-char.h Split spice.h 2014-11-27 14:27:18 +01:00
spice-core.h Split spice.h 2014-11-27 14:27:18 +01:00
spice-input.h Split spice.h 2014-11-27 14:27:18 +01:00
spice-migration.h Move spice_server_get_num_clients() declaration 2014-11-27 15:03:38 +01:00
spice-qxl.h Remove guest side video time-stamping 2014-11-27 14:27:41 +01:00
spice-server.h reds: add Unix socket support 2015-01-15 18:29:36 +01:00
spice-server.syms Add support for the Opus codec 2014-01-02 12:36:59 +01:00
spice-version.h.in build-sys: generate spice-version.h 2014-11-27 14:27:33 +01:00
spice.h Split spice.h 2014-11-27 14:27:18 +01:00
spicevmc.c red_channel: monitor connection latency using MSG_PING 2013-04-22 16:30:54 -04:00
stat.h Remove trailing blank lines 2012-01-13 18:11:59 +02:00
zlib_encoder.c Use the spice-common logging functions 2012-03-25 19:00:00 +02:00
zlib_encoder.h applying zlib compression over glz on WAN connection 2010-06-21 15:05:37 +02:00