Bug 14477 - naive one at a time talloc_realloc (explaining several fuzz timeouts)
Summary: naive one at a time talloc_realloc (explaining several fuzz timeouts)
Status: NEW
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: DCE-RPCs and pipes (show other bugs)
Version: 4.12.5
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Samba QA Contact
QA Contact: Samba QA Contact
Depends on:
Reported: 2020-09-01 23:32 UTC by Douglas Bagnall
Modified: 2020-09-21 10:08 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Douglas Bagnall 2020-09-01 23:32:32 UTC
In several places we do this kind of thing, building up an array of N items using N reallocations:

for (i = 0; remaining > 0; i++) {
     r->x = talloc_realloc(ndr->current_mem_ctx,
                           struct whatever, 
     if (r->x == NULL) {
         return NDR_ERR_UNHAPPY;


     remaining = ndr->data_size - ndr->offset;

When ndr->data_size is big, there will be a lot of reallocs, and the overall effect is quadratic with respect to the data_size, given O(n) memmoves of O(n) items.

In practice, in normal non-malicious traffic, this is insignificant. But fuzzers have a knack of creating packets that take multiple seconds or minutes to parse.

The obvious fix is to allocate more than one item at a time, keeping count of the extra space using another variable. For example 9148f38c203c3481a43ef6d39ea9313dfa1c1bea (fixed in bf16cd72b285662bcb4367cd2bdd6eac7655254f!) uses gentle exponential growth.

BUT while the effect is drastic in the fuzzer (particularly in oss-fuzz), it is hugely exaggerated the overhead of (I think) address sanitiser, which carefully nitpicks every talloc_realloc. I have seen an example that timed out at 60 seconds with address sanitiser take < 2 seconds without it.

This bug is here to point to and from oss-fuzz timeout bugs to remind us of the probable cause and a fix, and to remind us the probably aren't as drastic as they first look, once address sanitiser is turned off.
Comment 1 Douglas Bagnall 2020-09-01 23:40:05 UTC
Exhibit 1: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=24761