In OCaml before 4.14.3 and 5.x before 5.4.1, a buffer over-read in Marshal deserialization (runtime/intern.c) enables remote code execution through a multi-phase attack chain. The vulnerability stems from missing bounds validation in the readblock() function, which performs unbounded memcpy() operations using attacker-controlled lengths from crafted Marshal data.
OCaml versions before 4.14.3 and 5.x before 5.4.1 contain a critical buffer over-read vulnerability in Marshal deserialization that enables remote code execution through crafted serialized data. The vulnerability exploits missing bounds validation in the readblock() function, allowing attackers to read beyond allocated memory and potentially execute arbitrary code. This affects any application using OCaml's Marshal module to deserialize untrusted data, requiring immediate patching.
IMMEDIATE ACTIONS:
1. Identify all OCaml installations and applications using Marshal module across your infrastructure
2. Audit logs for suspicious Marshal deserialization attempts or crashes in runtime/intern.c
3. Implement network segmentation to restrict untrusted data sources from reaching OCaml applications
PATCHING GUIDANCE:
1. Upgrade OCaml to version 4.14.3 or later for 4.x branch
2. Upgrade OCaml to version 5.4.1 or later for 5.x branch
3. Test patches in non-production environments first, particularly for financial/critical systems
4. Coordinate patching with SAMA/NCA if systems are regulated
COMPENSATING CONTROLS (if immediate patching not possible):
1. Disable Marshal deserialization of untrusted data; use JSON/Protocol Buffers instead
2. Implement strict input validation and size limits before Marshal.from_channel() calls
3. Run OCaml applications in sandboxed containers with restricted memory access
4. Deploy Web Application Firewalls (WAF) to detect and block suspicious serialized payloads
5. Implement strict network access controls limiting data sources to trusted systems only
DETECTION RULES:
1. Monitor for OCaml process crashes with segmentation faults in intern.c
2. Alert on Marshal deserialization of data exceeding expected size thresholds
3. Track unusual memory access patterns in OCaml runtime processes
4. Log all deserialization operations with source IP/user for forensic analysis
الإجراءات الفورية:
1. تحديد جميع تثبيتات OCaml والتطبيقات التي تستخدم وحدة Marshal عبر البنية التحتية
2. مراجعة السجلات للكشف عن محاولات فك تسلسل Marshal المريبة أو الأعطال في runtime/intern.c
3. تنفيذ تقسيم الشبكة لتقييد مصادر البيانات غير الموثوقة من الوصول إلى تطبيقات OCaml
إرشادات التصحيح:
1. ترقية OCaml إلى الإصدار 4.14.3 أو أحدث للفرع 4.x
2. ترقية OCaml إلى الإصدار 5.4.1 أو أحدث للفرع 5.x
3. اختبار التصحيحات في بيئات غير الإنتاج أولاً، خاصة للأنظمة المالية/الحرجة
4. تنسيق التصحيح مع SAMA/NCA إذا كانت الأنظمة منظمة
الضوابط البديلة (إذا لم يكن التصحيح الفوري ممكناً):
1. تعطيل فك تسلسل Marshal للبيانات غير الموثوقة؛ استخدام JSON/Protocol Buffers بدلاً من ذلك
2. تنفيذ التحقق الصارم من المدخلات وحدود الحجم قبل استدعاءات Marshal.from_channel()
3. تشغيل تطبيقات OCaml في حاويات معزولة بإمكانية وصول محدودة للذاكرة
4. نشر جدران حماية تطبيقات الويب (WAF) للكشف عن الحمولات المسلسلة المريبة وحجبها
5. تنفيذ ضوابط وصول شبكة صارمة تقصر مصادر البيانات على الأنظمة الموثوقة فقط
قواعد الكشف:
1. مراقبة أعطال عملية OCaml مع أخطاء التجزئة في intern.c
2. التنبيه على فك تسلسل Marshal للبيانات التي تتجاوز حدود الحجم المتوقعة
3. تتبع أنماط الوصول غير العادية للذاكرة في عمليات تشغيل OCaml
4. تسجيل جميع عمليات فك التسلسل مع عنوان IP/المستخدم للتحليل الجنائي