-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Weak hash of serialized closures #5942
Description
Original bug ID: 5942
Reporter: bvaugon
Status: confirmed (set by @damiendoligez on 2017-10-05T15:45:39Z)
Resolution: open
Priority: normal
Severity: major
Version: 4.00.1
Category: runtime system and C interface
Tags: patch
Bug description
Usually, when you serialize a closure with one program, it is impossible to unserialize it with a different program, and you expect to obtain a runtime exception like: Failure("input_value: unknown code module FAE2E4BE7A3AE0091CF3043126B2CC65")
But, when two programs differs only by their data segments (see the attached example), it is possible to marshal a closure with the first program and to unmarshal it with the second program. Obviously, if you try to call the invalid unserialized closue, execution results in the famous "segmentation fault".
This bug is reproducible with ocamlc and ocamlopt.
The problem is that the hash sum stored in the marshalled closure is only computed with the code segment and not with the data segment.
I wrote a patch to fix it.
Steps to reproduce
With attached x.ml and y.ml, run:
ocamlopt x.ml -o x
ocamlopt y.ml -o y
./x
Do not import "data", ok
./y
Segmentation fault (core dumped)
Additional information
Fixed by the attached patch: ocaml-4.00.1-data-marsh.diff.
Remark: dynlink is ok because the entire dynlinked files are hashed.
So, I just modify byterun and asmrun.