-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CFLAGS ENV to Dockerfile #272
Comments
Any comments on this yet? The below is perhaps more-complete: ENV CFLAGS "-fstack-protector-strong -fpic -fpie -Wl,-O1 -O2 -Wl,--hash-style=both" Again, without the -fstack-protector-strong and position-independent executable, the PHP docker container does not enjoy protection from buffer-overflow-style attacks via address space randomization and stack smash detection. The rest are just performance improvements, mostly in loading libraries and extensions. |
Sorry for the long tail; this must've been hidden in all my email. 😞 I like adding the these for better protection and faster loading, but I would rather apply them where needed (like here in php) rather than applying to all Debian derived images with tianon/docker-brew-debian#56. I am not sure users would want that forced upon them. But still 👍 to adding them where we can. Although there is some overhead when |
I think deploying it to all Debian-derived images might make sense in the long-run; I share concerns about breaking a minority of downstream images, though. Ideally, these would have been slapped down in anticipation of this exact situation when the Debian image was first published; and downstream images could set CFLAGS to exclude the troublesome ones from the get-go, instead of facing sudden, unexpected breakage in what was once working. That's a discussion for elsewhere, and possibly viable for the next tagged release (look, if you As far as overhead and PHP goes, there's always overhead. On entry and exit from a function, a word-sized memory entry is set and tested. Each affected function call becomes a few cycles longer. In general, added overhead is unimportant if your CPU isn't pinned to 100%: if your CPU is running at 99% and you experience a 1% added overhead, your CPU will run at 99.99% and will effectively "catch up" on average once per second, and rarely find itself more than 10mS behind a reference load. Because a function call moves This is why we inline small functions: a 5-10 instruction function is actually doing more work getting called and returning than actually performing its function. By contrast, the overhead of function calling conventions on complex functions is vanishingly-small, especially if those functions have loops. In the context of
This overhead is further diminished in the context of the entire execution by how frequently said functions are called. If Between inline functions, the large code-path size of most non-inline functions, and the sparseness of functions candidate for I know that's a lot of gobbledygook, but throwing around terms like "overhead" tends to spook people without appropriate context. I once had to argue with Theo de Raadt about whether |
This issue needs to work again as musl 1.2.4 is removed support LFS64 so both flags can be removed
Filed php/php-src#11678 |
😕 I deleted those two flags and switched to |
3.18 also has musl 1.2.4 https://pkgs.alpinelinux.org/packages?name=musl&branch=v3.18&repo=&arch=&maintainer= So I have to patch all 8.1-8.3 versions with https://gitlab.alpinelinux.org/alpine/aports/-/commit/a0fde6c117c0d486340727bb538fe09646c2e4f1 |
Please add this to the Dockerfile around line 4 (above or below the first ENV command):
ENV CFLAGS "-fstack-protector-strong -fpic -fpie -O2 -Wl,-O,1 -Wl,--hash-style=both"
These flags:
These settings should provide added security and improved loading time. Setting these in ENV is harmless and will propagate the changes down to any Dockerfile, scripted, or interactive call to build php additional modules.
Also consider
-D_FORTIFY_SOURCE=1
, which adds compiler checking to some standard string library functions; this option is incompatible with Alpine's musl libc.The text was updated successfully, but these errors were encountered: