Bug 604691

Summary: OCaml bindings are not thread safe
Product: [Community] Virtualization Tools Reporter: Richard W.M. Jones <rjones>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED UPSTREAM QA Contact:
Severity: medium Docs Contact:
Priority: low    
Version: unspecifiedCC: mbooth, virt-maint
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-06-16 14:40:43 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:
Attachments:
Description Flags
Test case. none

Description Richard W.M. Jones 2010-06-16 14:01:43 UTC
Created attachment 424468 [details]
Test case.

Description of problem:

OCaml bindings take pointers to strings on the OCaml heap, and
then allow other threads to run.  For example:

  const char *filename = String_val (filenamev);
  int r;

  caml_enter_blocking_section ();
  r = guestfs_add_drive_ro (g, filename);

If other threads run (after caml_enter_blocking_section and while
waiting for the command to complete) then the GC could move or
reclaim the string pointed to by 'filename'.

Version-Release number of selected component (if applicable):

1.3.20

How reproducible:

Test case attached which reproduces the problem most of the time.

Steps to Reproduce:
1. Run test case with LIBGUESTFS_DEBUG=1
2.
3.
  
Actual results:

Strings are sometimes corrupted.

Expected results:

Strings should not be corrupted.

Additional info:

Should take a copy of strings before calling enter_blocking_section.

Comment 1 Richard W.M. Jones 2010-06-16 14:34:33 UTC
Patch posted upstream:
https://www.redhat.com/archives/libguestfs/2010-June/msg00099.html

Comment 2 Richard W.M. Jones 2010-06-16 14:40:43 UTC
Fix seems obvious, simple and correct.  Pushed upstream.