Bug 287811

Summary: libvirt: fix segmentation fault when buffer needs to be reallocated
Product: Red Hat Enterprise Linux 5 Reporter: Flavio Leitner <fleitner>
Component: libvirtAssignee: Daniel Veillard <veillard>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: high Docs Contact:
Priority: urgent    
Version: 5.1CC: jplans, xen-maint
Target Milestone: rcKeywords: ZStream
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard: GSSApproved
Fixed In Version: RHBA-2008-0291 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-05-21 16:47:41 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 430876    
Attachments:
Description Flags
Backported patch from upstream none

Description Flavio Leitner 2007-09-12 15:47:54 UTC
Description of problem:

When the specified number of characters is short, this issue does not
occur because the pointer of ret is same as buf.content.
But when that is long (i.e. exceeds 4000 bytes), this issue occurs
because the wrong pointer is returned.

So, we fixed the return value to not abend because of an excess number
of characters.

Here is a sequence of these case.
---------------------------------------------------------------------
the case of specifying short command line:

                    +--------------------------+
ret = buf.content => l malloc(4000)             l
                    +--------------------------+
                   0x10 (pointer to the allocated memory)

return(ret)
---------------------------------------------------------------------
the case of specifying long command line:

                    +--------------------------+
ret = buf.content => l malloc(4000)             l
                    +--------------------------+
                   0x10 (pointer to the allocated memory)

** When the allocated memory is lacking, the size of the memory is **
** changed by realloc at virBufferVSprintf.                        **
** So the area pointed to was moved.                               **

                    +--------------------------+
             ret => l malloc(4000)             l
                    +--------------------------+
                   0x10 (pointer to the previously allocated memory)

                    +---------------------------------+
     buf.content => l realloc(6000)                   l
                    +---------------------------------+
                   0x30 (pointer to the newly allocated memory.)

return(ret) <-- return the wrong pointer.
---------------------------------------------------------------------

Version-Release number of selected component (if applicable):
libvirt-0.2.3-9.el5

How reproducible:
Always

Steps to Reproduce:
Run a bug line like:
1. Run:
# virt-install --name=test --ram=350 --file=/dev/sda5 --paravirt \
   --location=ftp://10.131.236.20/rhel5.1b_ia64< /a> --vnc --network=bridge \
   --network=bridge --network=bridge --network=bridge --network=bridge \
   --network=bridge --network=bridge --network=bridge --network=bridge \
   --network=bridge --network=bridge --network=bridge --network=bridge \
   --network=bridge --network=bridge --network=bridge --network=bridge \
   --network=bridge --network=bridge --network=bridge --network=bridge \
   --network=bridge --network=bridge --network=bridge --network=bridge \
   --network=bridge --network=bridge --network=bridge --network=bridge \
   --network=bridge --network=bridge --network=bridge ...

  
Actual results:
Segfault

Additional info:
Patch submitted to upstream and applied:
https://www.redhat.com/archives/libvir-list/2007-August/msg00220.html

Backported patch to RHEL5 attached.

This ticket comes from IT#130873 and is related to BZ#273421 too.

Comment 1 Flavio Leitner 2007-09-12 15:47:54 UTC
Created attachment 193581 [details]
Backported patch from upstream

Comment 2 RHEL Program Management 2007-10-16 03:40:25 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux maintenance release.  Product Management has requested
further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed
products.  This request is not yet committed for inclusion in an Update
release.

Comment 4 Daniel Veillard 2008-01-23 13:36:16 UTC
The patch for this issue is actually in the current libvirt-0.3.3-4.el5
package being built for 5.2,

Daniel

Comment 5 Bill Burns 2008-01-23 13:43:12 UTC
Setting dev ack as this is fixed as per comment #4.


Comment 14 errata-xmlrpc 2008-05-21 16:47:41 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2008-0291.html