9 #include "trinity.h" // progname
15 #include "protocols.h"
18 #define TAINT_NAME_LEN 32
22 bool do_specific_syscall
= FALSE
;
23 bool do_exclude_syscall
= FALSE
;
25 bool do_32_arch
= TRUE
;
26 bool do_64_arch
= TRUE
;
28 unsigned int specific_proto
= 0;
29 unsigned int user_specified_children
= 0;
31 bool do_specific_proto
= FALSE
;
32 bool no_protos
[TRINITY_PF_MAX
];
35 bool show_syscall_list
= FALSE
;
36 bool show_ioctl_list
= FALSE
;
37 unsigned char quiet_level
= 0;
39 bool monochrome
= FALSE
;
40 bool dangerous
= FALSE
;
42 bool do_syslog
= FALSE
;
43 bool random_selection
= FALSE
;
44 unsigned int random_selection_num
;
45 bool no_files
= FALSE
;
47 bool user_set_seed
= FALSE
;
49 unsigned char desired_group
= GROUP_NONE
;
51 char *specific_proto_optarg
;
55 int kernel_taint_initial
= 0;
56 int kernel_taint_mask
= 0xFFFFFFFF;
57 bool kernel_taint_param_occured
= FALSE
;
59 static void usage(void)
61 outputerr("%s\n", progname
);
62 outputerr(" --arch, -a: selects syscalls for the specified architecture (32 or 64). Both by default.\n");
63 outputerr(" --children,-C: specify number of child processes\n");
64 outputerr(" --exclude,-x: don't call a specific syscall\n");
65 outputerr(" --group,-g: only run syscalls from a certain group (So far just 'vm').\n");
66 outputerr(" --ioctls,-I: list all ioctls.\n");
67 outputerr(" --kernel_taint, -T: controls which kernel taint flags should be considered, for more details refer to README file. \n");
68 outputerr(" --list,-L: list all syscalls known on this architecture.\n");
69 outputerr(" --logging,-l: (off=disable logging).\n");
70 outputerr(" --monochrome,-m: don't output ANSI codes\n");
71 outputerr(" --no_files,-n: Only pass sockets as fd's, not files\n");
72 outputerr(" --proto,-P: specify specific network protocol for sockets.\n");
73 outputerr(" --no_proto,-E: specify network protocols to be excluded from testing.\n");
74 outputerr(" --quiet,-q: less output.\n");
75 outputerr(" --random,-r#: pick N syscalls at random and just fuzz those\n");
76 outputerr(" --syslog,-S: log important info to syslog. (useful if syslog is remote)\n");
77 outputerr(" --verbose,-v: increase output verbosity.\n");
78 outputerr(" --victims,-V: path to victim files.\n");
80 outputerr(" -c#,@: target specific syscall (takes syscall name as parameter and optionally 32 or 64 as bit-width. Default:both).\n");
81 outputerr(" -N#: do # syscalls then exit.\n");
82 outputerr(" -p: pause after syscall.\n");
83 outputerr(" -s#: use # as random seed.\n");
87 static const struct option longopts
[] = {
88 { "children", required_argument
, NULL
, 'C' },
89 { "dangerous", no_argument
, NULL
, 'd' },
90 { "debug", no_argument
, NULL
, 'D' },
91 { "exclude", required_argument
, NULL
, 'x' },
92 { "group", required_argument
, NULL
, 'g' },
93 { "kernel_taint", required_argument
, NULL
, 'T' },
94 { "help", no_argument
, NULL
, 'h' },
95 { "list", no_argument
, NULL
, 'L' },
96 { "ioctls", no_argument
, NULL
, 'I' },
97 { "logging", required_argument
, NULL
, 'l' },
98 { "monochrome", no_argument
, NULL
, 'm' },
99 { "no_files", no_argument
, NULL
, 'n' },
100 { "proto", required_argument
, NULL
, 'P' },
101 { "no_proto", required_argument
, NULL
, 'E' },
102 { "random", required_argument
, NULL
, 'r' },
103 { "quiet", no_argument
, NULL
, 'q' },
104 { "syslog", no_argument
, NULL
, 'S' },
105 { "victims", required_argument
, NULL
, 'V' },
106 { "verbose", no_argument
, NULL
, 'v' },
107 { "arch", required_argument
, NULL
, 'a' },
108 { NULL
, 0, NULL
, 0 } };
110 static void toggle_taint_flag(int bit
) {
111 kernel_taint_mask
|= (1 << bit
);
114 static void toggle_taint_flag_by_name(char *beg
, char *end
) {
115 char flagname
[TAINT_NAME_LEN
];
124 if (maxlen
> (TAINT_NAME_LEN
- 1))
125 maxlen
= TAINT_NAME_LEN
- 1;
126 strncpy(flagname
, beg
, maxlen
);
127 flagname
[maxlen
] = 0;
130 if (strcmp(name
,"PROPRIETARY_MODULE") == 0)
131 toggle_taint_flag(TAINT_PROPRIETARY_MODULE
);
132 else if (strcmp(name
,"FORCED_MODULE") == 0)
133 toggle_taint_flag(TAINT_FORCED_MODULE
);
134 else if (strcmp(name
,"UNSAFE_SMP") == 0)
135 toggle_taint_flag(TAINT_UNSAFE_SMP
);
136 else if (strcmp(name
,"FORCED_RMMOD") == 0)
137 toggle_taint_flag(TAINT_FORCED_RMMOD
);
138 else if (strcmp(name
,"MACHINE_CHECK") == 0)
139 toggle_taint_flag(TAINT_MACHINE_CHECK
);
140 else if (strcmp(name
,"BAD_PAGE") == 0)
141 toggle_taint_flag(TAINT_BAD_PAGE
);
142 else if (strcmp(name
,"USER") == 0)
143 toggle_taint_flag(TAINT_USER
);
144 else if (strcmp(name
,"DIE") == 0)
145 toggle_taint_flag(TAINT_DIE
);
146 else if (strcmp(name
,"OVERRIDDEN_ACPI_TABLE") == 0)
147 toggle_taint_flag(TAINT_OVERRIDDEN_ACPI_TABLE
);
148 else if (strcmp(name
,"WARN") == 0)
149 toggle_taint_flag(TAINT_WARN
);
150 else if (strcmp(name
,"CRAP") == 0)
151 toggle_taint_flag(TAINT_CRAP
);
152 else if (strcmp(name
,"FIRMWARE_WORKAROUND") == 0)
153 toggle_taint_flag(TAINT_FIRMWARE_WORKAROUND
);
154 else if (strcmp(name
,"OOT_MODULE") == 0)
155 toggle_taint_flag(TAINT_OOT_MODULE
);
157 outputerr("Unrecognizable kernel taint flag \"%s\".\n", name
);
162 static void process_taint_arg(char *taintarg
) {
165 if (kernel_taint_param_occured
== FALSE
) {
166 kernel_taint_param_occured
= TRUE
;
167 kernel_taint_mask
= 0; //We now only care about flags that user specified.
171 end
= strchr(beg
, ',');
173 toggle_taint_flag_by_name(beg
,end
);
175 end
= strchr(beg
, ',');
177 toggle_taint_flag_by_name(beg
,end
);
180 void parse_args(int argc
, char *argv
[])
184 while ((opt
= getopt_long(argc
, argv
, "a:c:C:dDg:hIl:LN:mnP:E:pqr:s:T:SV:vx:", longopts
, NULL
)) != -1) {
190 outputstd("opt:%c\n", opt
);
197 /* syscalls are all disabled at this point. enable the syscall we care about. */
198 do_specific_syscall
= TRUE
;
199 toggle_syscall(optarg
, TRUE
);
203 /* One of the architectures selected*/
206 if (strcmp(optarg
, "64") == 0)
208 else if (strcmp(optarg
, "32") == 0)
216 user_specified_children
= strtoll(optarg
, NULL
, 10);
228 if (!strcmp(optarg
, "vm"))
229 desired_group
= GROUP_VM
;
230 if (!strcmp(optarg
, "vfs"))
231 desired_group
= GROUP_VFS
;
240 show_ioctl_list
= TRUE
;
244 if (!strcmp(optarg
, "off"))
249 show_syscall_list
= TRUE
;
260 /* Set number of syscalls to do */
262 syscalls_todo
= strtoll(optarg
, NULL
, 10);
265 /* Pause after each syscall */
271 do_specific_proto
= 1;
272 specific_proto
= strtol(optarg
, NULL
, 10);
273 specific_proto_optarg
= optarg
;
277 parse_exclude_protos(optarg
);
285 if (do_exclude_syscall
== TRUE
) {
286 outputerr("-r needs to be before any -x options.\n");
289 random_selection
= 1;
290 random_selection_num
= strtol(optarg
, NULL
, 10);
295 seed
= strtol(optarg
, NULL
, 10);
296 user_set_seed
= TRUE
;
305 //Load mask for kernel taint flags.
306 process_taint_arg(optarg
);
314 victim_path
= strdup(optarg
);
315 //FIXME: Later, allow for multiple victim files
319 do_exclude_syscall
= TRUE
;
320 toggle_syscall(optarg
, FALSE
);
324 if (quiet_level
> MAX_LOGLEVEL
)
325 quiet_level
= MAX_LOGLEVEL
;
327 quiet_level
= MAX_LOGLEVEL
- quiet_level
;