CVE-2018-9838: An integer overflow in the `bigarray` serialization module leads to arbitrary code execution

Published Apr 6, 2018
·
Updated

Bug description

The bigarray module in all recent ocaml versions is capable of reading in serialized (marshalled) objects from a external source which is often used for network operations and interprocess communication.

byterun/bigarray.c

Line 458 in ea60609 C b->data = malloc(eltsize numelts);

A integer overflow vulnerability allows under certain circumstances an remote attacker to input a corrupt object and edit arbitrary addresses in the processes memory which leads over common techniques (in this take libc one gadget but any rop gadget or got table vector would work) to arbitrary memory access (!) and in the course also arbitrary code execution

Please check the writeup.pdf for more details !!

In variations of this the exploit is usable in all ocaml versions we tested no matter if compiled to binary or intepreted (!)

Steps to reproduce

Check out the attached archive and run the makefile (or use the precompile executable) the exploit can be run by executing exploit.py (python2.7 and pwntools are required) The last step of code execution is using a one-gadget attack technique and is specific to the glibc version in use (e.g. tested is debian glibc 2.24-11+deb9u1) but can with minimal amount of work be ported to any libc version on any patch level to our knowledge

Of course you can also use the exploit.py to write your own version of exploit

Additional information

This Vulnerability in ocaml was discovered by me (maximilian.tschirschnitz@gmx.de) and the exploit collaboratly developed with (philipp.hagenlocher@tum.de) For illustration purposes it was packaged as security challenge to demonstrate the impact of the issue (see writeup.pdf)

Other sources

The camlbadeserialize function in byterun/bigarray.c in the standard library in OCaml 4.06.0 has an integer overflow which, in situations where marshalled data is accepted from an untrusted source, allows remote attackers to cause a denial of service (memory corruption) or possibly execute arbitrary code via a crafted object.

— MITRE

Affected Software

2 affected componentsFixes available
ocaml OCaml=4.06.0
opam/ocaml<4.07.0
4.07.0

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade opam/ocaml to a version that resolves this vulnerability.

    Fixed in 4.07.0

Event History

Apr 6, 2018
CVE Published
via MITRE·06:00 PM
Data Sourced
via MITRE·06:00 PM
Description
Advisory Published
via OSV·06:29 PM
Data Sourced
via NVD·06:29 PM
DescriptionSeverityWeaknessAffected Software
Data Sourced
via OSV·06:29 PM
DescriptionSeverityAffected Software

Frequently Asked Questions

1

What is the severity of CVE-2018-9838?

CVE-2018-9838 is classified as a medium severity vulnerability that can lead to denial of service or potential memory corruption.

2

How do I fix CVE-2018-9838?

To fix CVE-2018-9838, upgrade OCaml to versions newer than 4.06.0 where the vulnerability has been addressed.

3

What software is affected by CVE-2018-9838?

CVE-2018-9838 affects OCaml version 4.06.0 specifically.

4

What type of attack does CVE-2018-9838 facilitate?

CVE-2018-9838 allows remote attackers to exploit integer overflow that can cause memory corruption.

5

Can CVE-2018-9838 be exploited remotely?

Yes, CVE-2018-9838 can be exploited remotely if marshalled data from untrusted sources is accepted.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203