Closed Nemykal closed 10 years ago
OK, thanks to the help in IRC, I tried this again with the sabotage kernel (3.12.6-grsec), and it worked.
I'm going to try to figure out what the offending config option in my kernel was (or combination thereof)... it seems really really weird that only gcc fails to build.
the issue we face here is that for some reason, the kernel gives us a very narrow heap mapping of just about 200MB. musl's allocator uses only the heap for small allocations, and apparently the gen-attr-tab program of gcc has a usage pattern that does a lot of such small allocations, so in the end we run out of heap space. it's clearly a bug of recent kernels, especially when ASLR is enabled and PIE binaries used[0]. for some reason your custom kernel is affected by this, while the sabotage kernel isn't, or at least not that much. it would be interesting to see a dump of /proc/pid/maps for the gen-attr-tabs process on that box (maybe by manually invoking it and then sending it a SIGSTP from the console, using CTRL-Z), or at least from some other process that makes use of malloc() and free().
I bisected the changes from the known-good kernel (sabotage's, without grsecurity patch) and the known-bad kernel (my original config)
My findings are as follows: CONFIG_MEM_SOFT_DIRTY is to blame.
If I set CONFIG_MEM_SOFT_DIRTY=y, then gcc454, gcc464, gcc473 (all the gccs I tested) do not compile, with the above error. If I recompile the kernel with CONFIG_MEM_SOFT_DIRTY=n, everything builds fine.
I've gotten this bug to be 100% reproducible now, so please let me know if there's any additional information you need.
I will try this setting CONFIG_MEM_SOFT_DIRTY=y with grsec enabled now and see if it still breaks.
Here is the output of gdb "info proc mappings" after the process dies on the faulty kernel.
thanks for your research. my first assessment was incorrect, apparently the problem is that CONFIG_MEM_SOFT_DIRTY uses a new vma for each new heap page rather than extending the existing one and thus hitting the kernels vma limit. this is probably a bug, so reporting it to the kernel ML makes sense.
I've been trying to track down the cause of this following elusive bug for the last few days without any luck.
GCC fails to build due to "out of memory allocating 16 bytes after total of xyz bytes" but only from sabotage that is booted, not a chroot into same sabotage install.
Background:
This is 100% reproducible, it happens every time. The two "byte" values are different though always around the same respective sizes. The first one is nearly always 16 bytes, though I have seen it say 1752 bytes once. I have tried fiddling with the CFLAGS set in /src/pkg/gcc473 but this makes no impact, so I left it at -O0.
The extremely curious thing about this is that: if I boot a xubuntu 13.10 amd64 live cd, and mount and chroot into that sabotage install, IT WORKS - I can compile gcc473 without issues.
I thought that perhaps this was a resource limits problem, so I raised all the ulimit settings I could. I am not sure if I did this right, but ulimit -a shows the following in all new shells and also after a reboot. I just added several ulimit commands in my shell profile and also in rc.local to raise these limtis, but this didn't make any difference.
I went hunting in the above-mentioned directory, /src/build/gcc473/gcc-4.7.3/host-x86_64-unknown-linux-gnu/gcc, to see if I could replicate the problem manually (so I didnt have to wait for butch rebuild gcc473 each time, the error only occurs after about 30 seconds of compiling)
I straced this and it didnt enlighten me much on what it was doing - the only odd thing I noticed was that it was doing a ton of brk() syscalls:
So I then added '-ggdb' to CFLAGS for /src/pkg/gcc473 and ran this 'build/genattrtab' through gdb 7.6.2:
Very weird!
I even tried this with an identical kernel config as the one xubuntu used - same issue. I had thought maybe it was something to do with transparent hugepages so I tried it set to always and also set to never - same issue.
For me this bug is 100% reproducible. I can try to include any information you require... I'm out of ideas trying to debug this
env on sabotage native, where it doesnt work:
env on xubuntu boot, chroot into sabotage install, where it does work:
I just booted xubuntu and went to /src/build/gcc473/gcc-4.7.3/host-x86_64-unknown-linux-gnu/gcc without cleaning it, and ran that very same binary (build/genattrtab) - and it worked as it should, no memory allocation error. The error only manifests when trying run that same binary under sabotage. Bizarre!
Misc: I also noted that 'ulimit -a' on xubuntu was the same default limits as originally on sabotage too... so adjusting those didnt have any impact at all
I did some further testing and chrooted into it from a gentoo amd64 minimal install iso too... Same thing - it works from a chroot, but not if I boot sabotage normally!
Any ideas?