Bug 859027 - repeated client_migrate_info caused freeing invalid pointer, followed ultimately by segfault in _int_malloc
repeated client_migrate_info caused freeing invalid pointer, followed ultimat...
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: spice-server (Show other bugs)
6.4
Unspecified Unspecified
unspecified Severity medium
: beta
: ---
Assigned To: Yonit Halperin
Desktop QE
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-09-20 07:57 EDT by David Jaša
Modified: 2013-11-21 02:38 EST (History)
15 users (show)

See Also:
Fixed In Version: spice-server-0.12.4-1.el6
Doc Type: Bug Fix
Doc Text:
Cause: If client_migrate_info was called once with cert-host-subject and then again without cert-host-subject, on a third call to client_migrate info, the cert-host-subject from the first call would have been freed for the second time. [ An even more detailed explanation: In the first call with cert-host-subject a pointer was allocated. In the second call without cert-host-subject the pointer was freed, but not set to NULL. In the third call that same pointer was freed again. ] Consequence: glibc complains about double free and later it causes a segmentation fault. Fix: Set the pointer to NULL, if cert-host-subject is not given. [ That's fix happens in the "second" migrate-info ] Result: The pointer is freed only once and qemu-kvm/spice-server does not crash.
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-11-21 02:38:43 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
qemu backtrace (78.63 KB, text/plain)
2012-09-20 07:57 EDT, David Jaša
no flags Details

  None (edit)
Description David Jaša 2012-09-20 07:57:20 EDT
Created attachment 614861 [details]
qemu backtrace

Description of problem:
repeated client_migrate_info caused freeing invalid pointer, followed ultimately by segfault in _int_malloc.

The freeing of invalid pointer seems to be quite common (I see it second time in fairly short time frame) but the segmentation fault happened to me for the first time.

Version-Release number of selected component (if applicable):
qemu-kvm-0.12.1.2-2.312.el6.x86_64
spice-server-0.11.3-1_test2.el6.x86_64

How reproducible:
didn't try to reproduce

Steps to Reproduce:
0. have a set of x509 certs/keys in /etc/pki/libvirt-spice
1. run source qemu: qemu-kvm -monitor stdio -spice addr=::,tls-port=5811,x509-dir=/etc/pki/libvirt-spice,seamless-migration=on,disable-ticketing
2. run dest qemu: qemu-kvm -monitor stdio -spice addr=::,tls-port=5813,x509-dir=/etc/pki/libvirt-spice,seamless-migration=on,disable-ticketing -incoming tcp::5712
3. connect with client: remote-viewer --spice-ca-file /etc/pki/libvirt-spice/ca-cert.pem spice://<hostame>/?tls-port=5811
NOTE: <hostname> must match CN in Subject of ${x509-dir}/server-cert.pem
4. issue repeatedly this command on qemu CLI: client_migrate_info spice 127.0.0.1 0 5813 <Subject_of_server-cert.pem>
note: you may try without host subject specified as well
  
Actual results:
after several cycles, freeing invalid pointers appear:
*** glibc detected *** qemu-kvm: free(): invalid pointer: 0x00007f6a0e43a710 ***
after several more cycles, full segmentation fault occurs

Expected results:
qemu will never segfault

Additional info:
Comment 1 David Jaša 2012-09-20 08:12:01 EDT
When I tried to run source qemu in valgrind:
valgrind -v --error-limit=no --tool=memcheck --track-origins=yes --leak-check=full qemu-kvm -monitor stdio -spice addr=::,tls-port=5811,x509-dir=/etc/pki/libvirt-spice,seamless-migration=on,disable-ticketing

it got crazy as soon as I connected to it, repeating this stuff over an over (even when I rerun it with plaintext-port only and no x509-dir):
==23650== Use of uninitialised value of size 8
==23650==    at 0x9970C20: bn_mul_mont (x86_64-mont.s:152)
==23650==    by 0x152F1A6801292306: ???
==23650==    by 0x8CD975FE1C327A67: ???
==23650==    by 0xD0E8B5EB10CDE393: ???
==23650==    by 0xEF2A0D7A89142F69: ???
==23650==    by 0x1800C336037BE0BF: ???
==23650==    by 0xF933698707AE7DBD: ???
==23650==    by 0x8F86049E00EC185C: ???
==23650==    by 0x644D9C308B6DECCD: ???
==23650==  Uninitialised value was created by a heap allocation
==23650==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==23650==    by 0x993995D: CRYPTO_malloc (mem.c:306)
==23650==    by 0x996BDDD: bnrand (bn_rand.c:134)
==23650==    by 0x996BC47: bn_rand_range (bn_rand.c:281)
==23650==    by 0x996EC3A: BN_is_prime_fasttest_ex (bn_prime.c:322)
==23650==    by 0x996F203: BN_generate_prime_ex (bn_prime.c:199)
==23650==    by 0x997854A: RSA_generate_key_ex (rsa_gen.c:213)
==23650==    by 0x657C587: reds_handle_read_link_done (reds.c:1539)
==23650==    by 0x6577D75: spice_server_add_client (reds.c:3035)
==23650==    by 0x6577DD9: reds_accept (reds.c:3012)
==23650==    by 0x16B06E: main_loop_wait (vl.c:3999)
==23650==    by 0x18C9A9: kvm_main_loop (qemu-kvm.c:2244)
Comment 2 David Jaša 2012-09-20 08:34:31 EDT
When run under gdb, I couldn't make qemu do even the free() of invalid pointer.
Comment 3 Gerd Hoffmann 2012-09-24 03:49:28 EDT
qemu just passes on the info to spice server, reassigning.
Comment 4 RHEL Product and Program Management 2012-12-14 03:01:14 EST
This request was not resolved in time for the current release.
Red Hat invites you to ask your support representative to
propose this request, if still desired, for consideration in
the next release of Red Hat Enterprise Linux.
Comment 6 Yonit Halperin 2013-05-23 17:14:28 EDT
Hi,

Is it possible that you called client_migrate_info once with <host-subject> and then at a following call you (maybe accidently) omitted the <host-subject> and then the following call crashed?

I posted a patch for the above bug http://patchwork.freedesktop.org/patch/13728/ 

Please let me know if you manage to reproduce the bug without omitting the host-subject.
Comment 7 David Jaša 2013-05-24 11:49:31 EDT
(In reply to Yonit Halperin from comment #6)
> Hi,
> 
> Is it possible that you called client_migrate_info once with <host-subject>
> and then at a following call you (maybe accidently) omitted the
> <host-subject> and then the following call crashed?
> 
> I posted a patch for the above bug
> http://patchwork.freedesktop.org/patch/13728/ 
> 
> Please let me know if you manage to reproduce the bug without omitting the
> host-subject.

Yes, IIRC it was this case.
Comment 8 David Jaša 2013-05-28 04:23:14 EDT
To clarify - I meant that I did repeated client_migrate_info, some with host subject specified and following without.
Comment 15 errata-xmlrpc 2013-11-21 02:38:43 EST
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2013-1571.html

Note You need to log in before you can comment on or make changes to this bug.