Skip to content

MAX_MESSAGE_SIZE = 4MB is too large to be placed on stack #197

@funny-falcon

Description

@funny-falcon

Stack grows down by touching guard page.
See man mmap:

MAP_GROWSDOWN
This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory. The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

To acomplish this compiler inserts loop that touches every 4kb downwards until buffer is allocated.
Following memset also wipes out CPU caches.

More over, some systems are configured with as small default stack as 2MB.

And I don't see in rsa_report.c any usage of char buf[MAX_MESSAGE_SIZE]; to make any large string. All usages are only for short snprintf.

So what is so huge? Why 4MB is allocated on stack and cleared just to write tiny strings?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions