از 27 مارس 2025، توصیه می کنیم از android-latest-release به جای aosp-main برای ساختن و کمک به AOSP استفاده کنید. برای اطلاعات بیشتر، به تغییرات AOSP مراجعه کنید.
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
Scudo یک تخصیص دهنده حافظه پویا در حالت کاربر یا تخصیص دهنده هیپ است که به گونه ای طراحی شده است که در برابر آسیب پذیری های مرتبط با هیپ (مانند سرریز بافر مبتنی بر هیپ ، استفاده پس از آزاد شدن و دو برابر رایگان ) مقاوم باشد و در عین حال عملکرد را حفظ کند. این استانداردهای اولیه تخصیص و توزیع C (مانند malloc و رایگان)، و همچنین C++ اولیه (مانند جدید و حذف) را ارائه می دهد.
Scudo بیشتر یک کاهش دهنده است تا یک آشکارساز خطای حافظه کامل مانند AddressSanitizer (ASan) .
از زمان انتشار اندروید 11، scudo برای همه کدهای بومی استفاده می شود (به جز در دستگاه های با حافظه کم، جایی که هنوز از jemalloc استفاده می شود). در زمان اجرا، همه تخصیصها و تخصیصهای محلی Heap توسط Scudo برای همه فایلهای اجرایی و وابستگیهای کتابخانهای آنها سرویس میشوند و در صورت شناسایی خرابی یا رفتار مشکوک در پشته، این فرآیند متوقف میشود.
می توانید با استفاده از گزینه های شرح داده شده در زیر، کاهش اضافی را در تخصیص دهنده فعال یا غیرفعال کنید.
سفارشی سازی
برخی از پارامترهای تخصیص دهنده را می توان بر اساس هر فرآیند از چند راه تعریف کرد:
Statically: یک تابع __scudo_default_options را در برنامه تعریف کنید که رشته گزینه ها را برای تجزیه برمی گرداند. این تابع باید نمونه اولیه زیر را داشته باشد: extern "C" const char *__scudo_default_options() .
به صورت پویا: از متغیر محیطی SCUDO_OPTIONS که شامل رشته گزینه هایی است که باید تجزیه شوند استفاده کنید. گزینههایی که به این روش تعریف میشوند، هر تعریفی را که از طریق __scudo_default_options ایجاد شده است، لغو میکنند.
گزینه های زیر در دسترس هستند.
گزینه
64 بیت پیش فرض
32 بیت پیش فرض
توضیحات
QuarantineSizeKb
256
64
اندازه (به کیلوبایت) قرنطینه مورد استفاده برای به تاخیر انداختن تخصیص واقعی تکه ها. مقدار کمتر ممکن است استفاده از حافظه را کاهش دهد اما اثربخشی کاهش را کاهش دهد. یک مقدار منفی به حالت پیش فرض برمی گردد. صفر کردن این و ThreadLocalQuarantineSizeKb قرنطینه را به طور کامل غیرفعال می کند.
QuarantineChunksUpToSize
2048
512
اندازه (بر حسب بایت) که تا آن تکه ها را می توان قرنطینه کرد.
ThreadLocalQuarantineSizeKb
64
16
اندازه (به کیلوبایت) حافظه نهان در هر رشته برای تخلیه قرنطینه جهانی استفاده می شود. مقدار کمتر ممکن است استفاده از حافظه را کاهش دهد اما ممکن است مشاجره در قرنطینه جهانی را افزایش دهد. صفر کردن این و QuarantineSizeKb قرنطینه را به طور کامل غیرفعال می کند.
DeallocationTypeMismatch
false
false
گزارش خطا در malloc/delete، new/free، new/delete[]
DeleteSizeMismatch
true
true
گزارش خطا در مورد عدم تطابق بین اندازه های جدید و حذف را فعال می کند.
ZeroContents
false
false
محتویات قطعه صفر را در تخصیص و تخصیص فعال می کند.
allocator_may_return_null
false
false
مشخص میکند که تخصیصدهنده میتواند در صورت بروز خطای قابل بازیابی، به جای پایان دادن به فرآیند، null را برگرداند.
hard_rss_limit_mb
0
0
هنگامی که RSS فرآیند به این حد می رسد، فرآیند خاتمه می یابد.
soft_rss_limit_mb
0
0
هنگامی که RSS فرآیند به این حد می رسد، تخصیص های بیشتر با شکست مواجه می شوند یا null برمی گردند (بسته به مقدار allocator_may_return_null )، تا زمانی که RSS به پایین برود تا امکان تخصیص های جدید فراهم شود.
allocator_release_to_os_interval_ms
5000
N/A
فقط یک تخصیص دهنده 64 بیتی را تحت تأثیر قرار می دهد. در صورت تنظیم، سعی می کند حافظه استفاده نشده را در سیستم عامل آزاد کند، اما نه بیشتر از این فاصله زمانی (بر حسب میلی ثانیه). اگر مقدار منفی باشد، حافظه در سیستم عامل آزاد نمی شود.
abort_on_error
true
true
در صورت تنظیم، ابزار پس از چاپ پیام خطا به جای _exit()abort() فراخوانی می کند.
اعتبار سنجی
در حال حاضر هیچ آزمایش CTS به طور خاص برای Scudo وجود ندارد. درعوض، مطمئن شوید که تستهای CTS با یا بدون فعال بودن Scudo برای یک باینری معین انجام میشود تا مطمئن شوید که روی دستگاه تأثیر نمیگذارد.
عیب یابی
اگر مشکلی غیر قابل بازیابی تشخیص داده شود، تخصیص دهنده پیام خطا را به توصیفگر خطای استاندارد نمایش می دهد و سپس فرآیند را خاتمه می دهد. ردپای پشته ای که منجر به خاتمه می شود در گزارش سیستم اضافه می شود. خروجی معمولاً با Scudo ERROR: پس از آن یک خلاصه کوتاه از مشکل به همراه هر نشانگر ارائه می شود.
در اینجا لیستی از پیام های خطای فعلی و دلایل احتمالی آنها آمده است:
corrupted chunk header : تأیید جمعبندی بررسی سرصفحه قطعه ناموفق بود. این احتمالاً به دلیل یکی از این دو مورد است: هدر بازنویسی شده است (جزئی یا کامل)، یا نشانگر ارسال شده به تابع یک تکه نیست.
race on chunk header : دو رشته مختلف در حال تلاش برای دستکاری یک هدر در یک زمان هستند. این معمولاً علامت یک وضعیت مسابقه یا عدم قفل کلی هنگام انجام عملیات روی آن قطعه است.
invalid chunk state : قطعه در حالت مورد انتظار برای یک عملیات مشخص نیست، به عنوان مثال، هنگام تلاش برای آزاد کردن آن تخصیص داده نمی شود، یا هنگام تلاش برای بازیافت آن قرنطینه نمی شود. دو برابر رایگان دلیل معمولی برای این خطا است.
misaligned pointer : الزامات اصلی تراز به شدت اعمال می شود: 8 بایت در سیستم عامل های 32 بیتی و 16 بایت در سیستم عامل های 64 بیتی. اگر اشاره گر ارسال شده به توابع ما با آن ها مطابقت نداشته باشد، اشاره گر ارسال شده به یکی از توابع خارج از تراز است.
allocation type mismatch : هنگامی که این گزینه فعال است، یک تابع توزیع فراخوانی شده روی یک قطعه باید با نوع تابعی که برای تخصیص فراخوانی شده است مطابقت داشته باشد. این نوع عدم تطابق می تواند مسائل امنیتی را ایجاد کند.
invalid sized delete : زمانی که از اپراتور حذف با اندازه C++14 استفاده میشود و بررسی اختیاری فعال است، بین اندازهای که در هنگام اختصاص دادن یک قطعه ارسال شده و اندازه درخواست شده هنگام تخصیص آن ناسازگاری وجود دارد. این معمولاً یک مشکل کامپایلر یا یک سردرگمی نوع در شیء در حال واگذاری است.
RSS limit exhausted : از حداکثر RSS که به صورت اختیاری مشخص شده است تجاوز کرده است.
اگر در حال اشکال زدایی یک خرابی در خود سیستم عامل هستید، می توانید از ساخت سیستم عامل HWASan استفاده کنید. اگر در حال رفع اشکال یک خرابی در یک برنامه هستید، میتوانید از ساخت برنامه HWASan نیز استفاده کنید.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Scudo is a dynamic user-mode memory allocator, or *heap* allocator, designed\nto be resilient against heap-related vulnerabilities (such as [heap-based buffer\noverflow](https://cwe.mitre.org/data/definitions/122.html), [use after free](https://cwe.mitre.org/data/definitions/416.html),\nand [double free](https://cwe.mitre.org/data/definitions/415.html))\nwhile maintaining performance. It provides the standard C allocation and\ndeallocation primitives (such as [malloc](http://pubs.opengroup.org/onlinepubs/009695399/functions/malloc.html) and free), as well as the C++ primitives (such as new and delete).\n\nScudo is more of a mitigation than a fully fledged memory error\ndetector like [AddressSanitizer (ASan)](/docs/security/test/sanitizers#addresssanitizer).\n\nSince the Android 11 release, scudo is used for all native code\n(except on low-memory devices, where jemalloc is still used). At runtime, all native heap\nallocations and deallocations are serviced by Scudo for all executables and their library\ndependencies, and the process is aborted if a corruption or suspicious\nbehavior is detected in the heap.\n\nScudo is [open source](https://github.com/llvm/llvm-project/tree/main/compiler-rt/lib/scudo) and part of LLVM's compiler-rt project. Documentation is\navailable at \u003chttps://llvm.org/docs/ScudoHardenedAllocator.html\u003e. The Scudo runtime ships\nas part of the Android toolchain and support was added to [Soong and Make](https://android.googlesource.com/platform/build/soong/)\nto allow for easy enabling of the allocator in a binary.\n\nYou can enable or disable extra mitigation within\nthe allocator using the options described below.\n\nCustomization\n-------------\n\nSome parameters of the allocator can be defined on a per-process basis\nthrough several ways:\n\n- **Statically:** Define a `__scudo_default_options` function in the program that returns the options string to be parsed. This function must have the following prototype: `extern \"C\" const char\n *__scudo_default_options()`.\n- **Dynamically:** Use the environment variable `SCUDO_OPTIONS` containing the options string to be parsed. Options defined this way override any definition made through `__scudo_default_options`.\n\nThe following options are available.\n| **Note:** Frontend options have a different name format than backend options.\n\n| Option | 64-bit default | 32-bit default | Description |\n|---------------------------------------|----------------|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `QuarantineSizeKb` | `256` | `64` | The size (in KB) of quarantine used to delay the actual deallocation of chunks. A lower value may reduce memory usage but decrease the effectiveness of the mitigation; a negative value falls back to the defaults. Setting both this and `ThreadLocalQuarantineSizeKb` to zero disables the quarantine entirely. |\n| `QuarantineChunksUpToSize` | `2048` | `512` | The size (in bytes) up to which chunks can be quarantined. |\n| `ThreadLocalQuarantineSizeKb` | `64` | `16` | The size (in KB) of per-thread cache use to offload the global quarantine. A lower value may reduce memory usage but might increase contention on the global quarantine. Setting both this and `QuarantineSizeKb` to zero disables the quarantine entirely. |\n| `DeallocationTypeMismatch` | `false` | `false` | Enables error reporting on malloc/delete, new/free, new/delete\\[\\] |\n| `DeleteSizeMismatch` | `true` | `true` | Enables error reporting on mismatch between sizes of new and delete. |\n| `ZeroContents` | `false` | `false` | Enables zero chunk contents on allocation and deallocation. |\n| `allocator_may_return_null` | `false` | `false` | Specifies that the allocator can return null when a recoverable error occurs, instead of terminating the process. |\n| `hard_rss_limit_mb` | `0` | `0` | When the process's RSS reaches this limit, the process terminates. |\n| `soft_rss_limit_mb` | `0` | `0` | When the process's RSS reaches this limit, further allocations fail or return `null` (depending on the value of `allocator_may_return_null`), until the RSS goes back down to allow for new allocations. |\n| `allocator_release_to_os_interval_ms` | `5000` | N/A | Only affects a 64-bit allocator. If set, tries to release unused memory to the OS, but not more often than this interval (in milliseconds). If the value is negative, memory isn't released to the OS. |\n| `abort_on_error` | `true` | `true` | If set, the tool calls `abort()` instead of `_exit()` after printing the error message. |\n\nValidation\n----------\n\nCurrently, there are no CTS tests specifically for Scudo. Instead, make sure\nthat CTS tests pass with or without Scudo enabled for a given binary to verify\nthat it doesn't impact the device.\n\nTroubleshooting\n---------------\n\nIf a non-recoverable issue is detected, the allocator\ndisplays an error message to the standard error descriptor and then terminates the process.\nStack traces that lead to the termination are added in the system log.\nThe output usually starts with `Scudo ERROR:` followed by a\nshort summary of the problem along with any pointers.\n| **Note:** Again, Scudo is meant to be a mitigation. Consider using ASan to determine the root cause of the issue.\n\nHere is a list of the current error messages and their potential\ncauses:\n\n- `corrupted chunk header`: The checksum verification of the chunk header has failed. This is likely due to one of two things: the header was overwritten (partially or totally), or the pointer passed to the function is not a chunk.\n- `race on chunk header`: Two different threads are attempting to manipulate the same header at the same time. This is usually symptomatic of a race-condition or general lack of locking when performing operations on that chunk.\n- `invalid chunk state`: The chunk isn't in the expected state for a given operation, for example, it's not allocated when trying to free it, or it's not quarantined when trying to recycle it. A double free is the typical reason for this error.\n- `misaligned pointer`: Basic alignment requirements are strongly enforced: 8 bytes on 32-bit platforms and 16 bytes on 64-bit platforms. If a pointer passed to our functions does not fit those, the pointer passed to one of the functions is out of alignment.\n- `allocation type mismatch`: When this option is enabled, a deallocation function called on a chunk has to match the type of function that was called to allocate it. This type of mismatch can introduce security issues.\n- `invalid sized delete`: When the C++14 sized delete operator is used, and the optional check is enabled, there's a mismatch between the size that was passed when deallocating a chunk and the size that was requested when allocating it. This is typically a compiler issue or a [type confusion](https://cwe.mitre.org/data/definitions/843.html) on the object being deallocated.\n- `RSS limit exhausted`: The maximum RSS optionally specified has been exceeded.\n\n\nIf you're debugging a crash in the OS itself, you can use a\n[HWASan OS build](/devices/tech/debug/hwasan). If you're\ndebugging a crash in an app, it's possible to use a\n[HWASan app build](https://developer.android.com/ndk/guides/hwasan) too."]]