]>
git.ipfire.org Git - people/ms/suricata.git/blob - src/util-pages.c
1 /* Copyright (C) 2016 Open Information Security Foundation
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
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.
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
21 * \author Victor Julien <victor@inliniac.net>
26 #include "suricata-common.h"
27 #include "util-pages.h"
29 #ifndef HAVE_PAGESUPPORTSRWX_AS_MACRO
31 /** \brief check if OS allows for RWX pages
33 * Some OS' disallow RWX pages for security reasons. This function mmaps
34 * some memory RW and then tries to turn it into RWX. If this fails we
35 * assume that the OS doesn't allow for this.
37 * Thanks to Shawn Webb from HardenedBSD for the suggestion.
39 * \retval 1 RWX supported
40 * \retval 0 not supported
42 int PageSupportsRWX(void)
46 ptr
= mmap(0, getpagesize(), PROT_READ
|PROT_WRITE
, MAP_ANON
|MAP_SHARED
, -1, 0);
47 if (ptr
!= MAP_FAILED
) {
48 if (mprotect(ptr
, getpagesize(), PROT_READ
|PROT_WRITE
|PROT_EXEC
) == -1) {
49 SCLogConfig("RWX pages denied by OS");
52 munmap(ptr
, getpagesize());
56 #endif /* HAVE_PAGESUPPORTSRWX_AS_MACRO */