Summary: | stack overflow in getaddrinfo() when host has many addresses | ||
---|---|---|---|
Product: | glibc | Reporter: | Michal Kubeček <mkubecek> |
Component: | network | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED DUPLICATE | ||
Severity: | normal | CC: | aj, attila.r.nohl, fweimer, neleai, siddhesh |
Priority: | P2 | Flags: | fweimer:
security-
|
Version: | unspecified | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Last reconfirmed: | ||
Attachments: | proposed fix |
Could you please post the patch on libc-alpha AT sourceware DOT org? It can then be reviewed and pushed into git. Please go through the following wiki document for guidelines for posting the patch: http://sourceware.org/glibc/wiki/Contribution%20checklist Michal, the patch needs comments and adoption for GNU coding style, especially spaces before parents. Could you improve your patch, please? |
Created attachment 6720 [details] proposed fix Function make_request() in sysdeps/unix/sysv/linux/check_pf.c uses alloca() to allocate memory for the temporary linked list of local addresses. If the host has many addresses (originally observed with more than 7000 addresses and 256 KB stack size limit), this can cause stack overflow. Attached is a fix proposal which is a bit more complicated than necessary but I wanted to avoid (1) calling malloc() in the most common case when there are just a few addresses (2) allocating many small blocks if there are many addresses (3) allocating too much memory on stack Thus the patch allocates a small block for 16 addresses on stack; if this is not enough (usually it is), linked list of blocks for 64 addresses is allocated as needed (suitable values of 16 and 64 are open to discussion).