【问题标题】:How to enable buildroot gcc security build options like _FORTIFY_SOURCE and stack protector?如何启用 buildroot gcc 安全构建选项,如 _FORTIFY_SOURCE 和堆栈保护器?
【发布时间】:2017-11-10 08:02:19
【问题描述】:

我满足了一个要求,可执行二进制文件必须通过https://github.com/slimm609/checksec.sh的检查,

所以我为我的工具链 gcc 启用了以下构建配置:

_D_FORTIFY_SOURCE=2  -Wl,-z,relro,-z,now -fstack-protector-all 

但它在编译过程中没有输出任何警告消息,而当我使用主机 gcc 构建时它显示正确的警告消息。

以下是我的构建日志

jason@linux-server:~/tmp/test$ /opt/buildroot-gcc463/usr/bin/mipsel-buildroot-linux-uclibc-gcc -Wall -O2 -D_FORTIFY_SOURCE=2  -Wl,-z,relro,-z,now -fstack-protector-all -fpie -pie test.c -o testjason 

没有任何警告输出。

在主机 x86 gcc 中:在包含的文件中 /usr/include/string.h:640:0, 来自 test.c:2:在函数“memcpy”中, 从 test.c:28:8 的“main”内联:/usr/include/x86_64-linux-gnu/bits/string3.h:51:3:警告:调用 __builtin___memcpy_chk 将始终溢出目标缓冲区 [默认启用] return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest)); ^ 在函数“memset”中, 从 test.c:35:8 的“main”中内联:/usr/include/x86_64-linux-gnu/bits/string3.h:84:3:警告:调用 __builtin___memset_chk 将始终溢出目标缓冲区 [默认启用] return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));

对于构建工具链,我只在 package/gcc/gcc.mk 文件中启用了 libssp:

【问题讨论】:

  • HOST_GCC_COMMON_CONF_OPT = \ --target=$(GNU_TARGET_NAME) \ --with-sysroot=$(STAGING_DIR) \ --disable-__cxa_atexit \ --with-gnu-ld \ --enable-libssp \ --disable-multilib \ --with-gmp=$(HOST_DIR)/usr \ --with-mpfr=$(HOST_DIR)/usr

标签: gcc toolchain buildroot


【解决方案1】:

您的 buildroot 编译器路径表明它是针对 uclibc 的 GCC 4.6。此编译器版本没有您在主机上看到的警告。

此外,uclibc 不支持任何真正意义上的_FORTIFY_SOURCE,因此如果您必须使用具有该功能的工具链,那么 uclibc 是错误的选择。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-16
    • 1970-01-01
    • 2010-11-23
    • 2013-10-29
    • 2018-11-30
    • 1970-01-01
    相关资源
    最近更新 更多