I couldn't find this documented anywhere but I'd like to harden by ZNC build and thus enable PIC/PIE, is there a nice way to do this or I have to manually edit (c)makefiles?
I couldn't find this documented anywhere but I'd like to harden by ZNC build and thus enable PIC/PIE, is there a nice way to do this or I have to manually edit (c)makefiles?
<!-- github-sync-id:619502544 -->
According to a quick Google search, passing -DPOSITION_INDEPENDENT_CODE=ON to cmake should do the trick.
cmake --help-variable CMAKE_POSITION_INDEPENDENT_CODE
CMAKE_POSITION_INDEPENDENT_CODE
-------------------------------
Default value for ``POSITION_INDEPENDENT_CODE`` of targets.
This variable is used to initialize the
``POSITION_INDEPENDENT_CODE`` property on all the targets.
See that target property for additional information. If set, it's
value is also used by the ``try_compile()`` command.
According to a quick Google search, passing `-DPOSITION_INDEPENDENT_CODE=ON` to `cmake` should do the trick.
```
cmake --help-variable CMAKE_POSITION_INDEPENDENT_CODE
CMAKE_POSITION_INDEPENDENT_CODE
-------------------------------
Default value for ``POSITION_INDEPENDENT_CODE`` of targets.
This variable is used to initialize the
``POSITION_INDEPENDENT_CODE`` property on all the targets.
See that target property for additional information. If set, it's
value is also used by the ``try_compile()`` command.
```
<!-- github-comment-id:629666896 -->
You can also set CXXFLAGS/LDFLAGS environment variables to something like -pie -fPIC (I don't remember which of them is passed where)
You can also set `CXXFLAGS`/`LDFLAGS` environment variables to something like `-pie -fPIC` (I don't remember which of them is passed where)
<!-- github-comment-id:629667243 -->
You can also set CXXFLAGS/LDFLAGS environment variables to something like -pie -fPIC (I don't remember which of them is passed where)
This causes modules to be built with PIE which causes issues, or executables with PIC, which also causes issues.
-DPOSITION_INDEPENDENT_CODE=ON
I'll try this.
> You can also set CXXFLAGS/LDFLAGS environment variables to something like -pie -fPIC (I don't remember which of them is passed where)
This causes modules to be built with PIE which causes issues, or executables with PIC, which also causes issues.
> -DPOSITION_INDEPENDENT_CODE=ON
I'll try this.
<!-- github-comment-id:629667483 -->
"Manually-specified variables were not used for this project."
I suspect this is something ZNC has to specifically support.
> -DPOSITION_INDEPENDENT_CODE=ON
"Manually-specified variables were not used for this project."
I suspect this is something ZNC has to specifically support.
<!-- github-comment-id:629668195 -->
This causes modules to be built with PIE which causes issues, or executables with PIC, which also causes issues.
Can you be more specific?
> This causes modules to be built with PIE which causes issues, or executables with PIC, which also causes issues.
Can you be more specific?
<!-- github-comment-id:629689054 -->
[ .. ] Checking for list of available modules...
[ !! ] failed
[ ** ] No modules found. Perhaps you didn't install ZNC properly?
[ ** ] Read https://wiki.znc.in/Installation for instructions.
[ ?? ] Do you really want to run ZNC without any modules? (yes/no) [no]: yes
[ .. ] Opening config [/usr/local/share/znc/.znc/configs/znc.conf]...
[ ** ] Found old config from ZNC 1.7.1. Saving a backup of it.
[ .. ] Creating a config backup...
[ !! ] File exists
[ .. ] Loading global module [certauth]...
[ !! ] Could not find ZNCModuleEntry in module certauth
[ ** ] Unrecoverable config error.
Without -pie and -fPIE it compiles and runs nicely.
> Can you be more specific?
When built with:
```
CFLAGS="-O3 -fstack-protector-all -fPIE -D_FORTIFY_SOURCE=2 -fstack-clash-protection -mtune=native -march=native -Wl,-z,noexecstack,-z,noexecheap,-z,relro,z,now" CXXFLAGS="-O3 -fstack-protector-all -fPIE -D_FORTIFY_SOURCE=2 -fstack-clash-protection -mtune=native -march=native -Wl,-z,noexecstack,-z,noexecheap,-z,relro,-z,now" LDFLAGS="-pie -z,noexecstack -z,noexecheap -z,relro -z,now" cmake .. -DCMAKE_CXX_COMPILER="g++-8" -DCMAKE_C_COMPILER="gcc-8"
```
It errors out like this:
```
[ .. ] Checking for list of available modules...
[ !! ] failed
[ ** ] No modules found. Perhaps you didn't install ZNC properly?
[ ** ] Read https://wiki.znc.in/Installation for instructions.
[ ?? ] Do you really want to run ZNC without any modules? (yes/no) [no]: yes
[ .. ] Opening config [/usr/local/share/znc/.znc/configs/znc.conf]...
[ ** ] Found old config from ZNC 1.7.1. Saving a backup of it.
[ .. ] Creating a config backup...
[ !! ] File exists
[ .. ] Loading global module [certauth]...
[ !! ] Could not find ZNCModuleEntry in module certauth
[ ** ] Unrecoverable config error.
```
Without `-pie` and `-fPIE` it compiles and runs nicely.
<!-- github-comment-id:629705964 -->
$ file /tmp/znc/bin/znc
/tmp/znc/bin/znc: ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, with debug_info, not stripped
```
$ file /tmp/znc/bin/znc
/tmp/znc/bin/znc: ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, with debug_info, not stripped
```
<!-- github-comment-id:629856518 -->
Even -DPOSITION_INDEPENDENT_CODE=ON is enough to produce that result.
If cmake says it wasn't used I don't see how that's possible.
> export CXXFLAGS=
What about CFLAGS?
> Even -DPOSITION_INDEPENDENT_CODE=ON is enough to produce that result.
If cmake says it wasn't used I don't see how that's possible.
<!-- github-comment-id:629864227 -->
Oh, and I have to mention, the entire build folder had to be removed, otherwise the changes in C(XX)FLAGS did not apply properly.
Oh, and I have to mention, the entire build folder had to be removed, otherwise the changes in C(XX)FLAGS did not apply properly.
<!-- github-comment-id:629864353 -->
CMake 3.13 and lower did not add these link flags when POSITION_INDEPENDENT_CODE is set.
https://cmake.org/cmake/help/latest/policy/CMP0083.html
> CMake 3.13 and lower did not add these link flags when POSITION_INDEPENDENT_CODE is set.
<!-- github-comment-id:629867968 -->
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
I couldn't find this documented anywhere but I'd like to harden by ZNC build and thus enable PIC/PIE, is there a nice way to do this or I have to manually edit (c)makefiles?
According to a quick Google search, passing
-DPOSITION_INDEPENDENT_CODE=ONtocmakeshould do the trick.You can also set
CXXFLAGS/LDFLAGSenvironment variables to something like-pie -fPIC(I don't remember which of them is passed where)This causes modules to be built with PIE which causes issues, or executables with PIC, which also causes issues.
I'll try this.
"Manually-specified variables were not used for this project."
I suspect this is something ZNC has to specifically support.
Can you be more specific?
When built with:
It errors out like this:
Without
-pieand-fPIEit compiles and runs nicely.The only warning I see is this:
Even
-DPOSITION_INDEPENDENT_CODE=ONis enough to produce that result.What about CFLAGS?
If cmake says it wasn't used I don't see how that's possible.
Oh, and I have to mention, the entire build folder had to be removed, otherwise the changes in C(XX)FLAGS did not apply properly.
What cmake version?
ZNC doesn't use C
cmake version 3.10.2https://cmake.org/cmake/help/latest/policy/CMP0083.html