[[["わかりやすい","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-03-26 UTC。"],[],[],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."]]