Find a file
David Malcolm d777b38cde analyzer: new warning: -Wanalyzer-tainted-assertion [PR106235]
This patch adds a new -Wanalyzer-tainted-assertion warning to
-fanalyzer's "taint" mode (which also requires -fanalyzer-checker=taint).

It complains about attacker-controlled values being used in assertions,
or in any expression affecting control flow that guards a "noreturn"
function.  As noted in the docs part of the patch, in such cases:

  - when assertion-checking is enabled: an attacker could trigger
    a denial of service by injecting an assertion failure

  - when assertion-checking is disabled, such as by defining NDEBUG,
    an attacker could inject data that subverts the process, since it
    presumably violates a precondition that is being assumed by the code.

For example, given:

#include <assert.h>

int __attribute__((tainted_args))
test_tainted_assert (int n)
{
  assert (n > 0);
  return n * n;
}

compiling with
  -fanalyzer -fanalyzer-checker=taint
gives:

t.c: In function 'test_tainted_assert':
t.c:6:3: warning: use of attacked-controlled value in condition for assertion [CWE-617] [-Wanalyzer-tainted-assertion]
    6 |   assert (n > 0);
      |   ^~~~~~
  'test_tainted_assert': event 1
    |
    |    4 | test_tainted_assert (int n)
    |      | ^~~~~~~~~~~~~~~~~~~
    |      | |
    |      | (1) function 'test_tainted_assert' marked with '__attribute__((tainted_args))'
    |
    +--> 'test_tainted_assert': event 2
           |
           |    4 | test_tainted_assert (int n)
           |      | ^~~~~~~~~~~~~~~~~~~
           |      | |
           |      | (2) entry to 'test_tainted_assert'
           |
         'test_tainted_assert': events 3-6
           |
           |/usr/include/assert.h:106:10:
           |  106 |       if (expr)                                                         \
           |      |          ^
           |      |          |
           |      |          (3) use of attacker-controlled value for control flow
           |      |          (4) following 'false' branch (when 'n <= 0')...
           |......
           |  109 |         __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION);   \
           |      |         ~~~~~~~~~~~~~
           |      |         |
           |      |         (5) ...to here
           |      |         (6) treating '__assert_fail' as an assertion failure handler due to '__attribute__((__noreturn__))'
           |

The testcases have various examples for BUG and BUG_ON from the
Linux kernel; there, the diagnostic treats "panic" as an assertion
failure handler, due to '__attribute__((__noreturn__))'.

gcc/analyzer/ChangeLog:
	PR analyzer/106235
	* analyzer.opt (Wanalyzer-tainted-assertion): New.
	* checker-path.cc (checker_path::fixup_locations): Pass false to
	pending_diagnostic::fixup_location.
	* diagnostic-manager.cc (get_emission_location): Pass true to
	pending_diagnostic::fixup_location.
	* pending-diagnostic.cc (pending_diagnostic::fixup_location): Add
	bool param.
	* pending-diagnostic.h (pending_diagnostic::fixup_location): Add
	bool param to decl.
	* sm-taint.cc (taint_state_machine::m_tainted_control_flow): New.
	(taint_diagnostic::describe_state_change): Drop "final".
	(class tainted_assertion): New.
	(taint_state_machine::taint_state_machine): Initialize
	m_tainted_control_flow.
	(taint_state_machine::alt_get_inherited_state): Support
	comparisons being tainted, based on their arguments.
	(is_assertion_failure_handler_p): New.
	(taint_state_machine::on_stmt): Complain about calls to assertion
	failure handlers guarded by an attacker-controller conditional.
	Detect attacker-controlled gcond conditionals and gswitch index
	values.
	(taint_state_machine::check_control_flow_arg_for_taint): New.

gcc/ChangeLog:
	PR analyzer/106235
	* doc/gcc/gcc-command-options/option-summary.rst: Add
	-Wno-analyzer-tainted-assertion.
	* doc/gcc/gcc-command-options/options-that-control-static-analysis.rst:
	Add -Wno-analyzer-tainted-assertion.

gcc/testsuite/ChangeLog:
	PR analyzer/106235
	* gcc.dg/analyzer/taint-assert-BUG_ON.c: New test.
	* gcc.dg/analyzer/taint-assert-macro-expansion.c: New test.
	* gcc.dg/analyzer/taint-assert.c: New test.
	* gcc.dg/analyzer/taint-assert-system-header.c: New test.
	* gcc.dg/analyzer/test-assert.h: New header.
	* gcc.dg/plugin/analyzer_gil_plugin.c
	(gil_diagnostic::fixup_location): Add bool param.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2022-11-13 17:53:23 -05:00
c++tools Daily bump. 2022-03-19 00:16:22 +00:00
config Daily bump. 2022-11-10 00:17:57 +00:00
contrib Daily bump. 2022-11-12 00:17:25 +00:00
doc doc: Update Jeff Law's email-address in contrib.rst 2022-11-13 16:43:46 +01:00
fixincludes Daily bump. 2022-10-08 00:17:29 +00:00
gcc analyzer: new warning: -Wanalyzer-tainted-assertion [PR106235] 2022-11-13 17:53:23 -05:00
gnattools Daily bump. 2022-09-01 00:17:39 +00:00
gotools Daily bump. 2022-08-31 00:16:45 +00:00
include Manually add ChangeLog entries from r13-3652-ge4cba49413ca429dc82f6aa2e88129ecb3fdd943 2022-11-06 12:12:47 +01:00
INSTALL
intl Daily bump. 2021-11-30 00:16:44 +00:00
libada Daily bump. 2022-08-26 00:16:21 +00:00
libatomic Daily bump. 2022-10-20 00:17:52 +00:00
libbacktrace Daily bump. 2022-10-13 00:17:37 +00:00
libcc1 Daily bump. 2022-11-02 00:17:38 +00:00
libcody Daily bump. 2022-06-04 00:16:27 +00:00
libcpp Daily bump. 2022-11-06 11:05:22 +00:00
libdecnumber Daily bump. 2022-10-08 00:17:29 +00:00
libffi Daily bump. 2022-10-13 00:17:37 +00:00
libgcc Daily bump. 2022-11-06 11:05:22 +00:00
libgfortran Daily bump. 2022-10-13 00:17:37 +00:00
libgo runtime: use _libgo_off_t_type when calling C mmap 2022-10-27 17:12:57 -07:00
libgomp configure: always set SPHINX_BUILD 2022-11-13 16:35:25 +01:00
libiberty configure: always set SPHINX_BUILD 2022-11-13 16:35:25 +01:00
libitm configure: always set SPHINX_BUILD 2022-11-13 16:35:25 +01:00
libobjc Daily bump. 2022-10-21 00:17:52 +00:00
libphobos Daily bump. 2022-11-06 11:05:22 +00:00
libquadmath configure: always set SPHINX_BUILD 2022-11-13 16:35:25 +01:00
libsanitizer Daily bump. 2022-10-20 00:17:52 +00:00
libssp Daily bump. 2022-10-13 00:17:37 +00:00
libstdc++-v3 libstdc++: Add C++20 clocks 2022-11-13 01:10:45 +00:00
libvtv Daily bump. 2022-11-01 00:19:02 +00:00
lto-plugin Daily bump. 2022-10-13 00:17:37 +00:00
maintainer-scripts Daily bump. 2022-11-11 00:17:22 +00:00
zlib Daily bump. 2022-10-13 00:17:37 +00:00
.dir-locals.el dir-locals: Use https for bug references 2021-07-20 11:40:34 +01:00
.gitattributes
.gitignore .gitignore: do not ignore config.h 2022-07-19 17:07:04 +03:00
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2022-11-12 00:17:25 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess config.sub, config.guess : Import upstream 2021-01-25. 2021-02-23 17:21:10 +08:00
config.rpath
config.sub config.sub: change mode to 755. 2021-12-21 09:10:57 +01:00
configure docs: fix links pointing to gcc.gnu.org/install 2022-11-09 15:38:47 +01:00
configure.ac docs: fix links pointing to gcc.gnu.org/install 2022-11-09 15:38:47 +01:00
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
depcomp
install-sh
libtool-ldflags
libtool.m4 Generic configury support for shared libs on VxWorks 2022-10-11 07:31:07 +00:00
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
MAINTAINERS Update email address 2022-10-31 11:15:45 +00:00
Makefile.def Remove support for Intel MIC offloading 2022-11-04 10:51:01 +01:00
Makefile.in Remove support for Intel MIC offloading 2022-11-04 10:51:01 +01:00
Makefile.tpl Makefile.def: drop remnants of unused libelf 2022-08-18 09:37:09 +01:00
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
symlink-tree
test-driver
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.