{"id":18422474,"url":"https://github.com/sri-csl/sri-glibc-malloc","last_synced_at":"2026-01-28T22:31:47.168Z","repository":{"id":137662422,"uuid":"69708748","full_name":"SRI-CSL/sri-glibc-malloc","owner":"SRI-CSL","description":"SRI's modification of glibc malloc that eliminates metadata in client memory.","archived":false,"fork":false,"pushed_at":"2016-11-03T16:50:50.000Z","size":1447,"stargazers_count":2,"open_issues_count":0,"forks_count":3,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-07T15:44:08.181Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SRI-CSL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-30T23:25:43.000Z","updated_at":"2020-08-25T13:46:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"59724c85-6f3c-4822-b46e-72773ce8e960","html_url":"https://github.com/SRI-CSL/sri-glibc-malloc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SRI-CSL/sri-glibc-malloc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SRI-CSL%2Fsri-glibc-malloc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SRI-CSL%2Fsri-glibc-malloc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SRI-CSL%2Fsri-glibc-malloc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SRI-CSL%2Fsri-glibc-malloc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SRI-CSL","download_url":"https://codeload.github.com/SRI-CSL/sri-glibc-malloc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SRI-CSL%2Fsri-glibc-malloc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28853537,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T15:15:36.453Z","status":"ssl_error","status_checked_at":"2026-01-28T15:15:13.020Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T04:30:21.091Z","updated_at":"2026-01-28T22:31:47.151Z","avatar_url":"https://github.com/SRI-CSL.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n\n# Overview\n\nThis software is a variant of the malloc subsystem of GNU's Standard C\nlibrary (GLibc).  It separates the metadata from the client memory for\nincreased security.  The software currently targets the x86_64 linux\narchitecture and has been tested mainly on Ubuntu 14.04. It is based\non glibc-2.23.\n\n\n#  Building\n\nTyping `make` at the toplevel should build an entire installation\nof Glibc with our modifications in place. \n\nThis will:\n\n* download the glibc source in `./build/glibc` and `git checkout glibc-2.23`.\n* configure the build in `./build/glibc-build`\n* compile and install in `./build/glibc-install`\n\n\n# Testing \n\nA very basic test can be done by doing `make check` at the top level.\n\n### Using the testrun.sh script to test applications\n\nIn the simple case, your executable does not require any dynamic library other than glibc.\nYou can test our library as follows:\n```\n./build/glibc-build/testrun.sh /bin/echo \"Boo!\"\n```\nThis example runs the `/bin/echo` program with argument `\"Boo!\"` using the\nGLibc built in `./build/glibc-build`. In particular, the executable will use SRI's malloc.\n\n\nIf your executable relies on other dynamic libraries than glibc, then either add symbolic\nlinks or copy the libraries into the  `./build/glibc-build` area. \nFor example, `/bin/ls` on Ubuntu 14.04 requires four dynamic libraries. To run it with\nour malloc implementation:\n\n* link the required libraries into the `./build/glibc-build` directory:\n```\ncd ./build/glibc-build\n\nln -s /lib/x86_64-linux-gnu/libselinux.so.1 .\nln -s /lib/x86_64-linux-gnu/libacl.so.1 .\nln -s /lib/x86_64-linux-gnu/libpcre.so.3 .\nln -s /lib/x86_64-linux-gnu/libattr.so.1 .\n```\n* use the `testrun.sh` script:\n```\ncd ../../\n\n./build/glibc-build/testrun.sh /bin/ls\n```\n\nMore information about testing glibc builds can be found [here](https://sourceware.org/glibc/wiki/Testing/Builds).\n\n\n### Using the mhooks and replay programs for debugging\n\nWe have developed another approach to testing and analysis. This technique uses the malloc\nhooks to record (using the tool in `src/mhooks`) in a file the pattern \nof allocation of a particular program:\n```\nMHOOK=/tmp/mhook.out LD_PRELOAD=./mhook.so /bin/ls -la\n```\nThis will produce a log of the allocations/deallocation/reallocation operations, that can be replayed (or analyzed).\nTo replay it one would (in `src/glibc_test`) do \n```\n ./replay /tmp/mhook.out\n```\nThis will replay the pattern of allocation and return some statistics.\n```\n...\nmalloc   0.22  clocks per call\nfree   0.19  clocks per call\ncalloc   1.89  clocks per call\nrealloc  1.00  clocks per call\n...\n```\nThe replaying is currently only implemented for single threaded programs,\nthough in principle it could be extended to multithreaded programs. We have\nalso included a script `analysis/parse_data` that will summarize the pattern\nof allocation in the hook file:\n```\n\u003e./parse_data /tmp/mhook.out\n../src/mhooks/mhook.out contains 405 mallocs\n../src/mhooks/mhook.out contains 9 callocs\n../src/mhooks/mhook.out contains 3 reallocs\n../src/mhooks/mhook.out contains 295 frees\n           2 3\n           4 6\n           8 30\n          16 54\n          32 230\n          64 49\n         128 15\n         256 11\n         512 7\n        1024 9\n        2048 1\n       16384 1\n       32768 1\n```\nThe analysis consists of an overview and a log histogram of the allocations \n(3 of size \u003c 2, 6 of size \u003c 4, ...)\n\n### Using gdb ...\n\n\n# Design Details\n\nWe have attempted to make as few changes to the underlying\nglibc/ptmalloc/dlmalloc algorithms in order to achieve our\ngoal.\n\nThe metadata for a client pointer is contained in a per arena hash table.\nAccess to this table is protected by the same lock that protects access\nto other aspects of the arena (such as the bins etc). So no additional\nsynchronization overhead is incurred in accessing a pointer's metadata,\nonce the pointer's arena has been established.\nThe per arena hash table is an implementation of Dynamic hashing\nby Per-Ake Larson (CACM April 1988 pp 446-457), supported underneath\nby a custom pool allocator that relies on mmapped regions.\n\nDetermining which arena a client pointer belongs to is done by\na *lock-free* algorithm that keeps track of the underlying\nregions that are under our control.\n\n\n* Things that we could elaborate on: \n  * Pointers to the files in question?\n  * Maintaining the important glibc invariant (no adjacent free chunks).\n  * Mmapped memory also has metadata, which we store in the main arena.\n  * Chunks no longer overlap.\n  * Minimum size increased so as to avoid messing with the fenceposts.\n  * Memory exhaustion robustness\n  \n\n# Testing Regime\n\nWe have tested our prototype on a set of applications that\nmake heavy use of dynamic-memory allocation. Our primary tests include\nthe Yices regression tests, benchmarks for Cryptominisat, a\nmulti-threaded Boolean SAT solver, and the SPEC CPU 2006 integer\nbenchmark suite.  \n\n\n# Performance Measurements\n\nWe ran the SPEC CPU 2006 integer benchmark suite. In this table we present the \naverage runtime over 8 iterations, as well the overhead percentage.\n```\n               sri-glibc   glibc     % Overhead\n400.perlbench    387       335       15.52 \n401.bzip2        458       451       1.55 \n403.gcc          295       291       1.37 \n429.mcf          536       518       3.47 \n445.gobmk        427       428       -0.23 \n456.hmmer        397       397       0.0 \n458.sjeng        490       490       0.0 \n462.libquantum   342       342       0.0 \n464.h264ref      510       509       0.2 \n471.omnetpp      547       385       42.08 \n473.astar        450       442       1.81 \n483.xalancbmk    364       323       12.69 \n```\nNote the these benchmarks are single threaded, and so are not a complete picture.\nDetermining that a pointer belongs to the `main_arena` is faster than \ndetermining that it is either mmapped or belongs to a non main arena.\n\nWe would be very interested to hear of some multithreaded benchmarks that we could\ninclude.\n\n# Possible Improvements\n\n* It needs to be fully assimilated into glibc, for example the atomics we use are\nnot the glibc versions.\n\n* It should be brought upto date with the more recent changes in glibc's malloc.\n\n* The lock free hash table is probably not as polished as it could be.\n\n* The minimun chunksize could drop, provided the fencepost code was rewritten.\n\n* Understanding the omnetpp slow down could be illuminating.\n\n* Multithreaded benchmarking would be nice, and hopefully not too embarrasing.\n\n# Acknowledgements\n\nThis document summarizes the research performed under Darpa Contract\nNumber N66001-15-C-4061 by SRI International, and presents the\nproject's results. The project started in August 2015 and was\ncompleted in August 2016. The Principal Investigator for this project\nwas Drew Dean, until his departure in July 2016. Ian A. Mason took\nover as PI after Drew Dean left. The co-investigators were Bruno\nDutertre (SRI) and Dan Wallach (Rice University).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsri-csl%2Fsri-glibc-malloc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsri-csl%2Fsri-glibc-malloc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsri-csl%2Fsri-glibc-malloc/lists"}