]> xenbits.xensource.com Git - xen.git/commit
tools/ocaml/xc: Don't reference Abstract_Tag objects with the GC lock released
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 31 Jan 2023 17:19:30 +0000 (17:19 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 6 Feb 2023 10:22:12 +0000 (10:22 +0000)
commit9e7c74e6f9fd2e44df1212643b80af9032b45b07
treeadf91635393f66570fb2cbfee57f72d3c912e96b
parent4250683842104f02996428f93927a035c8e19266
tools/ocaml/xc: Don't reference Abstract_Tag objects with the GC lock released

The intf->{addr,len} references in the xc_map_foreign_range() call are unsafe.
From the manual:

  https://ocaml.org/manual/intfc.html#ss:parallel-execution-long-running-c-code

"After caml_release_runtime_system() was called and until
caml_acquire_runtime_system() is called, the C code must not access any OCaml
data, nor call any function of the run-time system, nor call back into OCaml
code."

More than what the manual says, the intf pointer is (potentially) invalidated
by caml_enter_blocking_section() if another thread happens to perform garbage
collection at just the right (wrong) moment.

Rewrite the logic.  There's no need to stash data in the Ocaml object until
the success path at the very end.

Fixes: 8b7ce06a2d34 ("ocaml: Add XC bindings.")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
tools/ocaml/libs/xc/xenctrl_stubs.c