suricata
util-pages.c
Go to the documentation of this file.
1/* Copyright (C) 2016 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18/**
19 * \file
20 *
21 * \author Victor Julien <victor@inliniac.net>
22 *
23 * Page util functions
24 */
25
26#include "suricata-common.h"
27#include "util-pages.h"
28#include "util-debug.h"
29
30#ifndef HAVE_PAGESUPPORTSRWX_AS_MACRO
31
32/** \brief check if OS allows for RWX pages
33 *
34 * Some OS' disallow RWX pages for security reasons. This function mmaps
35 * some memory RW and then tries to turn it into RWX. If this fails we
36 * assume that the OS doesn't allow for this.
37 *
38 * Thanks to Shawn Webb from HardenedBSD for the suggestion.
39 *
40 * \retval 1 RWX supported
41 * \retval 0 not supported
42 */
43int PageSupportsRWX(void)
44{
45 int retval = 1;
46 // suppress scan-build security.MmapWriteExec
47#ifndef __clang_analyzer__
48 void *ptr;
49 ptr = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
50 if (ptr != MAP_FAILED) {
51 if (mprotect(ptr, getpagesize(), PROT_READ|PROT_WRITE|PROT_EXEC) == -1) {
52 SCLogConfig("RWX pages denied by OS");
53 retval = 0;
54 }
55 munmap(ptr, getpagesize());
56 }
57#endif
58 return retval;
59}
60#endif /* HAVE_PAGESUPPORTSRWX_AS_MACRO */
61
#define SCLogConfig(...)
Definition util-debug.h:229
#define PageSupportsRWX()
Definition util-pages.h:37