新的安全功能 Fedora 21. #1 -Werror=格式安全

提高发行版安全性的最佳方法之一是改进编译器以检测可能导致漏洞利用的错误。

在 Fedora,每当编写新的编译器检查时,我们都希望重建整个发行版以查找并修复这些问题。

启用“-Werror=format-security”编译标志

所有包裹在 Fedora 21 是使用 -Werror=format-security 开关重建的,此标志导致 GCC 将拒绝编译可能易受不受控制的格式字符串安全漏洞影响的代码。

维基百科将不受控制的格式缺陷描述为:

不受控制的格式字符串 是一种软件漏洞,发现于 1999 年左右,可用于安全漏洞。 以前认为是无害的,格式字符串漏洞可用于使程序崩溃或执行有害代码。 问题源于在某些执行格式化的 C 函数(例如 printf())中使用未经检查的用户输入作为格式字符串参数。 恶意用户可能会使用 %s 和 %x 格式令牌等来打印堆栈或内存中可能的其他位置的数据。 也可以使用 %n 格式令牌将任意数据写入任意位置,该令牌命令 printf() 和类似函数将格式化的字节数写入存储在堆栈中的地址。

GCC 手册页描述了该选项:

man gcc
...
-Wformat-security
If -Wformat is specified, also warn about uses of format functions that represent possible security 
problems. At present, this warns about calls to "printf" and "scanf" functions where the format 
string is not a string literal and there are no format arguments, as in "printf (foo);". This may 
be a security hole if the format string came from untrusted input and contains %n. (This is
currently a subset of what -Wformat-nonliteral warns about, but in future warnings may be added to 
-Wformat-security that are not included in -Wformat-nonliteral.)

此更改导致软件包修复了许多潜在的错误/漏洞,提高了整体安全性 Fedora.

笔记:
过去,我在 danwalsh.livejournal.com 上写过这个博客。 我被要求把它搬到这里,因为它是 Fedora 具体的。 如果您对我在本系列中遗漏的内容有任何想法或意见,请发送邮件至 [email protected],我会考虑添加这些内容。