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  */
43 int PageSupportsRWX(void)
44 {
45  int retval = 1;
46  void *ptr;
47  ptr = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
48  if (ptr != MAP_FAILED) {
49  if (mprotect(ptr, getpagesize(), PROT_READ|PROT_WRITE|PROT_EXEC) == -1) {
50  SCLogConfig("RWX pages denied by OS");
51  retval = 0;
52  }
53  munmap(ptr, getpagesize());
54  }
55  return retval;
56 }
57 #endif /* HAVE_PAGESUPPORTSRWX_AS_MACRO */
58 
util-debug.h
PageSupportsRWX
#define PageSupportsRWX()
Definition: util-pages.h:37
util-pages.h
suricata-common.h
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.