dpkg-buildflags.1 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. .TH dpkg\-buildflags 1 "2011-09-13" "Debian Project" "dpkg suite"
  2. .SH NAME
  3. dpkg\-buildflags \- returns build flags to use during package build
  4. .
  5. .SH SYNOPSIS
  6. .B dpkg\-buildflags
  7. .RI [ option "...] [" command ]
  8. .
  9. .SH DESCRIPTION
  10. \fBdpkg\-buildflags\fP is a tool to retrieve compilation flags to use during
  11. build of Debian packages.
  12. .
  13. The default flags are defined by the vendor but they can be
  14. extended/overriden in several ways:
  15. .IP 1.
  16. system-wide with \fB/etc/dpkg/buildflags.conf\fP;
  17. .IP 2.
  18. for the current user with \fB$XDG_CONFIG_HOME/dpkg/buildflags.conf\fP
  19. where \fB$XDG_CONFIG_HOME\fP defaults to \fB$HOME/.config\fP;
  20. .IP 3.
  21. temporarily by the user with environment variables (see section
  22. \fBENVIRONMENT\fP);
  23. .IP 4.
  24. dynamically by the package maintainer with environment variables set via
  25. \fBdebian/rules\fP (see section \fBENVIRONMENT\fP).
  26. .P
  27. The configuration files can contain two types of directives:
  28. .TP
  29. .BI SET " flag value"
  30. Override the flag named \fIflag\fP to have the value \fIvalue\fP.
  31. .TP
  32. .BI STRIP " flag value"
  33. Strip from the flag named \fIflag\fP all the build flags listed in \fIvalue\fP.
  34. .TP
  35. .BI APPEND " flag value"
  36. Extend the flag named \fIflag\fP by appending the options given in \fIvalue\fP.
  37. A space is prepended to the appended value if the flag's current value is non-empty.
  38. .TP
  39. .BI PREPEND " flag value"
  40. Extend the flag named \fIflag\fP by prepending the options given in \fIvalue\fP.
  41. A space is appended to the prepended value if the flag's current value is non-empty.
  42. .P
  43. The configuration files can contain comments on lines starting with a hash
  44. (#). Empty lines are also ignored.
  45. .SH COMMANDS
  46. .TP
  47. .BI \-\-dump
  48. Print to standard output all compilation flags and their values. It prints
  49. one flag per line separated from its value by an equal sign
  50. ("\fIflag\fP=\fIvalue\fP"). This is the default action.
  51. .TP
  52. .BI \-\-list
  53. Print the list of flags supported by the current vendor
  54. (one per line). See the \fBSUPPORTED FLAGS\fP section for more
  55. information about them.
  56. .TP
  57. .BI \-\-export= format
  58. Print to standard output shell (if \fIformat\fP is \fBsh\fP) or make
  59. (if \fIformat\fP is \fBmake\fP) commands that can be used to export
  60. all the compilation flags in the environment. If \fIformat\fP is
  61. \fBconfigure\fP then the output can be used on a \fB./configure\fP
  62. command-line. If the \fIformat\fP value is not
  63. given, \fBsh\fP is assumed. Only compilation flags starting with an
  64. upper case character are included, others are assumed to not be suitable
  65. for the environment.
  66. .TP
  67. .BI \-\-get " flag"
  68. Print the value of the flag on standard output. Exits with 0
  69. if the flag is known otherwise exits with 1.
  70. .TP
  71. .BI \-\-origin " flag"
  72. Print the origin of the value that is returned by \fB\-\-get\fP. Exits
  73. with 0 if the flag is known otherwise exits with 1. The origin can be one
  74. of the following values:
  75. .RS
  76. .TP
  77. .B vendor
  78. the original flag set by the vendor is returned;
  79. .TP
  80. .B system
  81. the flag is set/modified by a system-wide configuration;
  82. .TP
  83. .B user
  84. the flag is set/modified by a user-specific configuration;
  85. .TP
  86. .B env
  87. the flag is set/modified by an environment-specific configuration.
  88. .RE
  89. .TP
  90. .BI \-\-query\-features " area"
  91. Print the features enabled for a given area. The only currently recognized
  92. area is \fBhardening\fP. Exits with 0 if the area is known otherwise exits
  93. with 1.
  94. .IP
  95. The output format is RFC822 header-style, with one section per feature.
  96. For example:
  97. .IP
  98. .nf
  99. Feature: pie
  100. Enabled: no
  101. Feature: stackprotector
  102. Enabled: yes
  103. .fi
  104. .TP
  105. .B \-\-help
  106. Show the usage message and exit.
  107. .TP
  108. .B \-\-version
  109. Show the version and exit.
  110. .
  111. .SH SUPPORTED FLAGS
  112. .TP
  113. .B CFLAGS
  114. Options for the C compiler. The default value set by the vendor
  115. includes \fI\-g\fP and the default optimization level (\fI\-O2\fP usually,
  116. or \fI\-O0\fP if the \fBDEB_BUILD_OPTIONS\fP environment variable defines
  117. \fInoopt\fP).
  118. .TP
  119. .B CPPFLAGS
  120. Options for the C preprocessor. Default value: empty.
  121. .TP
  122. .B CXXFLAGS
  123. Options for the C++ compiler. Same as \fBCFLAGS\fP.
  124. .TP
  125. .B FFLAGS
  126. Options for the Fortran compiler. Same as \fBCFLAGS\fP.
  127. .TP
  128. .B LDFLAGS
  129. Options passed to the compiler when linking executables or shared
  130. objects (if the linker is called directly, then
  131. .B \-Wl
  132. and
  133. .B ,
  134. have to be stripped from these options). Default value: empty.
  135. .
  136. .SH FILES
  137. .TP
  138. .B /etc/dpkg/buildflags.conf
  139. System wide configuration file.
  140. .TP
  141. .BR $XDG_CONFIG_HOME/dpkg/buildflags.conf " or " $HOME/.config/dpkg/buildflags.conf
  142. User configuration file.
  143. .SH ENVIRONMENT
  144. There are 2 sets of environment variables doing the same operations, the
  145. first one (DEB_\fIflag\fP_\fIop\fP) should never be used within
  146. \fBdebian/rules\fP. It's meant for any user that wants to rebuild the
  147. source package with different build flags. The second set
  148. (DEB_\fIflag\fP_MAINT_\fIop\fP) should only be used in \fBdebian/rules\fP
  149. by package maintainers to change the resulting build flags.
  150. .TP
  151. .BI DEB_ flag _SET
  152. .TQ
  153. .BI DEB_ flag _MAINT_SET
  154. This variable can be used to force the value returned for the given
  155. \fIflag\fP.
  156. .TP
  157. .BI DEB_ flag _STRIP
  158. .TQ
  159. .BI DEB_ flag _MAINT_STRIP
  160. This variable can be used to provide a space separated list of options
  161. that will be stripped from the set of flags returned for the given
  162. \fIflag\fP.
  163. .TP
  164. .BI DEB_ flag _APPEND
  165. .TQ
  166. .BI DEB_ flag _MAINT_APPEND
  167. This variable can be used to append supplementary options to the value
  168. returned for the given \fIflag\fP.
  169. .TP
  170. .BI DEB_ flag _PREPEND
  171. .TQ
  172. .BI DEB_ flag _MAINT_PREPEND
  173. This variable can be used to prepend supplementary options to the value
  174. returned for the given \fIflag\fP.
  175. .TP
  176. .B DEB_BUILD_MAINT_OPTIONS
  177. This variable can be used to disable/enable various hardening build
  178. flags through the \fBhardening\fP option. See the \fBHARDENING\fP section
  179. for details.
  180. .
  181. .SH HARDENING
  182. Several compile-time options (detailed below) can be used to help harden
  183. a resulting binary against memory corruption attacks, or provide
  184. additional warning messages during compilation. Except as noted below,
  185. these are enabled by default for architectures that support them.
  186. .P
  187. Each hardening feature can be enabled and disabled in the
  188. \fBDEB_BUILD_MAINT_OPTIONS\fP environment variable's \fBhardening\fP
  189. value with the "+" and "\-" modifier. For example, to enable the
  190. "pie" feature and disable the "fortify" feature you can do this
  191. in \fBdebian/rules\fP:
  192. .P
  193. export DEB_BUILD_MAINT_OPTIONS=hardening=+pie,\-fortify
  194. .P
  195. The special feature \fBall\fP can be used to enable or disable all
  196. hardening features at the same time. Thus disabling everything and
  197. enabling only "format" and "fortify" can be achieved with:
  198. .P
  199. export DEB_BUILD_MAINT_OPTIONS=hardening=\-all,+format,+fortify
  200. .
  201. .TP
  202. .B format
  203. This setting (enabled by default) adds
  204. .B \-Wformat \-Wformat\-security \-Werror=format\-security
  205. to \fBCFLAGS\fP and \fBCXXFLAGS\fP. This will warn about improper format
  206. string uses, and will fail when format functions are used in a way that
  207. that represent possible security problems. At present, this warns about
  208. calls to \fBprintf\fP and \fBscanf\fP functions where the format string is
  209. not a string literal and there are no format arguments, as in
  210. \fBprintf(foo);\fP instead of \fPprintf("%s", foo);\fP
  211. This may be a security hole if the format string came from untrusted
  212. input and contains "%n".
  213. .
  214. .TP
  215. .B fortify
  216. This setting (enabled by default) adds
  217. .B \-D_FORTIFY_SOURCE=2
  218. to \fBCPPFLAGS\fP. During code generation the compiler
  219. knows a great deal of information about buffer sizes (where possible), and
  220. attempts to replace insecure unlimited length buffer function calls with
  221. length-limited ones. This is especially useful for old, crufty code.
  222. Additionally, format strings in writable memory that contain '%n' are
  223. blocked. If an application depends on such a format string, it will need
  224. to be worked around.
  225. Note that for this option to have any effect, the source must also
  226. be compiled with \fB\-O1\fP or higher.
  227. .TP
  228. .B stackprotector
  229. This setting (enabled by default) adds
  230. .B \-fstack-protector \-\-param=ssp\-buffer\-size=4
  231. to \fBCFLAGS\fP and \fBCXXFLAGS\fP. This adds safety checks against stack
  232. overwrites. This renders many potential code injection attacks into
  233. aborting situations. In the best case this turns code injection
  234. vulnerabilities into denial of service or into non-issues (depending on
  235. the application).
  236. This feature requires linking against glibc (or another provider of
  237. \fB__stack_chk_fail\fP), so needs to be disabled when building with
  238. \fB\-nostdlib\fP or \fB\-ffreestanding\fP or similar.
  239. .
  240. .TP
  241. .B relro
  242. This setting (enabled by default) adds
  243. .B \-Wl,\-z,relro
  244. to \fBLDFLAGS\fP. During program load, several ELF memory sections need
  245. to be written to by the linker. This flags the loader to turn these
  246. sections read-only before turning over control to the program. Most
  247. notably this prevents GOT overwrite attacks. If this option is disabled,
  248. \fBbindnow\fP will become disabled as well.
  249. .
  250. .TP
  251. .B bindnow
  252. This setting (disabled by default) adds
  253. .B \-Wl,\-z,now
  254. to \fBLDFLAGS\fP. During program load, all dynamic symbols are resolved,
  255. allowing for the entire PLT to be marked read-only (due to \fBrelro\fP
  256. above). The option cannot become enabled if \fBrelro\fP is not enabled.
  257. .
  258. .TP
  259. .B pie
  260. This setting (disabled by default) adds \fB\-fPIE\fP to \fBCFLAGS\fP and
  261. \fBCXXFLAGS\fP, and \fB\-fPIE \-pie\fP to \fBLDFLAGS\fP. Position Independent
  262. Executable are needed to take advantage of Address Space Layout
  263. Randomization, supported by some kernel versions. While ASLR can already
  264. be enforced for data areas in the stack and heap (brk and mmap), the code
  265. areas must be compiled as position-independent. Shared libraries already
  266. do this (\-fPIC), so they gain ASLR automatically, but binary .text
  267. regions need to be build PIE to gain ASLR. When this happens, ROP (Return
  268. Oriented Programming) attacks are much harder since there are no static
  269. locations to bounce off of during a memory corruption attack.
  270. This is not compatible with \fB\-fPIC\fP so care must be taken when
  271. building shared objects.
  272. Additionally, since PIE is implemented via a general register, some
  273. architectures (most notably i386) can see performance losses of up to
  274. 15% in very text-segment-heavy application workloads; most workloads
  275. see less than 1%. Architectures with more general registers (e.g. amd64)
  276. do not see as high a worst-case penalty.
  277. .
  278. .SH AUTHOR
  279. Copyright \(co 2010-2011 Rapha\[:e]l Hertzog
  280. .sp
  281. Copyright \(co 2011 Kees Cook
  282. .sp
  283. This is free software; see the GNU General Public Licence version 2 or
  284. later for copying conditions. There is NO WARRANTY.