Skip to content

Commit 525ffd6

Browse files
authored
[clang][analyzer] Bring alpha.security.MmapWriteExec checker out of alpha package (#102636)
1 parent af5c18a commit 525ffd6

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

clang/docs/analyzer/checkers.rst

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,22 @@ security.insecureAPI.DeprecatedOrUnsafeBufferHandling (C)
12931293
strncpy(buf, "a", 1); // warn
12941294
}
12951295
1296+
.. _security-MmapWriteExec:
1297+
1298+
security.MmapWriteExec (C)
1299+
""""""""""""""""""""""""""
1300+
Warn on ``mmap()`` calls with both writable and executable access.
1301+
1302+
.. code-block:: c
1303+
1304+
void test(int n) {
1305+
void *c = mmap(NULL, 32, PROT_READ | PROT_WRITE | PROT_EXEC,
1306+
MAP_PRIVATE | MAP_ANON, -1, 0);
1307+
// warn: Both PROT_WRITE and PROT_EXEC flags are set. This can lead to
1308+
// exploitable memory regions, which could be overwritten with malicious
1309+
// code
1310+
}
1311+
12961312
.. _security-putenv-stack-array:
12971313
12981314
security.PutenvStackArray (C)
@@ -2967,22 +2983,6 @@ Warn about buffer overflows (newer checker).
29672983
char c = s[x]; // warn: index is tainted
29682984
}
29692985
2970-
.. _alpha-security-MmapWriteExec:
2971-
2972-
alpha.security.MmapWriteExec (C)
2973-
""""""""""""""""""""""""""""""""
2974-
Warn on mmap() calls that are both writable and executable.
2975-
2976-
.. code-block:: c
2977-
2978-
void test(int n) {
2979-
void *c = mmap(NULL, 32, PROT_READ | PROT_WRITE | PROT_EXEC,
2980-
MAP_PRIVATE | MAP_ANON, -1, 0);
2981-
// warn: Both PROT_WRITE and PROT_EXEC flags are set. This can lead to
2982-
// exploitable memory regions, which could be overwritten with malicious
2983-
// code
2984-
}
2985-
29862986
.. _alpha-security-ReturnPtrRange:
29872987
29882988
alpha.security.ReturnPtrRange (C)

clang/include/clang/StaticAnalyzer/Checkers/Checkers.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,10 @@ def FloatLoopCounter : Checker<"FloatLoopCounter">,
10001000
Dependencies<[SecuritySyntaxChecker]>,
10011001
Documentation<HasDocumentation>;
10021002

1003+
def MmapWriteExecChecker : Checker<"MmapWriteExec">,
1004+
HelpText<"Warn on mmap() calls with both writable and executable access">,
1005+
Documentation<HasDocumentation>;
1006+
10031007
def PutenvStackArray : Checker<"PutenvStackArray">,
10041008
HelpText<"Finds calls to the function 'putenv' which pass a pointer to "
10051009
"an automatic (stack-allocated) array as the argument.">,
@@ -1039,10 +1043,6 @@ def ArrayBoundCheckerV2 : Checker<"ArrayBoundV2">,
10391043
HelpText<"Warn about buffer overflows (newer checker)">,
10401044
Documentation<HasDocumentation>;
10411045

1042-
def MmapWriteExecChecker : Checker<"MmapWriteExec">,
1043-
HelpText<"Warn on mmap() calls that are both writable and executable">,
1044-
Documentation<HasDocumentation>;
1045-
10461046
def ReturnPointerRangeChecker : Checker<"ReturnPtrRange">,
10471047
HelpText<"Check for an out-of-bound pointer being returned to callers">,
10481048
Documentation<HasDocumentation>;

clang/test/Analysis/mmap-writeexec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=alpha.security.MmapWriteExec -DUSE_ALTERNATIVE_PROT_EXEC_DEFINITION -verify %s
2-
// RUN: %clang_analyze_cc1 -triple x86_64-unknown-apple-darwin10 -analyzer-checker=alpha.security.MmapWriteExec -verify %s
1+
// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=security.MmapWriteExec -DUSE_ALTERNATIVE_PROT_EXEC_DEFINITION -verify %s
2+
// RUN: %clang_analyze_cc1 -triple x86_64-unknown-apple-darwin10 -analyzer-checker=security.MmapWriteExec -verify %s
33

44
#ifndef USE_ALTERNATIVE_PROT_EXEC_DEFINITION
55
#define PROT_EXEC 0x01

0 commit comments

Comments
 (0)