View | Details | Raw Unified | Return to bug 221132
Collapse All | Expand All

(-)security/sandsifter/Makefile (+22 lines)
Line 0 Link Here
1
# Created by: Rozhuk Ivan <rozhuk.im@gmail.com>
2
# $FreeBSD$
3
4
PORTNAME=	sandsifter
5
PORTVERSION=	0.1
6
CATEGORIES=	security
7
8
MAINTAINER=	ports@FreeBSD.org
9
COMMENT=	x86 processor fuzzer
10
11
USE_GITHUB=	yes
12
GH_ACCOUNT=	xoreaxeaxeax
13
GH_TAGNAME=	dff63246fed84d90118441b8ba5b5d3bdd094427
14
15
BUILD_DEPENDS=	${LOCALBASE}/include/capstone/capstone.h:devel/capstone3
16
RUN_DEPENDS=	${PYTHON_PKGNAMEPREFIX}capstone>0:devel/py-capstone
17
USES=		gmake python localbase
18
19
#do-install:
20
#	${INSTALL_PROGRAM} ${WRKSRC}/sasp ${STAGEDIR}${PREFIX}/sbin
21
22
.include <bsd.port.mk>
(-)security/sandsifter/distinfo (+3 lines)
Line 0 Link Here
1
TIMESTAMP = 1501534237
2
SHA256 (xoreaxeaxeax-sandsifter-0.1-dff63246fed84d90118441b8ba5b5d3bdd094427_GH0.tar.gz) = 010d662705bb67035e3d6b93a0fbe0bcf7ab2b5ba93e6eb977eb614c7dec3691
3
SIZE (xoreaxeaxeax-sandsifter-0.1-dff63246fed84d90118441b8ba5b5d3bdd094427_GH0.tar.gz) = 5284438
(-)security/sandsifter/files/patch-Makefile (+11 lines)
Line 0 Link Here
1
--- Makefile.orig	2017-07-27 22:17:30.000000000 +0300
2
+++ Makefile	2017-08-01 02:08:49.396326000 +0300
3
@@ -32,7 +32,7 @@
4
 all: injector
5
 
6
 injector: injector.o
7
-	$(CC) $(CFLAGS) $< -O3 -Wall -l:libcapstone.a -o $@ -pthread
8
+	$(CC) $(CFLAGS) $(LIBS) $(LDFLAGS) $< -O3 -Wall -l:libcapstone.a -o $@ -pthread
9
 
10
 %.o: %.c
11
 	$(CC) $(CFLAGS) -c $< -o $@ -Wall
(-)security/sandsifter/files/patch-injector.c (+96 lines)
Line 0 Link Here
1
--- injector.c.orig	2017-07-27 22:17:30.000000000 +0300
2
+++ injector.c	2017-08-01 01:54:04.885858000 +0300
3
@@ -77,10 +77,24 @@
4
 
5
 /* 32 vs 64 */
6
 
7
-#if __x86_64__
8
-	#define IP REG_RIP 
9
+#ifdef __linux__ /* Linux specific code. */
10
+#	define PAGE_SIZE 4096
11
+#	define EFL gregs[REG_EFL]
12
+#	if __x86_64__
13
+#		define IP gregs[REG_RIP]
14
+#	else
15
+#		define IP gregs[REG_EIP]
16
+#	endif
17
 #else
18
-	#define IP REG_EIP 
19
+#	include <pthread_np.h>
20
+	typedef cpuset_t cpu_set_t;
21
+#	if __x86_64__
22
+#		define IP mc_rip
23
+#		define EFL mc_rflags
24
+#	else
25
+#		define IP mc_eip
26
+#		define EFL mc_eflags
27
+#	endif
28
 #endif
29
 
30
 /* leave state as 0 */
31
@@ -155,7 +169,6 @@
32
 /* x86/64 */
33
 
34
 #define UD2_SIZE  2
35
-#define PAGE_SIZE 4096
36
 #define TF        0x100
37
 
38
 /* injection */
39
@@ -850,7 +863,7 @@
40
 void state_handler(int signum, siginfo_t* si, void* p)
41
 {
42
 	fault_context=((ucontext_t*)p)->uc_mcontext;
43
-	((ucontext_t*)p)->uc_mcontext.gregs[IP]+=UD2_SIZE;
44
+	((ucontext_t*)p)->uc_mcontext.IP+=UD2_SIZE;
45
 }
46
 
47
 void fault_handler(int signum, siginfo_t* si, void* p)
48
@@ -863,7 +876,7 @@
49
 
50
 	/* make an initial estimate on the instruction length from the fault address */
51
 	insn_length=
52
-		(uintptr_t)uc->uc_mcontext.gregs[IP]-(uintptr_t)packet-preamble_length;
53
+		(uintptr_t)uc->uc_mcontext.IP-(uintptr_t)packet-preamble_length;
54
 
55
 	if (insn_length<0) {
56
 		insn_length=JMP_LENGTH;
57
@@ -880,9 +893,13 @@
58
 		(signum==SIGSEGV||signum==SIGBUS)?(uint32_t)(uintptr_t)si->si_addr:(uint32_t)-1
59
 	};
60
 
61
+#ifdef __linux__ /* Linux specific code. */
62
 	memcpy(uc->uc_mcontext.gregs, fault_context.gregs, sizeof(fault_context.gregs));
63
-	uc->uc_mcontext.gregs[IP]=(uintptr_t)&resume;
64
-	uc->uc_mcontext.gregs[REG_EFL]&=~TF;
65
+#else
66
+	memcpy(&uc->uc_mcontext, &fault_context, sizeof(fault_context));
67
+#endif
68
+	uc->uc_mcontext.IP=(uintptr_t)&resume;
69
+	uc->uc_mcontext.EFL&=~TF;
70
 }
71
 
72
 void configure_sig_handler(void (*handler)(int, siginfo_t*, void*))
73
@@ -1341,7 +1358,13 @@
74
 		cpu_set_t mask;
75
 		CPU_ZERO(&mask);
76
 		CPU_SET(config.core,&mask);
77
-		if (sched_setaffinity(0, sizeof(mask), &mask)) {
78
+#ifdef __linux__ /* Linux specific code. */
79
+		if (sched_setaffinity(0, sizeof(mask), &mask))
80
+#else
81
+		if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID,
82
+		    -1, sizeof(mask), &mask))
83
+#endif
84
+		{
85
 			printf("error: failed to set cpu\n");
86
 			exit(1);
87
 		}
88
@@ -1439,7 +1462,7 @@
89
 		null_p=mmap(0, PAGE_SIZE, PROT_READ|PROT_WRITE,
90
 			MAP_FIXED|MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
91
 		if (null_p==MAP_FAILED) {
92
-			printf("null access requires running as root\n");
93
+			printf("null access requires running as root, %i\n", errno);
94
 			exit(1);
95
 		}
96
 	}
(-)security/sandsifter/files/patch-sifter.py (+25 lines)
Line 0 Link Here
1
--- sifter.py.orig	2017-08-01 03:34:37.224624000 +0300
2
+++ sifter.py	2017-08-01 03:35:34.961522000 +0300
3
@@ -30,7 +30,7 @@
4
 INJECTOR = "./injector"
5
 arch = ""
6
 
7
-OUTPUT = "./data/"
8
+OUTPUT = "~/.sandsifter/"
9
 LOG  = OUTPUT + "log"
10
 SYNC = OUTPUT + "sync"
11
 TICK = OUTPUT + "tick"
12
@@ -679,9 +679,10 @@
13
             time.sleep(self.TIME_SLICE)
14
 
15
 def get_cpu_info():
16
-    with open("/proc/cpuinfo", "r") as f:
17
-        cpu = [l.strip() for l in f.readlines()[:7]]
18
-    return cpu
19
+    #with open("/proc/cpuinfo", "r") as f:
20
+    #    cpu = [l.strip() for l in f.readlines()[:7]]
21
+    #return cpu
22
+    return "01234567"
23
 
24
 def dump_artifacts(r, injector, command_line):
25
     global arch
(-)security/sandsifter/files/pkg-message.in (+8 lines)
Line 0 Link Here
1
2
Attention
3
4
Before use this tool You should set:
5
6
sysctl security.bsd.map_at_zero=1
7
8
(-)security/sandsifter/pkg-descr (+31 lines)
Line 0 Link Here
1
s a n d s i f t e r
2
3
: the x86 processor fuzzer
4
Overview
5
6
The sandsifter audits x86 processors for hidden instructions and 
7
hardware bugs, by systematically generating machine code to search
8
through a processor's instruction set, and monitoring execution for
9
anomalies. Sandsifter has uncovered secret processor instructions from
10
every major vendor; ubiquitous software bugs in disassemblers,
11
assemblers, and emulators; flaws in enterprise hypervisors; and both
12
benign and security-critical hardware bugs in x86 chips.
13
14
With the multitude of x86 processors in existence, the goal of the tool
15
is to enable users to check their own systems for hidden instructions
16
and bugs.
17
18
To run a basic audit against your processor:
19
20
sudo ./sifter.py --unk --dis --len --sync --tick -- -P1 -t
21
22
The computer is systematically scanned for anomalous instructions.
23
In the upper half, you can view the instructions that the sandsifter
24
is currently testing on the processor. In the bottom half, the
25
sandsifter reports anomalies it finds.
26
27
The search will take from a few hours to a few days, depending on the
28
speed of and complexity of your processor. When it is complete,
29
summarize the results:
30
31
./summarize.py data/log

Return to bug 221132