-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replacing seccomp printing with a seccomp disassembler
- Loading branch information
netblue30
committed
Dec 28, 2017
1 parent
96f26b0
commit f9c60d5
Showing
14 changed files
with
571 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
all: fsec-print | ||
|
||
CC=@CC@ | ||
prefix=@prefix@ | ||
exec_prefix=@exec_prefix@ | ||
libdir=@libdir@ | ||
sysconfdir=@sysconfdir@ | ||
|
||
VERSION=@PACKAGE_VERSION@ | ||
NAME=@PACKAGE_NAME@ | ||
HAVE_SECCOMP_H=@HAVE_SECCOMP_H@ | ||
HAVE_SECCOMP=@HAVE_SECCOMP@ | ||
HAVE_CHROOT=@HAVE_CHROOT@ | ||
HAVE_BIND=@HAVE_BIND@ | ||
HAVE_FATAL_WARNINGS=@HAVE_FATAL_WARNINGS@ | ||
HAVE_NETWORK=@HAVE_NETWORK@ | ||
HAVE_USERNS=@HAVE_USERNS@ | ||
HAVE_X11=@HAVE_X11@ | ||
HAVE_FILE_TRANSFER=@HAVE_FILE_TRANSFER@ | ||
HAVE_WHITELIST=@HAVE_WHITELIST@ | ||
HAVE_GLOBALCFG=@HAVE_GLOBALCFG@ | ||
HAVE_APPARMOR=@HAVE_APPARMOR@ | ||
HAVE_OVERLAYFS=@HAVE_OVERLAYFS@ | ||
HAVE_PRIVATE_HOME=@HAVE_PRIVATE_HOME@ | ||
EXTRA_LDFLAGS +=@EXTRA_LDFLAGS@ | ||
HAVE_GCOV=@HAVE_GCOV@ | ||
EXTRA_LDFLAGS +=@EXTRA_LDFLAGS@ | ||
|
||
H_FILE_LIST = $(sort $(wildcard *.[h])) | ||
C_FILE_LIST = $(sort $(wildcard *.c)) | ||
OBJS = $(C_FILE_LIST:.c=.o) | ||
BINOBJS = $(foreach file, $(OBJS), $file) | ||
CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' $(HAVE_GCOV) -DPREFIX='"$(prefix)"' -DSYSCONFDIR='"$(sysconfdir)/firejail"' -DLIBDIR='"$(libdir)"' $(HAVE_X11) $(HAVE_PRIVATE_HOME) $(HAVE_APPARMOR) $(HAVE_OVERLAYFS) $(HAVE_SECCOMP) $(HAVE_GLOBALCFG) $(HAVE_SECCOMP_H) $(HAVE_CHROOT) $(HAVE_NETWORK) $(HAVE_USERNS) $(HAVE_BIND) $(HAVE_FILE_TRANSFER) $(HAVE_WHITELIST) -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIE -pie -Wformat -Wformat-security | ||
LDFLAGS += -pie -Wl,-z,relro -Wl,-z,now -lpthread | ||
|
||
%.o : %.c $(H_FILE_LIST) ../include/common.h ../include/seccomp.h ../include/syscall.h | ||
$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ | ||
|
||
fsec-print: $(OBJS) ../lib/libnetlink.o | ||
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(EXTRA_LDFLAGS) | ||
|
||
clean:; rm -f *.o fsec-print *.gcov *.gcda *.gcno | ||
|
||
distclean: clean | ||
rm -fr Makefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2014-2017 Firejail Authors | ||
* | ||
* This file is part of firejail project | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
#ifndef FSEC_PRINT_H | ||
#define FSEC_PRINT_H | ||
#include "../include/common.h" | ||
#include "../include/seccomp.h" | ||
#include <sys/mman.h> | ||
|
||
// print.c | ||
void print(struct sock_filter *filter, int entries); | ||
|
||
// syscall_list.c | ||
const char *syscall_find_nr(int nr); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (C) 2014-2017 Firejail Authors | ||
* | ||
* This file is part of firejail project | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
#include "fsec_print.h" | ||
|
||
static void usage(void) { | ||
printf("Usage:\n"); | ||
printf("\tfsec-print file - disassemble seccomp filter\n"); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
#if 0 | ||
{ | ||
//system("cat /proc/self/status"); | ||
int i; | ||
for (i = 0; i < argc; i++) | ||
printf("*%s* ", argv[i]); | ||
printf("\n"); | ||
} | ||
#endif | ||
if (argc != 2) { | ||
usage(); | ||
return 1; | ||
} | ||
|
||
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) { | ||
usage(); | ||
return 0; | ||
} | ||
|
||
char *fname = argv[1]; | ||
|
||
// open input file | ||
int fd = open(fname, O_RDONLY); | ||
if (fd == -1) | ||
goto errexit; | ||
|
||
// calculate the number of entries | ||
int size = lseek(fd, 0, SEEK_END); | ||
if (size == -1) // todo: check maximum size of seccomp filter (4KB?) | ||
goto errexit; | ||
unsigned short entries = (unsigned short) size / (unsigned short) sizeof(struct sock_filter); | ||
|
||
// read filter | ||
struct sock_filter *filter = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); | ||
if (filter == MAP_FAILED) | ||
goto errexit; | ||
|
||
|
||
// print filter | ||
print(filter, entries); | ||
|
||
// free mapped memory | ||
if (munmap(filter, size) == -1) | ||
perror("Error un-mmapping the file"); | ||
|
||
// close file | ||
close(fd); | ||
return 0; | ||
errexit: | ||
close(fd); | ||
fprintf(stderr, "Error: cannot read %s\n", fname); | ||
exit(1); | ||
|
||
} |
Oops, something went wrong.