-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtnt_include.h
323 lines (254 loc) · 12.3 KB
/
tnt_include.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*--------------------------------------------------------------------*/
/*--- A header file for all parts of Taintgrind. ---*/
/*--- tnt_include.h ---*/
/*--------------------------------------------------------------------*/
/*
This file is part of Taintgrind, a heavyweight Valgrind tool for
taint analysis.
Copyright (C) 2010 Wei Ming Khoo
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., 59 Temple Place, Suite 330, Boston, MA
02111-1307, USA.
The GNU General Public License is contained in the file COPYING.
*/
#ifndef __TNT_INCLUDE_H
#define __TNT_INCLUDE_H
#include "taintgrind.h"
#define STACK_TRACE_SIZE 20
#define TNT_(str) VGAPPEND(vgTaintgrind_,str)
/*------------------------------------------------------------*/
/*--- Profiling of memory events ---*/
/*------------------------------------------------------------*/
/* Define to collect detailed performance info. */
/* #define TNT_PROFILE_MEMORY */
#ifdef TNT_PROFILE_MEMORY
# define N_PROF_EVENTS 500
UInt TNT_(event_ctr)[N_PROF_EVENTS];
HChar* TNT_(event_ctr_name)[N_PROF_EVENTS];
# define PROF_EVENT(ev, name) \
do { tl_assert((ev) >= 0 && (ev) < N_PROF_EVENTS); \
/* crude and inaccurate check to ensure the same */ \
/* event isn't being used with > 1 name */ \
if (TNT_(event_ctr_name)[ev]) \
tl_assert(name == TNT_(event_ctr_name)[ev]); \
TNT_(event_ctr)[ev]++; \
TNT_(event_ctr_name)[ev] = (name); \
} while (False);
#else
# define PROF_EVENT(ev, name) /* */
#endif /* TNT_PROFILE_MEMORY */
/*------------------------------------------------------------*/
/*--- V and A bits (Victoria & Albert ?) ---*/
/*------------------------------------------------------------*/
/* The number of entries in the primary map can be altered. However
we hardwire the assumption that each secondary map covers precisely
64k of address space. */
#define SM_SIZE 65536 /* DO NOT CHANGE */
#define SM_MASK (SM_SIZE-1) /* DO NOT CHANGE */
#define V_BIT_UNTAINTED 0
#define V_BIT_TAINTED 1
#define V_BITS8_UNTAINTED 0
#define V_BITS8_TAINTED 0xFF
#define V_BITS16_UNTAINTED 0
#define V_BITS16_TAINTED 0xFFFF
#define V_BITS32_UNTAINTED 0
#define V_BITS32_TAINTED 0xFFFFFFFF
#define V_BITS64_UNTAINTED 0ULL
#define V_BITS64_TAINTED 0xFFFFFFFFFFFFFFFFULL
/*------------------------------------------------------------*/
/*--- Instrumentation ---*/
/*------------------------------------------------------------*/
/* Functions/vars defined in tnt_main.c */
UChar get_vabits2( Addr a ); // Taintgrind: needed by TNT_(instrument)
void TNT_(make_mem_noaccess)( Addr a, SizeT len );
void TNT_(make_mem_tainted)( Addr a, SizeT len );
void TNT_(make_mem_defined)( Addr a, SizeT len );
void TNT_(copy_address_range_state) ( Addr src, Addr dst, SizeT len );
VG_REGPARM(3) void TNT_(helperc_0_tainted_enc32) ( UInt, UInt, UInt, UInt, UInt, UInt );
VG_REGPARM(3) void TNT_(helperc_0_tainted_enc64) ( ULong, ULong, ULong, ULong );
VG_REGPARM(3) void TNT_(helperc_1_tainted_enc32) ( UInt, UInt, UInt, UInt, UInt, UInt, UInt );
VG_REGPARM(3) void TNT_(helperc_1_tainted_enc64) ( ULong, ULong, ULong, ULong, ULong, ULong );
VG_REGPARM(3) void TNT_(helperc_0_tainted) ( HChar *, UInt, UInt );
VG_REGPARM(3) void TNT_(helperc_1_tainted) ( HChar *, UInt, UInt, UInt, UInt );
VG_REGPARM(3) void TNT_(helperc_2_tainted) ( HChar *, UInt, UInt, UInt, UInt, UInt, UInt );
VG_REGPARM(3) void TNT_(helperc_3_tainted) ( HChar *, UInt, UInt, UInt, UInt, UInt );
VG_REGPARM(3) void TNT_(helperc_4_tainted) ( HChar *, UInt, UInt, UInt, UInt, UInt, UInt );
/* Strings used by tnt_translate, printed by tnt_main */
extern const char *IRType_string[];
extern const char *IREndness_string[];
extern const char *IRConst_string[];
extern const char *IROp_string[];
extern const char *IRExpr_string[];
extern const char *IRStmt_string[];
extern const char *IRJumpKind_string[];
/* V-bits load/store helpers */
VG_REGPARM(1) void TNT_(helperc_STOREV64be) ( Addr, ULong );
VG_REGPARM(1) void TNT_(helperc_STOREV64le) ( Addr, ULong );
VG_REGPARM(2) void TNT_(helperc_STOREV32be) ( Addr, UWord );
VG_REGPARM(2) void TNT_(helperc_STOREV32le) ( Addr, UWord );
VG_REGPARM(2) void TNT_(helperc_STOREV16be) ( Addr, UWord );
VG_REGPARM(2) void TNT_(helperc_STOREV16le) ( Addr, UWord );
VG_REGPARM(2) void TNT_(helperc_STOREV8) ( Addr, UWord );
VG_REGPARM(1) ULong TNT_(helperc_LOADV64be) ( Addr );
VG_REGPARM(1) ULong TNT_(helperc_LOADV64le) ( Addr );
VG_REGPARM(1) UWord TNT_(helperc_LOADV32be) ( Addr );
VG_REGPARM(1) UWord TNT_(helperc_LOADV32le) ( Addr );
VG_REGPARM(1) UWord TNT_(helperc_LOADV16be) ( Addr );
VG_REGPARM(1) UWord TNT_(helperc_LOADV16le) ( Addr );
VG_REGPARM(1) UWord TNT_(helperc_LOADV8) ( Addr );
void TNT_(helperc_MAKE_STACK_UNINIT) ( Addr base, UWord len,
Addr nia );
/* Taintgrind args */
extern HChar* TNT_(clo_file_filter);
extern Int TNT_(clo_taint_start);
extern Int TNT_(clo_taint_len);
extern Bool TNT_(clo_taint_all);
extern Int TNT_(clo_after_bb);
extern Int TNT_(clo_before_bb);
extern Bool TNT_(clo_tainted_ins_only);
extern Bool TNT_(clo_critical_ins_only);
extern Int TNT_(do_print);
//extern Char* TNT_(clo_allowed_syscalls);
//extern Bool TNT_(read_syscalls_file);
extern Bool TNT_(instrument_start);
/* Functions defined in malloc_wrappers.c */
#define TNT_MALLOC_REDZONE_SZB 16
#if 0
/* For malloc()/new/new[] vs. free()/delete/delete[] mismatch checking. */
typedef
enum {
TNT_AllocMalloc = 0,
TNT_AllocNew = 1,
TNT_AllocNewVec = 2,
TNT_AllocCustom = 3
}
TNT_AllocKind;
#endif
/* This describes a heap block. Nb: first two fields must match core's
* VgHashNode. */
typedef
struct _HP_Chunk {
struct _HP_Chunk* next;
Addr data; // Address of the actual block.
SizeT req_szB; // Size requested
SizeT slop_szB; // Extra bytes given above those requested
}
HP_Chunk;
#if 0
/* Memory pool. Nb: first two fields must match core's VgHashNode. */
typedef
struct _TNT_Mempool {
struct _TNT_Mempool* next;
Addr pool; // pool identifier
SizeT rzB; // pool red-zone size
Bool is_zeroed; // allocations from this pool are zeroed
VgHashTable chunks; // chunks associated with this pool
}
TNT_Mempool;
void* TNT_(new_block) ( ThreadId tid,
Addr p, SizeT size, SizeT align,
Bool is_zeroed, TNT_AllocKind kind,
VgHashTable table);
void TNT_(handle_free) ( ThreadId tid,
Addr p, UInt rzB, TNT_AllocKind kind );
void TNT_(create_mempool) ( Addr pool, UInt rzB, Bool is_zeroed );
void TNT_(destroy_mempool) ( Addr pool );
void TNT_(mempool_alloc) ( ThreadId tid, Addr pool,
Addr addr, SizeT size );
void TNT_(mempool_free) ( Addr pool, Addr addr );
void TNT_(mempool_trim) ( Addr pool, Addr addr, SizeT size );
void TNT_(move_mempool) ( Addr poolA, Addr poolB );
void TNT_(mempool_change) ( Addr pool, Addr addrA, Addr addrB, SizeT size );
Bool TNT_(mempool_exists) ( Addr pool );
TNT_Chunk* TNT_(get_freed_list_head)( void );
#endif
/* For tracking malloc'd blocks. Nb: it's quite important that it's a
VgHashTable, because VgHashTable allows duplicate keys without complaint.
This can occur if a user marks a malloc() block as also a custom block with
MALLOCLIKE_BLOCK. */
extern VgHashTable TNT_(malloc_list);
/* For tracking memory pools. */
//extern VgHashTable TNT_(mempool_list);
/* Shadow memory functions */
Bool TNT_(check_mem_is_noaccess)( Addr a, SizeT len, Addr* bad_addr );
void TNT_(make_mem_noaccess) ( Addr a, SizeT len );
void TNT_(make_mem_undefined_w_otag)( Addr a, SizeT len, UInt otag );
void TNT_(make_mem_defined) ( Addr a, SizeT len );
void TNT_(copy_address_range_state) ( Addr src, Addr dst, SizeT len );
void TNT_(print_malloc_stats) ( void );
void* TNT_(malloc) ( ThreadId tid, SizeT n );
void* TNT_(__builtin_new) ( ThreadId tid, SizeT n );
void* TNT_(__builtin_vec_new) ( ThreadId tid, SizeT n );
void* TNT_(memalign) ( ThreadId tid, SizeT align, SizeT n );
void* TNT_(calloc) ( ThreadId tid, SizeT nmemb, SizeT size1 );
void TNT_(free) ( ThreadId tid, void* p );
void TNT_(__builtin_delete) ( ThreadId tid, void* p );
void TNT_(__builtin_vec_delete) ( ThreadId tid, void* p );
void* TNT_(realloc) ( ThreadId tid, void* p, SizeT new_size );
SizeT TNT_(malloc_usable_size) ( ThreadId tid, void* p );
/* Functions defined in tnt_syswrap.c */
/* System call wrappers */
extern void TNT_(syscall_read)(ThreadId tid, UWord* args, UInt nArgs, SysRes res);
extern void TNT_(syscall_write)(ThreadId tid, UWord* args, UInt nArgs, SysRes res);
extern void TNT_(syscall_open)(ThreadId tid, UWord* args, UInt nArgs, SysRes res);
extern void TNT_(syscall_close)(ThreadId tid, UWord* args, UInt nArgs, SysRes res);
extern void TNT_(syscall_llseek)(ThreadId tid, UWord* args, UInt nArgs, SysRes res);
extern void TNT_(syscall_pread)(ThreadId tid, UWord* args, UInt nArgs, SysRes res);
extern Bool TNT_(syscall_allowed_check)(ThreadId tid, int syscallno);
/* Functions defined in tnt_translate.c */
IRSB* TNT_(instrument)( VgCallbackClosure* closure,
IRSB* bb_in,
VexGuestLayout* layout,
VexGuestExtents* vge,
VexArchInfo* vai,
IRType gWordTy, IRType hWordTy );
/* Client request handler */
extern Bool TNT_(handle_client_requests) ( ThreadId tid, UWord* arg, UWord* ret );
/* SOAAP-related data */
extern HChar* client_binary_name;
#define FNNAME_MAX 100
extern UInt persistent_sandbox_nesting_depth;
extern UInt ephemeral_sandbox_nesting_depth;
extern Bool have_created_sandbox;
#define FD_MAX 256
#define FD_MAX_PATH 256
#define FD_READ 0x1
#define FD_WRITE 0x2
#define FD_STAT 0x4
extern UInt shared_fds[];
#define VAR_MAX 100
#define VAR_READ 0x1
#define VAR_WRITE 0x2
enum VariableType { Local = 3, Global = 4 };
enum VariableLocation { GlobalFromApplication = 5, GlobalFromElsewhere = 6 };
extern struct myStringArray shared_vars;
extern UInt shared_vars_perms[];
extern HChar* next_shared_variable_to_update;
#define IN_SANDBOX (persistent_sandbox_nesting_depth > 0 || ephemeral_sandbox_nesting_depth > 0)
#define FD_SET_PERMISSION(fd,perm) shared_fds[fd] |= perm
#define VAR_SET_PERMISSION(var_idx,perm) shared_vars_perms[var_idx] |= perm
#define SYSCALLS_MAX 500
extern Bool allowed_syscalls[];
#define IS_SYSCALL_ALLOWED(no) (allowed_syscalls[no] == True)
extern UInt callgate_nesting_depth;
#define IN_CALLGATE (nested_callgate_depth > 0)
/* System call array */
extern const char* syscallnames[];
/* Utility functions */
extern void TNT_(describe_data)(Addr addr, HChar* varnamebuf, UInt bufsize, enum VariableType* type, enum VariableLocation* loc);
extern void TNT_(get_fnname)(ThreadId tid, HChar* buf, UInt buf_size);
extern void TNT_(check_fd_access)(ThreadId tid, UInt fd, Int fd_request);
extern void TNT_(check_var_access)(ThreadId tid, HChar* varname, Int var_request, enum VariableType type, enum VariableLocation var_loc);
#endif /* ndef __TNT_INCLUDE_H */
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/