bind9/doc
Tony Finch 03e0083e3b Avoid using C99 variable length arrays
From an attacker's point of view, a VLA declaration is essentially a
primitive for performing arbitrary arithmetic on the stack pointer. If
the attacker can control the size of a VLA they have a very powerful
tool for causing memory corruption.

To mitigate this kind of attack, and the more general class of stack
clash vulnerabilities, C compilers insert extra code when allocating a
VLA to probe the growing stack one page at a time. If these probes hit
the stack guard page, the program will crash.

From the point of view of a C programmer, there are a few things to
consider about VLAs:

  * If it is important to handle allocation failures in a controlled
    manner, don't use VLAs. You can use VLAs if it is OK for
    unreasonable inputs to cause an uncontrolled crash.

  * If the VLA is known to be smaller than some known fixed size,
    use a fixed size array and a run-time check to ensure it is large
    enough. This will be more efficient than the compiler's stack
    probes that need to cope with arbitrary-size VLAs.

  * If the VLA might be large, allocate it on the heap. The heap
    allocator can allocate multiple pages in one shot, whereas the
    stack clash probes work one page at a time.

Most of the existing uses of VLAs in BIND are in test code where they
are benign, but there was one instance in `named`, in the GSS-TSIG
verification code, which has now been removed.

This commit adjusts the style guide and the C compiler flags to allow
VLAs in test code but not elsewhere.

(cherry picked from commit 599c1d2a6b)
2022-03-18 16:05:56 +00:00
..
arm Set up release notes for BIND 9.18.2 2022-03-16 23:18:18 +01:00
design Drop documents that have been folded into doc/dev/dev.md 2022-03-10 14:53:21 +00:00
dev Avoid using C99 variable length arrays 2022-03-18 16:05:56 +00:00
dnssec-guide Hyperlink program names to their manual pages 2022-03-14 11:01:31 +01:00
doxygen Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
man Fix named.conf man page documentation 2022-03-15 14:15:26 +01:00
misc Fix named.conf man page documentation 2022-03-15 14:15:26 +01:00
notes Set up release notes for BIND 9.18.2 2022-03-16 23:18:18 +01:00
Makefile.am Install man pages when sphinx-build tool is missing 2021-05-25 11:21:32 +02:00