Skip to content

fix possible integer overflow in alloc()#109

Merged
DerDakon merged 1 commit into
masterfrom
Dakon-alloc-align
Dec 27, 2019
Merged

fix possible integer overflow in alloc()#109
DerDakon merged 1 commit into
masterfrom
Dakon-alloc-align

Conversation

@DerDakon

Copy link
Copy Markdown
Member

If n is close to 2**32 then the alignment calculation could cause an integer overflow. Rule this out by checking if the allocation is smaller than the fixed buffer. It could be done by checking against the possible space, which is done later anyway, but checking against SPACE has the benefit that this is a constant.

Alternative implementation for #37.

@DerDakon DerDakon added the bug Something isn't working label Dec 26, 2019
@DerDakon DerDakon added this to the 1.08 milestone Dec 26, 2019
Comment thread alloc.c Outdated
Comment thread alloc.c Outdated
If n is close to 2**32 then the alignment calculation could cause an integer
overflow. Rule this out by checking if the allocation is smaller than the fixed
buffer. It could be done by checking against the possible space, which is done
later anyway, but checking against SPACE has the benefit that this is a
constant.
@DerDakon
DerDakon merged commit 75a935b into master Dec 27, 2019
@DerDakon
DerDakon deleted the Dakon-alloc-align branch December 27, 2019 14:18
DerDakon added a commit that referenced this pull request Dec 27, 2019
 * it's as simple as possible, probably intentional. This makes things like
   alloc_re() (i.e. realloc()) inefficient as it does not look if the thing it
   reallocates is already the last thing in the batch, and simply extends that,
   or if alloc_free() has the last block and adds things back to the pool
   (ideally with zeroing for security reasons).
 * it makes it basically impossible to detect overruns on early small
   allocations with tools like valgrind, address sanitizer or friends as
   those allocations never hit malloc(), so are never traced by any custom
   tools. Any overrun will just go into the next variable, untracable.
 * allocators do their own buffering, alignment, and so on. If they are broken,
   your system is severely screwed. And if we need more money^H^H^H^Hemory we
   will hit that buggy allocatator anyway, making things harder to detect as
   it will only happen on "heavy" memory usage. This is not TruOS, SunOS 1.x
   or something like that anymore. We expect a reasonably sane OS. Everything
   else will get us screwed in much more severe ways.
 * it has shown issues when coming close to 4GiB allocations (#37, #109, older
   reports). DJB correctly says that an allocation of that size in your mailer
   shows that you have already done something wrong, but still: 64 bit
   platforms are the default, so using a 32 bit type to pass allocation sizes
   is a bug of it's own.
 * why bother at all with having a custom allocator?
DerDakon added a commit that referenced this pull request Dec 29, 2019
 * it's as simple as possible, probably intentional. This makes things like
   alloc_re() (i.e. realloc()) inefficient as it does not look if the thing it
   reallocates is already the last thing in the batch, and simply extends that,
   or if alloc_free() has the last block and adds things back to the pool
   (ideally with zeroing for security reasons).
 * it makes it basically impossible to detect overruns on early small
   allocations with tools like valgrind, address sanitizer or friends as
   those allocations never hit malloc(), so are never traced by any custom
   tools. Any overrun will just go into the next variable, untracable.
 * allocators do their own buffering, alignment, and so on. If they are broken,
   your system is severely screwed. And if we need more money^H^H^H^Hemory we
   will hit that buggy allocatator anyway, making things harder to detect as
   it will only happen on "heavy" memory usage. This is not TruOS, SunOS 1.x
   or something like that anymore. We expect a reasonably sane OS. Everything
   else will get us screwed in much more severe ways.
 * it has shown issues when coming close to 4GiB allocations (#37, #109, older
   reports). DJB correctly says that an allocation of that size in your mailer
   shows that you have already done something wrong, but still: 64 bit
   platforms are the default, so using a 32 bit type to pass allocation sizes
   is a bug of it's own.
 * why bother at all with having a custom allocator?
DerDakon added a commit that referenced this pull request May 8, 2020
 * it's as simple as possible, probably intentional. This makes things like
   alloc_re() (i.e. realloc()) inefficient as it does not look if the thing it
   reallocates is already the last thing in the batch, and simply extends that,
   or if alloc_free() has the last block and adds things back to the pool
   (ideally with zeroing for security reasons).
 * it makes it basically impossible to detect overruns on early small
   allocations with tools like valgrind, address sanitizer or friends as
   those allocations never hit malloc(), so are never traced by any custom
   tools. Any overrun will just go into the next variable, untracable.
 * allocators do their own buffering, alignment, and so on. If they are broken,
   your system is severely screwed. And if we need more money^H^H^H^Hemory we
   will hit that buggy allocatator anyway, making things harder to detect as
   it will only happen on "heavy" memory usage. This is not TruOS, SunOS 1.x
   or something like that anymore. We expect a reasonably sane OS. Everything
   else will get us screwed in much more severe ways.
 * it has shown issues when coming close to 4GiB allocations (#37, #109, older
   reports). DJB correctly says that an allocation of that size in your mailer
   shows that you have already done something wrong, but still: 64 bit
   platforms are the default, so using a 32 bit type to pass allocation sizes
   is a bug of it's own.
 * why bother at all with having a custom allocator?
DerDakon added a commit that referenced this pull request May 10, 2020
 * it's as simple as possible, probably intentional. This makes things like
   alloc_re() (i.e. realloc()) inefficient as it does not look if the thing it
   reallocates is already the last thing in the batch, and simply extends that,
   or if alloc_free() has the last block and adds things back to the pool
   (ideally with zeroing for security reasons).
 * it makes it basically impossible to detect overruns on early small
   allocations with tools like valgrind, address sanitizer or friends as
   those allocations never hit malloc(), so are never traced by any custom
   tools. Any overrun will just go into the next variable, untracable.
 * allocators do their own buffering, alignment, and so on. If they are broken,
   your system is severely screwed. And if we need more money^H^H^H^Hemory we
   will hit that buggy allocatator anyway, making things harder to detect as
   it will only happen on "heavy" memory usage. This is not TruOS, SunOS 1.x
   or something like that anymore. We expect a reasonably sane OS. Everything
   else will get us screwed in much more severe ways.
 * it has shown issues when coming close to 4GiB allocations (#37, #109, older
   reports). DJB correctly says that an allocation of that size in your mailer
   shows that you have already done something wrong, but still: 64 bit
   platforms are the default, so using a 32 bit type to pass allocation sizes
   is a bug of it's own.
 * why bother at all with having a custom allocator?
DerDakon added a commit that referenced this pull request May 11, 2020
 * it's as simple as possible, probably intentional. This makes things like
   alloc_re() (i.e. realloc()) inefficient as it does not look if the thing it
   reallocates is already the last thing in the batch, and simply extends that,
   or if alloc_free() has the last block and adds things back to the pool
   (ideally with zeroing for security reasons).
 * it makes it basically impossible to detect overruns on early small
   allocations with tools like valgrind, address sanitizer or friends as
   those allocations never hit malloc(), so are never traced by any custom
   tools. Any overrun will just go into the next variable, untracable.
 * allocators do their own buffering, alignment, and so on. If they are broken,
   your system is severely screwed. And if we need more money^H^H^H^Hemory we
   will hit that buggy allocator anyway, making things harder to detect as it
   will only happen on "heavy" memory usage. This is not TruOS, SunOS 1.x or
   something like that anymore. We expect a reasonably sane OS. Everything else
   will get us screwed in much more severe ways.
 * it has shown issues when coming close to 4GiB allocations (#37, #109, older
   reports). DJB correctly says that an allocation of that size in your mailer
   shows that you have already done something wrong, but still: 64 bit
   platforms are the default, so using a 32 bit type to pass allocation sizes
   is a bug of it's own.
 * why bother at all with having a custom allocator?
DerDakon added a commit that referenced this pull request May 11, 2020
 * it's as simple as possible, probably intentional. This makes things like
   alloc_re() (i.e. realloc()) inefficient as it does not look if the thing it
   reallocates is already the last thing in the batch, and simply extends that,
   or if alloc_free() has the last block and adds things back to the pool
   (ideally with zeroing for security reasons).
 * it makes it basically impossible to detect overruns on early small
   allocations with tools like valgrind, address sanitizer or friends as
   those allocations never hit malloc(), so are never traced by any custom
   tools. Any overrun will just go into the next variable, untracable.
 * allocators do their own buffering, alignment, and so on. If they are broken,
   your system is severely screwed. And if we need more money^H^H^H^Hemory we
   will hit that buggy allocator anyway, making things harder to detect as it
   will only happen on "heavy" memory usage. This is not TruOS, SunOS 1.x or
   something like that anymore. We expect a reasonably sane OS. Everything else
   will get us screwed in much more severe ways.
 * it has shown issues when coming close to 4GiB allocations (#37, #109, older
   reports). DJB correctly says that an allocation of that size in your mailer
   shows that you have already done something wrong, but still: 64 bit
   platforms are the default, so using a 32 bit type to pass allocation sizes
   is a bug of it's own.
 * when any additional patch accidentially mixes calls to this functions with
   normal realloc()/free() this can lead to random crashes
 * why bother at all with having a custom allocator?
DerDakon added a commit that referenced this pull request May 12, 2020
 * it's as simple as possible, probably intentional. This makes things like
   alloc_re() (i.e. realloc()) inefficient as it does not look if the thing it
   reallocates is already the last thing in the batch, and simply extends that,
   or if alloc_free() has the last block and adds things back to the pool
   (ideally with zeroing for security reasons).
 * it makes it basically impossible to detect overruns on early small
   allocations with tools like valgrind, address sanitizer or friends as
   those allocations never hit malloc(), so are never traced by any custom
   tools. Any overrun will just go into the next variable, untracable.
 * allocators do their own buffering, alignment, and so on. If they are broken,
   your system is severely screwed. And if we need more money^H^H^H^Hemory we
   will hit that buggy allocator anyway, making things harder to detect as it
   will only happen on "heavy" memory usage. This is not TruOS, SunOS 1.x or
   something like that anymore. We expect a reasonably sane OS. Everything else
   will get us screwed in much more severe ways.
 * it has shown issues when coming close to 4GiB allocations (#37, #109, older
   reports). DJB correctly says that an allocation of that size in your mailer
   shows that you have already done something wrong, but still: 64 bit
   platforms are the default, so using a 32 bit type to pass allocation sizes
   is a bug of it's own.
 * when any additional patch accidentially mixes calls to this functions with
   normal realloc()/free() this can lead to random crashes
 * why bother at all with having a custom allocator?
DerDakon added a commit that referenced this pull request May 12, 2020
 * it's as simple as possible, probably intentional. This makes things like
   alloc_re() (i.e. realloc()) inefficient as it does not look if the thing it
   reallocates is already the last thing in the batch, and simply extends that,
   or if alloc_free() has the last block and adds things back to the pool
   (ideally with zeroing for security reasons).
 * it makes it basically impossible to detect overruns on early small
   allocations with tools like valgrind, address sanitizer or friends as
   those allocations never hit malloc(), so are never traced by any custom
   tools. Any overrun will just go into the next variable, untracable.
 * allocators do their own buffering, alignment, and so on. If they are broken,
   your system is severely screwed. And if we need more money^H^H^H^Hemory we
   will hit that buggy allocator anyway, making things harder to detect as it
   will only happen on "heavy" memory usage. This is not TruOS, SunOS 1.x or
   something like that anymore. We expect a reasonably sane OS. Everything else
   will get us screwed in much more severe ways.
 * it has shown issues when coming close to 4GiB allocations (#37, #109, older
   reports). DJB correctly says that an allocation of that size in your mailer
   shows that you have already done something wrong, but still: 64 bit
   platforms are the default, so using a 32 bit type to pass allocation sizes
   is a bug of it's own.
 * when any additional patch accidentially mixes calls to this functions with
   normal realloc()/free() this can lead to random crashes
 * why bother at all with having a custom allocator?
DerDakon added a commit that referenced this pull request May 20, 2020
 * it's as simple as possible, probably intentional. This makes things like
   alloc_re() (i.e. realloc()) inefficient as it does not look if the thing it
   reallocates is already the last thing in the batch, and simply extends that,
   or if alloc_free() has the last block and adds things back to the pool
   (ideally with zeroing for security reasons).
 * it makes it basically impossible to detect overruns on early small
   allocations with tools like valgrind, address sanitizer or friends as
   those allocations never hit malloc(), so are never traced by any custom
   tools. Any overrun will just go into the next variable, untracable.
 * allocators do their own buffering, alignment, and so on. If they are broken,
   your system is severely screwed. And if we need more money^H^H^H^Hemory we
   will hit that buggy allocator anyway, making things harder to detect as it
   will only happen on "heavy" memory usage. This is not TruOS, SunOS 1.x or
   something like that anymore. We expect a reasonably sane OS. Everything else
   will get us screwed in much more severe ways.
 * it has shown issues when coming close to 4GiB allocations (#37, #109, older
   reports). DJB correctly says that an allocation of that size in your mailer
   shows that you have already done something wrong, but still: 64 bit
   platforms are the default, so using a 32 bit type to pass allocation sizes
   is a bug of it's own.
 * when any additional patch accidentially mixes calls to this functions with
   normal realloc()/free() this can lead to random crashes
 * why bother at all with having a custom allocator?
DerDakon added a commit that referenced this pull request May 22, 2020
 * it's as simple as possible, probably intentional. This makes things like
   alloc_re() (i.e. realloc()) inefficient as it does not look if the thing it
   reallocates is already the last thing in the batch, and simply extends that,
   or if alloc_free() has the last block and adds things back to the pool
   (ideally with zeroing for security reasons).
 * it makes it basically impossible to detect overruns on early small
   allocations with tools like valgrind, address sanitizer or friends as
   those allocations never hit malloc(), so are never traced by any custom
   tools. Any overrun will just go into the next variable, untracable.
 * allocators do their own buffering, alignment, and so on. If they are broken,
   your system is severely screwed. And if we need more money^H^H^H^Hemory we
   will hit that buggy allocator anyway, making things harder to detect as it
   will only happen on "heavy" memory usage. This is not TruOS, SunOS 1.x or
   something like that anymore. We expect a reasonably sane OS. Everything else
   will get us screwed in much more severe ways.
 * it has shown issues when coming close to 4GiB allocations (#37, #109, older
   reports). DJB correctly says that an allocation of that size in your mailer
   shows that you have already done something wrong, but still: 64 bit
   platforms are the default, so using a 32 bit type to pass allocation sizes
   is a bug of it's own.
 * when any additional patch accidentially mixes calls to this functions with
   normal realloc()/free() this can lead to random crashes
 * why bother at all with having a custom allocator?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants