summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/malloc.c
AgeCommit message (Collapse)Author
2009-06-08quieten compiler by converting pointers to uintptr_t before truncating themTheo de Raadt
to u_int32_t to do integer math with (in a situation where that is legit) ok otto millert
2009-01-03reintroduce extra malloc protections, but avoiding the use ofDamien Miller
PAGE_(SIZE|SHIFT|MASK) defines that evaluate to variables on the sparc architecture; ok otto@ tested on my reanimated ss20
2008-12-31PAGE_SIZE is not a valid symbol to use in that way. In particular,Theo de Raadt
on sparc, it expands to something that just plain does not work, because the page size can be variable. Sorry we didn't spot this before. Backing it all out to allow sparc to build; please find a different way to fix it.
2008-12-30Remove mprotecting of struct dir_info introduced in previous commitDamien Miller
(MALLOC_OPTIONS=L). It was too slow to turn on by default, and we don't do optional security. requested by deraadt@ grumbling ok otto@
2008-12-29extra paranoia for malloc(3):Damien Miller
Move all runtime options into a structure that is made read-only (via mprotect) after initialisation to protect against attacks that overwrite options to turn off malloc protections (e.g. use-after-free) Allocate the main bookkeeping data (struct dir_info) using mmap(), thereby giving it an unpredictable address. Place a PROT_NONE guard page on either side to further frustrate attacks on it. Add a new 'L' option that maps struct dir_info PROT_NONE except when in the allocator code itself. Makes attacks on it basically impossible. feedback tedu deraadt otto canacar ok otto
2008-12-15shave off more bytes than you expect by declaring a few const local arraysOtto Moerbeek
as static const
2008-11-20move allocations between half a page and a page as close to the end ofOtto Moerbeek
the page as possible (i.e. make malloc option P a default). ok art@ millert@ krw@
2008-11-20Reduce the leeway malloc allows when moving allocations to the end ofOtto Moerbeek
a page to 0. P default will be changed in a separate commit. ok millert@ art@ krw@
2008-11-13To allow for easier playing with more strict settings introduceOtto Moerbeek
a separate symbolic constant for the leeway we allow when moving allocations towards the end of a page. No functional change.
2008-11-12avoid a few strlen calls for constant strings; prompted by tg; ok djm@Otto Moerbeek
2008-11-06if the freeprot flag (F) is set, do not do delayed frees for chunksOtto Moerbeek
(might catch errors closer to the trouble spot) and junk fill pages just before reuse instead of immediate (we can't access the page anyway) since we set PROT_NONE in the F case. ok djm@
2008-11-02remove distinction between warnings and errors, ok deraadt@ djm@Otto Moerbeek
2008-10-29if MALLOC_STATS is defined, record how many "cheap reallocs" wereOtto Moerbeek
tried and how many actually succeeded.
2008-10-20oops, assign errno the right way. caught by david running regress testsOtto Moerbeek
2008-10-03reduce rbyte cache to 512 bytes, no measurable slowdown (even in theOtto Moerbeek
threaded case) but much smaller working set; prompted by and ok deraadt@
2008-10-03save and restore errno on success. while it is not stricly needed forOtto Moerbeek
non-syscalls, there's just too much code not doing the right thing on error paths; prompted by and ok deraadt@
2008-10-03when increasing the size of a larger than a page allocation tryOtto Moerbeek
mapping the region next to the existing one first; there's a pretty high chance there's a hole there we can use; ok deraadt@ tedu@
2008-10-03avoid spitting up regions when purging stuff from the cache, it putsOtto Moerbeek
too much pressure on the amaps. ok tedu@ deraadt@
2008-08-25Make all combinations of G, P, J and zero-fill work with as littleOtto Moerbeek
effort as possible in most cases; ok djm@
2008-08-23unbreak MALLOC_OPTIONS=G that I broke in my last commit;Damien Miller
slightly kludgey solution for until otto fixes it properly; ok otto@
2008-08-23fix calloc() for MALLOC_OPTIONS=J case: SOME_JUNK was being filled intoDamien Miller
the freshly mmaped pages disrupting their pure zeroness; ok otto@ deraadt@
2008-08-22make sure we always map and unmap multiples of MALLOC_PAGESIZE;Otto Moerbeek
case spotted by beck, one by me; ok deraadt@ beck@
2008-08-22Smarter implementation of calloc(3), which uses the fact that mmap(2)Otto Moerbeek
returns zero filled pages; remember to replace this function as well if you provide your own malloc implementation; ok djm@ deraadt@
2008-08-07small cleanup of error/warning stringsOtto Moerbeek
2008-07-28Almost complete rewrite of malloc, to have a more efficient dataOtto Moerbeek
structure of tracking pages returned by mmap(). Lots of testing by lots of people, thanks to you all. ok djm@ (for a slighly earlier version) deraadt@
2008-06-13remove _MALLOC_LOCK_INIT; major bump; ok deraadt@Otto Moerbeek
2008-05-19remove recalloc(3); it is buggy and impossible to repair without bigOtto Moerbeek
costs; ok jmc@ for the man page bits; ok millert@ deraadt@
2008-04-13Use arc4random_buf() when requesting more than a single word of outputDamien Miller
Use arc4random_uniform() when the desired random number upper bound is not a power of two ok deraadt@ millert@
2008-02-20use pgfree pool like other code does to reserve free list slots.Otto Moerbeek
prevents a few "cannot free mem because i need mem to free mem" scenarios (one found by weingart@). ok weingart@ millert@ miod@
2007-09-03add recaloc(3)Todd C. Miller
2007-02-12get cheaper random bytes, less waste and no getpid() calls, which areOtto Moerbeek
done by arc4random(); ok millert@ deraadt@
2006-12-19a failed mmap returns MAP_FAILED, not NULL. found while exercising paxOtto Moerbeek
in low-mem conditions; ok dim@
2006-10-24respond to ben hawkes's ruxcon presentation.Ted Unangst
create special allocators for pginfo and pgfree structs instead of imalloc. this keeps them separated from application memory. for chunks, to prevent deterministic reuse, keep a small array and swizzle the to be freed chunk with a random previously freed chunk. this last bit only for chunks because keeping arbitrarily large regions of pages around may cause out of memory issues (and pages are, to some extent, returned in random order). all changes enabled by default. thanks to ben for pointing out these issues. ok tech@
2006-05-14Fix the second malloc_ulimit regression: maintaining the free listOtto Moerbeek
requires memory; try to make sure we have it. If all fails, leak instead of crash. Test case originally found by cloder@, fix tested by many.
2006-04-24Do not leave an hole in the directory list if allocation of theOtto Moerbeek
region succeeds, but allocation a required page dir failed. This can happen if we're really close to ulimit after allocation the region of the size requested. See malloc_ulimit1 regress test. Tested by many; thanks.
2006-04-18delint; original from deraadt@ with fixes from tdeval@ and me;Otto Moerbeek
tested by quite a few developers. ok deraadt@
2006-02-14quick path for free(0)Marc Espie
`looks to be safe' millert, okay tedu.
2005-10-10Remove a few warnings. Those were not apparent thanks to a bug in gcc 2.95.Marc Espie
Patch by Leonardo Chiquitto Filho <leonardo@iken.com.br> Thanks.
2005-10-05further knf and cleaning; ok tdevalTheo de Raadt
2005-10-05first KNF (no binary diffs)Theo de Raadt
2005-08-08zap remaining rcsid.Marc Espie
Kill old files that are no longer compiled. okay theo
2005-07-07Fix the unmapping of freed pages, leaving just 64k worth of cache pages.Thierry Deval
Prodded by art@ and fgsch@, ok deraadt@
2005-06-07adding pointer protection to 'G' was too heavyweight. Since malloc guardTed Unangst
should be generally usable, split this out into option 'P'. ok deraadt
2005-05-24handle sizeof(void *) allocations specially when using malloc guard.Ted Unangst
they get a whole page and go right at the end of it. ok deraadt tdeval
2005-03-31MMAP(2) malloc, here we go again.Thierry Deval
2004-08-11Back out to brk(2) version.Thierry Deval
The mmap(2) code is cool and it has already uncovered some bugs in other code. But some issues remain on some archs, and we can't afford that for production. Don't worry, it will be back soon... I'll make sure of it...
2004-08-05- Remove the userland data limit check. It's mmap(2)'s job.Thierry Deval
- When malloc_abort==0 (MALLOC_OPTIONS=a), don't abort in wrterror(). fine deraadt@
2004-08-04Missing check for NULL.Thierry Deval
2004-08-01After a long gestation period, here comes our custom version of malloc(3)Thierry Deval
using mmap(2) instead of sbrk(2). To make a long story short, using mmap(2) in malloc(3) allows us to draw all the benefits from our mmap(2)'s randomization feature, closing the effort we did for returning memory blocks from random addresses. Tested for a long time by many, thanks to them. Go for it ! deraadt@
2004-04-12Clean up malloc_active state when aborting.Thierry Deval
This allows for safe abort handling, without tripping into false recursivity problems. Ok tedu@, deraadt@