Rust in Android: move fast and fix things الصدأ في Android: تحرك بسرعة وأصلح الأشياء
Related Articles
Last year, we wrote about why a memory safety strategy that focuses on vulnerability prevention in new code quickly yields durable and compounding gains. This year we look at how this approach isn’t just fixing things, but helping us move faster.
The 2025 data continues to validate the approach, with memory safety vulnerabilities falling below 20% of total vulnerabilities for the first time.
Updated data for 2025. This data covers first-party and third-party (open source) code changes to the Android platform across C, C++, Java, Kotlin, and Rust. This post is published a couple of months before the end of 2025, but Android’s industry-standard 90-day patch window means that these results are very likely close to final. We can and will accelerate patching when necessary.
We adopted Rust for its security and are seeing a 1000x reduction in memory safety vulnerability density compared to Android’s C and C++ code. But the biggest surprise was Rust's impact on software delivery. With Rust changes having a 4x lower rollback rate and spending 25% less time in code review, the safer path is now also the faster one.
In this post, we dig into the data behind this shift and also cover:
- How we’re expanding our reach: We're pushing to make secure code the default across our entire software stack. We have updates on Rust adoption in first-party apps, the Linux kernel, and firmware.
- Our first rust memory safety vulnerability...almost: We'll analyze a near-miss memory safety bug in unsafe Rust: how it happened, how it was mitigated, and steps we're taking to prevent recurrence. It’s also a good chance to answer the question “if Rust can have memory safety issues, why bother at all?”
Building Better Software, Faster
Developing an operating system requires the low-level control and predictability of systems programming languages like C, C++, and Rust. While Java and Kotlin are important for Android platform development, their role is complementary to the systems languages rather than interchangeable. We introduced Rust into Android as a direct alternative to C and C++, offering a similar level of control but without many of their risks. We focus this analysis on new and actively developed code because our data shows this to be an effective approach.
When we look at development in systems languages (excluding Java and Kotlin), two trends emerge: a steep rise in Rust usage and a slower but steady decline in new C++.
Net lines of code added: Rust vs. C++, first-party Android code.
This chart focuses on first-party (Google-developed) code (unlike the previous chart that included all first-party and third-party code in Android.) We only include systems languages, C/C++ (which is primarily C++), and Rust.
The chart shows that the volume of new Rust code now rivals that of C++, enabling reliable comparisons of software development process metrics. To measure this, we use the DORA1 framework, a decade-long research program that has become the industry standard for evaluating software engineering team performance. DORA metrics focus on:
- Throughput: the velocity of delivering software changes.
- Stability: the quality of those changes.
Cross-language comparisons can be challenging. We use several techniques to ensure the comparisons are reliable.
- Similar sized changes: Rust and C++ have similar functionality density, though Rust is slightly denser. This difference favors C++, but the comparison is still valid. We use Gerrit’s change size definitions.
- Similar developer pools: We only consider first-party changes from Android platform developers. Most are software engineers at Google, and there is considerable overlap between pools with many contributing in both.
- Track trends over time: As Rust adoption increases, are metrics changing steadily, accelerating the pace, or reverting to the mean?
Throughput
Code review is a time-consuming and high-latency part of the development process. Reworking code is a primary source of these costly delays. Data shows that Rust code requires fewer revisions. This trend has been consistent since 2023. Rust changes of a similar size need about 20% fewer revisions than their C++ counterparts.
In addition, Rust changes currently spend about 25% less time in code review compared to C++. We speculate that the significant change in favor of Rust between 2023 and 2024 is due to increased Rust expertise on the Android team.
While less rework and faster code reviews offer modest productivity gains, the most significant improvements are in the stability and quality of the changes.
Stability
Stable and high-quality changes differentiate Rust. DORA uses rollback rate for evaluating change stability. Rust's rollback rate is very low and continues to decrease, even as its adoption in Android surpasses C++.
For medium and large changes, the rollback rate of Rust changes in Android is ~4x lower than C++. This low rollback rate doesn't just indicate stability; it actively improves overall development throughput. Rollbacks are highly disruptive to productivity, introducing organizational friction and mobilizing resources far beyond the developer who submitted the faulty change. Rollbacks necessitate rework and more code reviews, can also lead to build respins, postmortems, and blockage of other teams. Resulting postmortems often introduce new safeguards that add even more development overhead.
In a self-reported survey from 2022, Google software engineers reported that Rust is both easier to review and more likely to be correct. The hard data on rollback rates and review times validates those impressions.
Putting it all together
Historically, security improvements often came at a cost. More security meant more process, slower performance, or delayed features, forcing trade-offs between security and other product goals. The shift to Rust is different: we are significantly improving security and key development efficiency and product stability metrics.
Expanding Our Reach
With Rust support now mature for building Android system services and libraries, we are focused on bringing its security and productivity advantages elsewhere.
- Kernel: Android’s 6.12 Linux kernel is our first kernel with Rust support enabled and our first production Rust driver. More exciting projects are underway, such as our ongoing collaboration with Arm and Collabora on a Rust-based kernel-mode GPU driver.
- Firmware: The combination of high privilege, performance constraints, and limited applicability of many security measures makes firmware both high-risk, and challenging to secure. Moving firmware to Rust can yield a major improvement in security. We have been deploying Rust in firmware for years now, and even released tutorials, training, and code for the wider community. We’re particularly excited about our collaboration with Arm on Rusted Firmware-A.
- First-party applications: Rust is ensuring memory safety from the ground up in several security-critical Google applications, such as:
- Nearby Presence: The protocol for securely and privately discovering local devices over Bluetooth is implemented in Rust and is currently running in Google Play Services.
- MLS: The protocol for secure RCS messaging is implemented in Rust and will be included in the Google Messages app in a future release.
- Chromium: Parsers for PNG, JSON, and web fonts have been replaced with memory-safe implementations in Rust, making it easier for Chromium engineers to deal with data from the web while following the Rule of 2.
These examples highlight Rust's role in reducing security risks, but memory-safe languages are only one part of a comprehensive memory safety strategy. We continue to employ a defense-in-depth approach, the value of which was clearly demonstrated in a recent near-miss.
Our First Rust Memory Safety Vulnerability...Almost
We recently avoided shipping our very first Rust-based memory safety vulnerability: a linear buffer overflow in CrabbyAVIF. It was a near-miss. To ensure the patch received high priority and was tracked through release channels, we assigned it the identifier CVE-2025-48530. While it’s great that the vulnerability never made it into a public release, the near-miss offers valuable lessons. The following sections highlight key takeaways from our postmortem.
Scudo Hardened Allocator for the Win
A key finding is that Android’s Scudo hardened allocator deterministically rendered this vulnerability non-exploitable due to guard pages surrounding secondary allocations. While Scudo is Android’s default allocator, used on Google Pixel and many other devices, we continue to work with partners to make it mandatory. In the meantime, we will issue CVEs of sufficient severity for vulnerabilities that could be prevented by Scudo.
In addition to protecting against overflows, Scudo’s use of guard pages helped identify this issue by changing an overflow from silent memory corruption into a noisy crash. However, we did discover a gap in our crash reporting: it failed to clearly show that the crash was a result of an overflow, which slowed down triage and response. This has been fixed, and we now have a clear signal when overflows occur into Scudo guard pages.
Unsafe Review and Training
Operating system development requires unsafe code, typically C, C++, or unsafe Rust (for example, for FFI and interacting with hardware), so simply banning unsafe code is not workable. When developers must use unsafe, they should understand how to do so soundly and responsibly
To that end, we are adding a new deep dive on unsafe code to our Comprehensive Rust training. This new module, currently in development, aims to teach developers how to reason about unsafe Rust code, soundness and undefined behavior, as well as best practices like safety comments and encapsulating unsafe code in safe abstractions.
Better understanding of unsafe Rust will lead to even higher quality and more secure code across the open source software ecosystem and within Android. As we'll discuss in the next section, our unsafe Rust is already really quite safe. It’s exciting to consider just how high the bar can go.
Comparing Vulnerability Densities
This near-miss inevitably raises the question: "If Rust can have memory safety vulnerabilities, then what’s the point?"
The point is that the density is drastically lower. So much lower that it represents a major shift in security posture. Based on our near-miss, we can make a conservative estimate. With roughly 5 million lines of Rust in the Android platform and one potential memory safety vulnerability found (and fixed pre-release), our estimated vulnerability density for Rust is 0.2 vuln per 1 million lines (MLOC).
Our historical data for C and C++ shows a density of closer to 1,000 memory safety vulnerabilities per MLOC. Our Rust code is currently tracking at a density orders of magnitude lower: a more than 1000x reduction.
Memory safety rightfully receives significant focus because the vulnerability class is uniquely powerful and (historically) highly prevalent. High vulnerability density undermines otherwise solid security design because these flaws can be chained to bypass defenses, including those specifically targeting memory safety exploits. Significantly lowering vulnerability density does not just reduce the number of bugs; it dramatically boosts the effectiveness of our entire security architecture.
The primary security concern regarding Rust generally centers on the approximately 4% of code written within unsafe{} blocks. This subset of Rust has fueled significant speculation, misconceptions, and even theories that unsafe Rust might be more buggy than C. Empirical evidence shows this to be quite wrong.
Our data indicates that even a more conservative assumption, that a line of unsafe Rust is as likely to have a bug as a line of C or C++, significantly overestimates the risk of unsafe Rust. We don’t know for sure why this is the case, but there are likely several contributing factors:
- unsafe{} doesn't actually disable all or even most of Rust’s safety checks (a common misconception).
- The practice of encapsulation enables local reasoning about safety invariants.
- The additional scrutiny that unsafe{} blocks receive.
Final Thoughts
Historically, we had to accept a trade-off: mitigating the risks of memory safety defects required substantial investments in static analysis, runtime mitigations, sandboxing, and reactive patching. This approach attempted to move fast and then pick up the pieces afterwards. These layered protections were essential, but they came at a high cost to performance and developer productivity, while still providing insufficient assurance.
While C and C++ will persist, and both software and hardware safety mechanisms remain critical for layered defense, the transition to Rust is a different approach where the more secure path is also demonstrably more efficient. Instead of moving fast and then later fixing the mess, we can move faster while fixing things. And who knows, as our code gets increasingly safe, perhaps we can start to reclaim even more of that performance and productivity that we exchanged for security, all while also improving security.
Acknowledgments
Thank you to the following individuals for their contributions to this post:
- Ivan Lozano for compiling the detailed postmortem on CVE-2025-48530.
- Chris Ferris for validating the postmortem’s findings and improving Scudo’s crash handling as a result.
- Dmytro Hrybenko for leading the effort to develop training for unsafe Rust and for providing extensive feedback on this post.
- Alex Rebert and Lars Bergstrom for their valuable suggestions and extensive feedback on this post.
- Peter Slatala, Matthew Riley, and Marshall Pierce for providing information on some of the places where Rust is being used in Google's apps.
Finally, a tremendous thank you to the Android Rust team, and the entire Android organization for your relentless commitment to engineering excellence and continuous improvement.
Notes
The DevOps Research and Assessment (DORA) program is published by Google Cloud. ↩
Last year, we wrote حول السبب وراء تحقيق استراتيجية سلامة الذاكرة التي تركز على منع الثغرات الأمنية في التعليمات البرمجية الجديدة لمكاسب دائمة ومركبة بسرعة. سننظر هذا العام في كيف لا يقتصر دور هذا النهج على إصلاح الأمور فحسب، بل يساعدنا على التحرك بشكل أسرع.
تستمر بيانات 2025 في التحقق من صحة النهج، مع انخفاض ثغرات أمان الذاكرة إلى أقل من 20% من إجمالي الثغرات الأمنية لأول مرة.
البيانات المحدثة لعام 2025. وتغطي هذه البيانات الطرف الأول والطرف الثالث (مفتوح المصدر). يتغير الكود إلى نظام Android الأساسي عبر C وC++ وJava وKotlin وRust. يتم نشر هذا المنشور قبل شهرين من نهاية عام 2025، ولكن نافذة التصحيح التي تبلغ 90 يومًا وفقًا لمعايير الصناعة لنظام Android تعني أن هذه النتائج من المحتمل جدًا أن تكون قريبة من النهائية. يمكننا تسريع عملية التصحيح عند الضرورة.
لقد اعتمدنا Rust من أجل أمانه ونشهد انخفاضًا بمقدار 1000 مرة في كثافة الثغرات الأمنية في الذاكرة مقارنة بكود Android C وC++. لكن المفاجأة الكبرى كانت تأثير Rust على توصيل البرامج. بفضل تغييرات Rust التي معدل تراجع أقل بمقدار 4 مرات وقضاء وقت أقل بنسبة 25% في مراجعة التعليمات البرمجية، أصبح المسار الأكثر أمانًا الآن هو المسار الأسرع أيضًا.
في هذا المنشور، نتعمق في البيانات الكامنة وراء هذا التحول ونغطي أيضًا:
- كيف نعمل على توسيع نطاق وصولنا: نحن نسعى جاهدين لجعل التعليمات البرمجية الآمنة هي الإعداد الافتراضي عبر مجموعة برامجنا بأكملها. لدينا تحديثات حول اعتماد Rust في تطبيقات الطرف الأول، ونواة Linux، والبرامج الثابتة.
- أول ثغرة أمنية لدينا في مجال سلامة ذاكرة الصدأ...تقريبًا: سنقوم بتحليل خطأ سلامة الذاكرة الوشيك في Rust غير الآمن: كيف حدث، وكيف تم تخفيفه، والخطوات التي نتخذها لمنع تكرارها. إنها أيضًا فرصة جيدة للإجابة على السؤال "إذا كان لدى Rust مشكلات تتعلق بسلامة الذاكرة، فلماذا تهتم على الإطلاق؟"
إنشاء برامج أفضل وأسرع
يتطلب تطوير نظام التشغيل مستوى منخفض من التحكم وإمكانية التنبؤ بلغات برمجة الأنظمة مثل C وC++ وRust. على الرغم من أهمية Java وKotlin في تطوير نظام Android الأساسي، إلا أن دورهما مكمل للغات الأنظمة وليس قابلاً للتبديل. We introduced Rust into Android كبديل مباشر لـ C وC++، حيث تقدم مستوى مشابهًا من التحكم ولكن دون الكثير من المخاطر. نحن نركز هذا التحليل على التعليمات البرمجية الجديدة والمطورة بنشاط لأن بياناتنا تظهر أن هذا هو an effective approach.
عندما ننظر إلى التطوير في لغات الأنظمة (باستثناء Java وKotlin)، يظهر اتجاهان: ارتفاع حاد في استخدام Rust وانخفاض أبطأ ولكن ثابت في C++ الجديد.
صافي أسطر التعليمات البرمجية المضافة: Rust مقابل C++، كود Android للطرف الأول.
يركز هذا المخطط على كود الطرف الأول (الذي طورته Google) (على عكس المخطط السابق الذي تضمن جميع أكواد الطرف الأول والطرف الثالث في Android.) نحن ندرج فقط لغات الأنظمة، C/C++ (وهي C++ بشكل أساسي)، وRust.
يوضح الرسم البياني أن حجم كود Rust الجديد ينافس الآن حجم C++، مما يتيح إجراء مقارنات موثوقة لمقاييس عملية تطوير البرامج. لقياس ذلك، نستخدم إطار عمل DORA1، وهو برنامج بحثي مدته عقد من الزمن والذي أصبح المعيار الصناعي لتقييم أداء فريق هندسة البرمجيات. DORA metrics التركيز على:
- الإنتاجية: سرعة تقديم تغييرات البرامج.
- الاستقرار: جودة تلك التغييرات.
قد تشكل المقارنات بين اللغات تحديًا. نحن نستخدم العديد من التقنيات لضمان موثوقية المقارنات.
- تغييرات مماثلة في الحجم: يتمتع كل من Rust وC++ بكثافة وظيفية مماثلة، على الرغم من أن Rust أكثر كثافة قليلاً. هذا الاختلاف يفضل C++، لكن المقارنة لا تزال صالحة. نحن نستخدم Gerrit’s change size definitions.
- مجموعات المطورين المماثلة: نحن نأخذ في الاعتبار فقط تغييرات الطرف الأول من مطوري نظام Android الأساسي. معظمهم مهندسو برمجيات في Google، وهناك تداخل كبير بين المجموعات حيث يساهم العديد منهم في كليهما.
- تتبع الاتجاهات بمرور الوقت: مع زيادة اعتماد Rust، هل تتغير المقاييس بشكل ثابت، أو تتسارع الوتيرة، أو تعود إلى المتوسط؟
الإنتاجية
تعد مراجعة التعليمات البرمجية جزءًا مستهلكًا للوقت وعالي الاستجابة من عملية التطوير. تعد إعادة صياغة التعليمات البرمجية المصدر الرئيسي لهذه التأخيرات المكلفة. تظهر البيانات أن كود Rust يتطلب مراجعات أقل. ظل هذا الاتجاه ثابتًا منذ عام 2023. تحتاج تغييرات Rust ذات الحجم المماثل إلى مراجعات أقل بنسبة 20% تقريبًا من نظيراتها في C++.
بالإضافة إلى ذلك، تقضي تغييرات Rust حاليًا وقتًا أقل بنسبة 25% تقريبًا في مراجعة التعليمات البرمجية مقارنة بـ C++. نعتقد أن التغيير الكبير لصالح Rust بين عامي 2023 و2024 يرجع إلى زيادة خبرة Rust في فريق Android.
بينما توفر عمليات إعادة صياغة أقل ومراجعات أسرع للكود مكاسب متواضعة في الإنتاجية، فإن التحسينات الأكثر أهمية تكمن في استقرار وجودة التغييرات.
الاستقرار
التغييرات المستقرة وعالية الجودة تميز Rust. تستخدم DORA معدل التراجع لتقييم استقرار التغيير. معدل التراجع عن Rust منخفض جدًا ويستمر في الانخفاض، حتى مع تجاوز اعتماده في Android لـ C++.
بالنسبة للتغييرات المتوسطة والكبيرة، فإن معدل التراجع عن تغييرات Rust في Android أقل بمقدار 4 مرات تقريبًا من C++. لا يشير معدل التراجع المنخفض هذا إلى الاستقرار فحسب؛ فهو يعمل بنشاط على تحسين إنتاجية التطوير الشاملة. تؤدي عمليات التراجع إلى تعطيل الإنتاجية بشكل كبير، مما يؤدي إلى احتكاك تنظيمي وتعبئة الموارد إلى ما هو أبعد من المطور الذي أرسل التغيير الخاطئ. تتطلب عمليات التراجع إعادة صياغة ومزيدًا من مراجعات التعليمات البرمجية، ويمكن أن تؤدي أيضًا إلى إنشاء فترات راحة، وتشريح ما بعد الوفاة، وعرقلة الفرق الأخرى. غالبًا ما تقدم عمليات التشريح اللاحقة ضمانات جديدة تضيف المزيد من أعباء التطوير.
في self-reported survey from 2022، أبلغ مهندسو برمجيات Google أن مراجعة Rust أسهل ومن المرجح أن تكون صحيحة. وتؤكد البيانات الثابتة المتعلقة بمعدلات التراجع وأوقات المراجعة هذه مرات الظهور.
تجميع كل ذلك معًا
من الناحية التاريخية، غالبًا ما كانت التحسينات الأمنية تأتي بتكلفة. المزيد من الأمان يعني مزيدًا من العمليات، أو أداءً أبطأ، أو ميزات متأخرة، مما يفرض المفاضلة بين الأمان وأهداف المنتج الأخرى. إن التحول إلى Rust مختلف: فنحن نعمل بشكل كبير على تحسين الأمان و كفاءة التطوير الرئيسية ومقاييس استقرار المنتج.
توسيع نطاق وصولنا
مع دعم Rust الآن لبناء خدمات ومكتبات نظام Android، فإننا نركز على جلب مزايا الأمان والإنتاجية إلى أماكن أخرى.
- النواة: نواة Linux 6.12 لنظام التشغيل Android هي أول نواة لدينا مع تمكين دعم Rust وأول إنتاج لنا. سائق الصدأ. هناك المزيد من المشاريع المثيرة قيد التنفيذ، مثل collaboration with Arm and Collabora on a Rust-based kernel-mode GPU driver الجاري تنفيذه.
- البرامج الثابتة: إن الجمع بين الامتيازات العالية وقيود الأداء والتطبيق المحدود للعديد من إجراءات الأمان يجعل البرامج الثابتة عالية المخاطر ويصعب تأمينها. يمكن أن يؤدي نقل البرامج الثابتة إلى Rust إلى تحسين كبير في الأمان. لقد كنا deploying Rust in firmware for years now، بل وقمنا بإصدار tutorials وtraining وcode للمجتمع الأوسع. نحن متحمسون بشكل خاص بشأن collaboration with Arm on Rusted Firmware-A.
- تطبيقات الطرف الأول: يضمن Rust سلامة الذاكرة من الألف إلى الياء في العديد من تطبيقات Google ذات الأهمية الأمنية، مثل:
- Nearby Presence: يتم تنفيذ بروتوكول اكتشاف الأجهزة المحلية بشكل آمن وخاصة عبر Bluetooth في Rust ويعمل حاليًا في Google Play Services.
- MLS: يتم تنفيذ بروتوكول مراسلة RCS الآمنة في Rust وسيتم تضمينه في تطبيق رسائل Google في إصدار مستقبلي.
- Chromium: تم استبدال المحللين اللغويين لـ PNG وJSON وweb fonts بتطبيقات آمنة للذاكرة في Rust، مما يسهل على مهندسي Chromium التعامل مع البيانات من الويب أثناء اتباع Rule of 2.
تسلط هذه الأمثلة الضوء على دور Rust. في تقليل المخاطر الأمنية، ولكن اللغات الآمنة للذاكرة ليست سوى جزء واحد من إستراتيجية شاملة لسلامة الذاكرة. نحن نواصل استخدام نهج دفاعي متعمق، وقد تجلت قيمته بوضوح في حادثة كادت أن تفشل مؤخرًا.
أول ثغرة أمنية لدينا في مجال أمان ذاكرة الصدأ...تقريبًا
لقد تجنبنا مؤخرًا شحن أول ثغرة أمنية في أمان الذاكرة المستندة إلى الصدأ: تجاوز سعة المخزن المؤقت الخطي في CrabbyAVIF. لقد كانت قريبة من الوقوع. لضمان حصول the patch على أولوية عالية وتتبعه من خلال قنوات الإصدار، قمنا بتعيين المعرف CVE-2025-48530 له. على الرغم من أنه من الرائع أن لم يتم نشر الثغرة الأمنية مطلقًا في إصدار عام، إلا أن هذه الثغرة الوشيكة تقدم دروسًا قيمة. تسلط الأقسام التالية الضوء على النقاط الرئيسية من تحليلنا بعد الوفاة.
أداة تخصيص Scudo المعززة للفوز
من النتائج الرئيسية هي أن أداة تخصيص Scudo المعززة لنظام Android جعلت هذه الثغرة الأمنية غير قابلة للاستغلال بشكل حتمي due to guard pages surrounding secondary allocations. على الرغم من أن Scudo هو المُخصص الافتراضي لنظام Android، ويتم استخدامه على Google Pixel والعديد من الأجهزة الأخرى، إلا أننا نواصل العمل مع الشركاء لجعله إلزاميًا. في هذه الأثناء، سنقوم بإصدار CVEs ذات خطورة كافية لنقاط الضعف التي يمكن منعها بواسطة Scudo.
بالإضافة إلى الحماية من التجاوزات، ساعد استخدام Scudo لصفحات الحماية في تحديد هذه المشكلة عن طريق تغيير التجاوز من تلف الذاكرة الصامت إلى تعطل صاخب. ومع ذلك، فقد اكتشفنا وجود فجوة في تقارير الأعطال لدينا: فقد فشل في إظهار أن العطل كان نتيجة لتجاوز السعة، مما أدى إلى إبطاء عملية الفرز والاستجابة. تم إصلاح هذه المشكلة، ولدينا الآن إشارة واضحة عند حدوث تجاوزات في صفحات Scudo Guard.
المراجعة والتدريب غير الآمنين
يتطلب تطوير نظام التشغيل تعليمات برمجية غير آمنة، عادةً C أو C++ أو Rust غير الآمن (على سبيل المثال، لـ FFI والتفاعل مع الأجهزة)، لذا فإن حظر التعليمات البرمجية غير الآمنة ببساطة غير قابل للتنفيذ. عندما يتعين على المطورين استخدام غير آمن، يجب عليهم فهم كيفية القيام بذلك بشكل سليم ومسؤول
ولتحقيق هذه الغاية، فإننا نضيف بحثًا عميقًا جديدًا حول التعليمات البرمجية غير الآمنة إلى Comprehensive Rust training. تهدف هذه الوحدة الجديدة، قيد التطوير حاليًا، إلى تعليم المطورين كيفية التفكير في كود Rust غير الآمن وسلامته وسلوكه غير المحدد، بالإضافة إلى أفضل الممارسات مثل التعليقات المتعلقة بالسلامة وتغليف التعليمات البرمجية غير الآمنة في تجريدات آمنة.
سيؤدي الفهم الأفضل لـ Rust غير الآمن إلى جودة أعلى وتعليمات برمجية أكثر أمانًا عبر النظام البيئي للبرامج مفتوحة المصدر وداخل Android. وكما سنناقش في القسم التالي، فإن الصدأ غير الآمن لدينا آمن تمامًا بالفعل. من المثير التفكير في مدى الارتفاع الذي يمكن أن يصل إليه المعيار.
مقارنة كثافات الثغرات الأمنية
يثير هذا الخطأ الوشيك حتمًا السؤال التالي: "إذا كان من الممكن أن يحتوي Rust على ثغرات أمنية في الذاكرة، فما المغزى إذن؟"
النقطة المهمة هي أن الكثافة أقل بشكل كبير. أقل بكثير مما يمثل تحولا كبيرا في الوضع الأمني. واستنادًا إلى توقعنا الوشيك، يمكننا إجراء تقدير متحفظ. مع وجود ما يقرب من 5 ملايين سطر من Rust في نظام Android الأساسي والعثور على ثغرة أمنية واحدة محتملة لسلامة الذاكرة (وإصدار مسبق ثابت)، تبلغ كثافة الثغرات الأمنية المقدرة لـ Rust 0.2 فولت لكل مليون سطر (MLOC).
تُظهر بياناتنا التاريخية لـ C وC++ كثافة تقترب من 1000 ثغرة أمنية لسلامة الذاكرة لكل MLOC. يتم حاليًا تتبع كود Rust الخاص بنا بمعدلات كثافة أقل من حيث الحجم: تقليل أكثر من 1000 مرة.
تحظى سلامة الذاكرة بحق بتركيز كبير لأن فئة الثغرات الأمنية قوية بشكل فريد ومنتشرة بشكل كبير (تاريخيًا). تؤدي كثافة الثغرات الأمنية العالية إلى تقويض التصميم الأمني القوي لأنه يمكن تقييد هذه العيوب لتجاوز الدفاعات، بما في ذلك تلك التي تستهدف عمليات استغلال سلامة الذاكرة على وجه التحديد. إن خفض كثافة الثغرات الأمنية بشكل كبير لا يؤدي فقط إلى تقليل عدد الأخطاء؛ فهو يعزز بشكل كبير فعالية بنية الأمان لدينا بالكامل.
تركز المخاوف الأمنية الأساسية المتعلقة بـ Rust بشكل عام على ما يقرب من 4% من التعليمات البرمجية المكتوبة ضمن كتل{} غير آمنة. لقد غذت هذه المجموعة الفرعية من الصدأ تكهنات ومفاهيم خاطئة كبيرة وحتى نظريات تشير إلى unsafe Rust might be more buggy than C. تُظهر الأدلة التجريبية أن هذا خطأ تمامًا.
تشير بياناتنا إلى أنه حتى الافتراض الأكثر تحفظًا، وهو أن خط الصدأ غير الآمن من المحتمل أن يحتوي على خطأ مثل خط C أو C++، يبالغ بشكل كبير في تقدير خطر الصدأ غير الآمن. لا نعرف على وجه اليقين سبب حدوث ذلك، ولكن من المحتمل أن يكون هناك العديد من العوامل المساهمة:
- غير آمن{} لا يؤدي فعليًا إلى تعطيل كل أو حتى معظم فحوصات الأمان في Rust (مفهوم خاطئ شائع).
- تُمكّن ممارسة التغليف التفكير المحلي حول ثوابت الأمان.
- التدقيق الإضافي الذي تتلقاه الكتل غير الآمنة{}.
أخير الأفكار
من الناحية التاريخية، كان علينا أن نقبل مقايضة: التخفيف من مخاطر عيوب سلامة الذاكرة يتطلب استثمارات كبيرة في التحليل الثابت، وتخفيف وقت التشغيل، ووضع الحماية، والتصحيح التفاعلي. حاول هذا النهج التحرك بسرعة ثم التقاط القطع بعد ذلك. كانت هذه الحماية الطبقية ضرورية، لكنها جاءت بتكلفة عالية على الأداء وإنتاجية المطورين، في حين لا تزال توفر ضمانًا غير كافٍ.
بينما ستستمر C وC++، وتظل آليات سلامة البرامج والأجهزة ضرورية للدفاع الطبقي، فإن الانتقال إلى Rust هو نهج مختلف حيث يكون المسار الأكثر أمانًا أيضًا أكثر كفاءة بشكل واضح. فبدلاً من التحرك بسرعة وثم إصلاح الفوضى لاحقًا، يمكننا التحرك بشكل أسرع أثناء إصلاح الأشياء. ومن يدري، مع تزايد أمان التعليمات البرمجية الخاصة بنا، ربما يمكننا البدء في استعادة المزيد من هذا الأداء والإنتاجية التي استبدلناها بالأمان، كل ذلك مع تحسين الأمان أيضًا.
شكر وتقدير
شكرًا للأفراد التاليين على مساهماتهم في هذا المنشور:
- إيفان لوزانو لتجميع التقرير التفصيلي بعد الوفاة حول CVE-2025-48530.
- كريس فيريس للتحقق من صحة نتائج التشريح وتحسين التعامل مع تحطم Scudo نتيجة لذلك.
- ديميترو هريبينكو لقيادة الجهود لتطوير التدريب على الصدأ غير الآمن ولتقديم تعليقات مكثفة على هذا المنشور.
- أليكس ريبرت ولارس بيرجستروم لاقتراحاتهم القيمة وتعليقاتهم الشاملة حول هذا المنشور.
- بيتر سلاتالا، ماثيو رايلي، ومارشال بيرس على توفير معلومات حول بعض الأماكن التي يتم فيها استخدام Rust في تطبيقات Google.
أخيرًا، شكرًا جزيلاً لفريق Android Rust، ومؤسسة Android بأكملها على التزامكم المتواصل بالتميز الهندسي والتحسين المستمر.
ملاحظات
يتم نشر برنامج DevOps Research and Assessment (DORA) بواسطة Google Cloud. ↩




