blob: 9ea5dca966d6e6eeb1875ace5af5df7f04bf2dea [file] [log] [blame]
Jorge Lucangeli Obesa6b034d2012-08-07 15:29:20 -07001/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -07002 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -07004 */
5
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -07006#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -07009
10#include "syscall_filter.h"
11
Jorge Lucangeli Obesa6b034d2012-08-07 15:29:20 -070012#include "util.h"
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -070013
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -070014#define MAX_LINE_LENGTH 1024
15#define MAX_POLICY_LINE_LENGTH 1024
16
Jorge Lucangeli Obesa6b034d2012-08-07 15:29:20 -070017#define ONE_INSTR 1
18#define TWO_INSTRS 2
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -070019
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -070020int str_to_op(const char *op_str)
21{
22 if (!strcmp(op_str, "==")) {
23 return EQ;
24 } else if (!strcmp(op_str, "!=")) {
25 return NE;
Jorge Lucangeli Obes66cfc142012-11-30 15:42:52 -080026 } else if (!strcmp(op_str, "&")) {
27 return SET;
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -070028 } else {
29 return 0;
30 }
31}
32
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -070033struct sock_filter *new_instr_buf(size_t count)
34{
35 struct sock_filter *buf = calloc(count, sizeof(struct sock_filter));
36 if (!buf)
Jorge Lucangeli Obes224e4272012-08-02 14:31:39 -070037 die("could not allocate BPF instruction buffer");
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -070038
39 return buf;
40}
41
Jorge Lucangeli Obesd96baf42013-03-26 15:11:30 -070042struct filter_block *new_filter_block()
43{
44 struct filter_block *block = calloc(1, sizeof(struct filter_block));
45 if (!block)
46 die("could not allocate BPF filter block");
47
48 block->instrs = NULL;
49 block->last = block->next = NULL;
50
51 return block;
52}
53
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -070054void append_filter_block(struct filter_block *head,
55 struct sock_filter *instrs, size_t len)
56{
57 struct filter_block *new_last;
58
59 /*
60 * If |head| has no filter assigned yet,
61 * we don't create a new node.
62 */
63 if (head->instrs == NULL) {
64 new_last = head;
65 } else {
Jorge Lucangeli Obesd96baf42013-03-26 15:11:30 -070066 new_last = new_filter_block();
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -070067 if (head->next != NULL) {
68 head->last->next = new_last;
69 head->last = new_last;
70 } else {
71 head->last = head->next = new_last;
72 }
73 head->total_len += len;
74 }
75
76 new_last->instrs = instrs;
77 new_last->total_len = new_last->len = len;
78 new_last->last = new_last->next = NULL;
79}
80
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -070081void extend_filter_block_list(struct filter_block *list,
82 struct filter_block *another)
83{
84 if (list->last != NULL) {
85 list->last->next = another;
86 list->last = another->last;
87 } else {
88 list->next = another;
89 list->last = another->last;
90 }
91 list->total_len += another->total_len;
92}
93
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -070094void append_ret_kill(struct filter_block *head)
95{
96 struct sock_filter *filter = new_instr_buf(ONE_INSTR);
97 set_bpf_ret_kill(filter);
98 append_filter_block(head, filter, ONE_INSTR);
99}
100
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -0700101void append_ret_trap(struct filter_block *head)
102{
103 struct sock_filter *filter = new_instr_buf(ONE_INSTR);
104 set_bpf_ret_trap(filter);
105 append_filter_block(head, filter, ONE_INSTR);
106}
107
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700108void append_ret_errno(struct filter_block *head, int errno_val)
109{
110 struct sock_filter *filter = new_instr_buf(ONE_INSTR);
111 set_bpf_ret_errno(filter, errno_val);
112 append_filter_block(head, filter, ONE_INSTR);
113}
114
Jorge Lucangeli Obesc8b21e12014-06-13 14:26:16 -0700115void append_allow_syscall(struct filter_block *head, int nr)
116{
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -0700117 struct sock_filter *filter = new_instr_buf(ALLOW_SYSCALL_LEN);
118 size_t len = bpf_allow_syscall(filter, nr);
119 if (len != ALLOW_SYSCALL_LEN)
120 die("error building syscall number comparison");
121
122 append_filter_block(head, filter, len);
123}
124
125void allow_log_syscalls(struct filter_block *head)
126{
127 unsigned int i;
Kees Cook03b2af22014-12-18 17:11:13 -0800128 for (i = 0; i < log_syscalls_len; i++) {
129 warn("allowing syscall: %s", log_syscalls[i]);
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -0700130 append_allow_syscall(head, lookup_syscall(log_syscalls[i]));
Kees Cook03b2af22014-12-18 17:11:13 -0800131 }
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -0700132}
133
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700134unsigned int get_label_id(struct bpf_labels *labels, const char *label_str)
135{
136 int label_id = bpf_label_id(labels, label_str);
137 if (label_id < 0)
Jorge Lucangeli Obes224e4272012-08-02 14:31:39 -0700138 die("could not allocate BPF label string");
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700139 return label_id;
140}
141
142unsigned int group_end_lbl(struct bpf_labels *labels, int nr, int idx)
143{
144 char lbl_str[MAX_BPF_LABEL_LEN];
145 snprintf(lbl_str, MAX_BPF_LABEL_LEN, "%d_%d_end", nr, idx);
146 return get_label_id(labels, lbl_str);
147}
148
149unsigned int success_lbl(struct bpf_labels *labels, int nr)
150{
151 char lbl_str[MAX_BPF_LABEL_LEN];
152 snprintf(lbl_str, MAX_BPF_LABEL_LEN, "%d_success", nr);
153 return get_label_id(labels, lbl_str);
154}
155
Jorge Lucangeli Obes66cfc142012-11-30 15:42:52 -0800156int compile_atom(struct filter_block *head, char *atom,
157 struct bpf_labels *labels, int nr, int group_idx)
158{
159 /* Splits the atom. */
160 char *atom_ptr;
161 char *argidx_str = strtok_r(atom, " ", &atom_ptr);
162 char *operator_str = strtok_r(NULL, " ", &atom_ptr);
163 char *constant_str = strtok_r(NULL, " ", &atom_ptr);
164
165 if (argidx_str == NULL || operator_str == NULL || constant_str == NULL)
166 return -1;
167
168 int op = str_to_op(operator_str);
169 if (op < MIN_OPERATOR)
170 return -1;
171
172 if (strncmp(argidx_str, "arg", 3)) {
173 return -1;
174 }
175
176 char *argidx_ptr;
177 long int argidx = strtol(argidx_str + 3, &argidx_ptr, 10);
178 /*
179 * Checks to see if an actual argument index
180 * was parsed.
181 */
182 if (argidx_ptr == argidx_str + 3)
183 return -1;
184
185 long int c = strtol(constant_str, NULL, 0);
186 /*
187 * Looks up the label for the end of the AND statement
188 * this atom belongs to.
189 */
190 unsigned int id = group_end_lbl(labels, nr, group_idx);
191
192 /*
193 * Builds a BPF comparison between a syscall argument
194 * and a constant.
195 * The comparison lives inside an AND statement.
196 * If the comparison succeeds, we continue
197 * to the next comparison.
198 * If this comparison fails, the whole AND statement
199 * will fail, so we jump to the end of this AND statement.
200 */
201 struct sock_filter *comp_block;
202 size_t len = bpf_arg_comp(&comp_block, op, argidx, c, id);
203 if (len == 0)
204 return -1;
205
206 append_filter_block(head, comp_block, len);
207 return 0;
208}
209
Jorge Lucangeli Obesc8b21e12014-06-13 14:26:16 -0700210int compile_errno(struct filter_block *head, char *ret_errno)
211{
Jorge Lucangeli Obes66cfc142012-11-30 15:42:52 -0800212 char *errno_ptr;
213
214 /* Splits the 'return' keyword and the actual errno value. */
215 char *ret_str = strtok_r(ret_errno, " ", &errno_ptr);
216 if (strncmp(ret_str, "return", strlen("return")))
217 return -1;
218
219 char *errno_val_str = strtok_r(NULL, " ", &errno_ptr);
220
221 if (errno_val_str) {
222 char *errno_val_ptr;
223 int errno_val = strtol(
224 errno_val_str, &errno_val_ptr, 0);
225 /* Checks to see if we parsed an actual errno. */
226 if (errno_val_ptr == errno_val_str)
227 return -1;
228
229 append_ret_errno(head, errno_val);
230 } else {
231 append_ret_kill(head);
232 }
233 return 0;
234}
235
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700236struct filter_block *compile_section(int nr, const char *policy_line,
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700237 unsigned int entry_lbl_id, struct bpf_labels *labels)
238{
239 /*
240 * |policy_line| should be an expression of the form:
241 * "arg0 == 3 && arg1 == 5 || arg0 == 0x8"
242 *
243 * This is, an expression in DNF (disjunctive normal form);
244 * a disjunction ('||') of one or more conjunctions ('&&')
245 * of one or more atoms.
246 *
Jorge Lucangeli Obesd96baf42013-03-26 15:11:30 -0700247 * Atoms are of the form "arg{DNUM} {OP} {NUM}"
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700248 * where:
249 * - DNUM is a decimal number.
Jorge Lucangeli Obes66cfc142012-11-30 15:42:52 -0800250 * - OP is an operator: ==, !=, or & (flags set).
251 * - NUM is an octal, decimal, or hexadecimal number.
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700252 *
253 * When the syscall arguments make the expression true,
254 * the syscall is allowed. If not, the process is killed.
255 *
Jorge Lucangeli Obesd96baf42013-03-26 15:11:30 -0700256 * To block a syscall without killing the process,
257 * |policy_line| can be of the form:
258 * "return <errno>"
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700259 *
Jorge Lucangeli Obesd96baf42013-03-26 15:11:30 -0700260 * This "return {NUM}" policy line will block the syscall,
261 * make it return -1 and set |errno| to NUM.
262 *
263 * A regular policy line can also include a "return <errno>" clause,
264 * separated by a semicolon (';'):
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700265 * "arg0 == 3 && arg1 == 5 || arg0 == 0x8; return {NUM}"
266 *
Jorge Lucangeli Obesd96baf42013-03-26 15:11:30 -0700267 * If the syscall arguments don't make the expression true,
268 * the syscall will be blocked as above instead of killing the process.
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700269 */
270
271 size_t len = 0;
272 int group_idx = 0;
273
274 /* Checks for overly long policy lines. */
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -0700275 if (strlen(policy_line) >= MAX_POLICY_LINE_LENGTH)
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700276 return NULL;
277
Jorge Lucangeli Obesd96baf42013-03-26 15:11:30 -0700278 /* We will modify |policy_line|, so let's make a copy. */
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -0700279 char *line = strndup(policy_line, MAX_POLICY_LINE_LENGTH);
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700280 if (!line)
281 return NULL;
282
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700283 /*
Jorge Lucangeli Obesd96baf42013-03-26 15:11:30 -0700284 * We build the filter section as a collection of smaller
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700285 * "filter blocks" linked together in a singly-linked list.
286 */
Jorge Lucangeli Obesd96baf42013-03-26 15:11:30 -0700287 struct filter_block *head = new_filter_block();
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700288
289 /*
Jorge Lucangeli Obesd96baf42013-03-26 15:11:30 -0700290 * Filter sections begin with a label where the main filter
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700291 * will jump after checking the syscall number.
292 */
293 struct sock_filter *entry_label = new_instr_buf(ONE_INSTR);
294 set_bpf_lbl(entry_label, entry_lbl_id);
295 append_filter_block(head, entry_label, ONE_INSTR);
296
Jorge Lucangeli Obesd96baf42013-03-26 15:11:30 -0700297 /* Checks whether we're unconditionally blocking this syscall. */
298 if (strncmp(line, "return", strlen("return")) == 0) {
299 if (compile_errno(head, line) < 0)
300 return NULL;
301 free(line);
302 return head;
303 }
304
305 /* Splits the optional "return <errno>" part. */
306 char *line_ptr;
307 char *arg_filter = strtok_r(line, ";", &line_ptr);
308 char *ret_errno = strtok_r(NULL, ";", &line_ptr);
309
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700310 /*
311 * Splits the policy line by '||' into conjunctions and each conjunction
312 * by '&&' into atoms.
313 */
Jorge Lucangeli Obes66cfc142012-11-30 15:42:52 -0800314 char *arg_filter_str = arg_filter;
315 char *group;
316 while ((group = tokenize(&arg_filter_str, "||")) != NULL) {
317 char *group_str = group;
318 char *comp;
319 while ((comp = tokenize(&group_str, "&&")) != NULL) {
320 /* Compiles each atom into a BPF block. */
321 if (compile_atom(head, comp, labels, nr, group_idx) < 0)
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700322 return NULL;
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700323 }
324 /*
325 * If the AND statement succeeds, we're done,
326 * so jump to SUCCESS line.
327 */
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700328 unsigned int id = success_lbl(labels, nr);
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700329 struct sock_filter *group_end_block = new_instr_buf(TWO_INSTRS);
330 len = set_bpf_jump_lbl(group_end_block, id);
331 /*
332 * The end of each AND statement falls after the
333 * jump to SUCCESS.
334 */
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700335 id = group_end_lbl(labels, nr, group_idx++);
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700336 len += set_bpf_lbl(group_end_block + len, id);
337 append_filter_block(head, group_end_block, len);
338 }
339
340 /*
341 * If no AND statements succeed, we end up here,
342 * because we never jumped to SUCCESS.
343 * If we have to return an errno, do it,
344 * otherwise just kill the task.
345 */
346 if (ret_errno) {
Jorge Lucangeli Obes66cfc142012-11-30 15:42:52 -0800347 if (compile_errno(head, ret_errno) < 0)
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700348 return NULL;
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700349 } else {
350 append_ret_kill(head);
351 }
352
353 /*
354 * Every time the filter succeeds we jump to a predefined SUCCESS
355 * label. Add that label and BPF RET_ALLOW code now.
356 */
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700357 unsigned int id = success_lbl(labels, nr);
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700358 struct sock_filter *success_block = new_instr_buf(TWO_INSTRS);
359 len = set_bpf_lbl(success_block, id);
360 len += set_bpf_ret_allow(success_block + len);
361 append_filter_block(head, success_block, len);
362
363 free(line);
364 return head;
365}
366
Jorge Lucangeli Obesb0cea432013-02-04 11:55:30 -0800367int compile_filter(FILE *policy_file, struct sock_fprog *prog,
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -0700368 int log_failures)
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700369{
370 char line[MAX_LINE_LENGTH];
371 int line_count = 0;
372
373 struct bpf_labels labels;
374 labels.count = 0;
375
Jorge Lucangeli Obesb0cea432013-02-04 11:55:30 -0800376 if (!policy_file)
Jorge Lucangeli Obes6135db92012-07-27 13:37:30 -0700377 return -1;
378
Jorge Lucangeli Obesd96baf42013-03-26 15:11:30 -0700379 struct filter_block *head = new_filter_block();
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700380 struct filter_block *arg_blocks = NULL;
381
382 /* Start filter by validating arch. */
383 struct sock_filter *valid_arch = new_instr_buf(ARCH_VALIDATION_LEN);
384 size_t len = bpf_validate_arch(valid_arch);
385 append_filter_block(head, valid_arch, len);
386
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -0700387 /* Load syscall number. */
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700388 struct sock_filter *load_nr = new_instr_buf(ONE_INSTR);
389 len = bpf_load_syscall_nr(load_nr);
390 append_filter_block(head, load_nr, len);
391
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -0700392 /* If we're logging failures, allow the necessary syscalls first. */
393 if (log_failures)
394 allow_log_syscalls(head);
395
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700396 /*
397 * Loop through all the lines in the policy file.
398 * Build a jump table for the syscall number.
399 * If the policy line has an arg filter, build the arg filter
400 * as well.
401 * Chain the filter sections together and dump them into
402 * the final buffer at the end.
403 */
Jorge Lucangeli Obesb0cea432013-02-04 11:55:30 -0800404 while (fgets(line, sizeof(line), policy_file)) {
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700405 ++line_count;
Jorge Lucangeli Obesb0cea432013-02-04 11:55:30 -0800406 char *policy_line = line;
407 char *syscall_name = strsep(&policy_line, ":");
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700408 int nr = -1;
409
410 syscall_name = strip(syscall_name);
411
412 /* Allow comments and empty lines. */
413 if (*syscall_name == '#' || *syscall_name == '\0')
414 continue;
415
Jorge Lucangeli Obesb0cea432013-02-04 11:55:30 -0800416 if (!policy_line)
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700417 return -1;
418
419 nr = lookup_syscall(syscall_name);
Jorge Lucangeli Obes275b07f2012-08-28 11:50:29 -0700420 if (nr < 0) {
421 warn("compile_filter: nonexistent syscall '%s'",
422 syscall_name);
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700423 return -1;
Jorge Lucangeli Obes275b07f2012-08-28 11:50:29 -0700424 }
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700425
Jorge Lucangeli Obesb0cea432013-02-04 11:55:30 -0800426 policy_line = strip(policy_line);
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700427
428 /*
429 * For each syscall, add either a simple ALLOW,
430 * or an arg filter block.
431 */
Jorge Lucangeli Obesb0cea432013-02-04 11:55:30 -0800432 if (strcmp(policy_line, "1") == 0) {
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700433 /* Add simple ALLOW. */
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -0700434 append_allow_syscall(head, nr);
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700435 } else {
436 /*
437 * Create and jump to the label that will hold
438 * the arg filter block.
439 */
440 unsigned int id = bpf_label_id(&labels, syscall_name);
441 struct sock_filter *nr_comp =
442 new_instr_buf(ALLOW_SYSCALL_LEN);
443 bpf_allow_syscall_args(nr_comp, nr, id);
444 append_filter_block(head, nr_comp, ALLOW_SYSCALL_LEN);
445
446 /* Build the arg filter block. */
447 struct filter_block *block =
Jorge Lucangeli Obesb0cea432013-02-04 11:55:30 -0800448 compile_section(nr, policy_line, id, &labels);
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700449
450 if (!block)
451 return -1;
452
453 if (arg_blocks) {
454 extend_filter_block_list(arg_blocks, block);
455 } else {
456 arg_blocks = block;
457 }
458 }
459 }
460
Jorge Lucangeli Obesbda833c2012-07-31 16:25:56 -0700461 /*
462 * If none of the syscalls match, either fall back to KILL,
463 * or return TRAP.
464 */
465 if (!log_failures)
466 append_ret_kill(head);
467 else
468 append_ret_trap(head);
Jorge Lucangeli Obesd4467262012-03-23 16:19:59 -0700469
470 /* Allocate the final buffer, now that we know its size. */
471 size_t final_filter_len = head->total_len +
472 (arg_blocks? arg_blocks->total_len : 0);
473 if (final_filter_len > BPF_MAXINSNS)
474 return -1;
475
476 struct sock_filter *final_filter =
477 calloc(final_filter_len, sizeof(struct sock_filter));
478
479 if (flatten_block_list(head, final_filter, 0, final_filter_len) < 0)
480 return -1;
481
482 if (flatten_block_list(arg_blocks, final_filter,
483 head->total_len, final_filter_len) < 0)
484 return -1;
485
486 free_block_list(head);
487 free_block_list(arg_blocks);
488
489 bpf_resolve_jumps(&labels, final_filter, final_filter_len);
490
491 free_label_strings(&labels);
492
493 prog->filter = final_filter;
494 prog->len = final_filter_len;
495 return 0;
496}
497
498int flatten_block_list(struct filter_block *head, struct sock_filter *filter,
499 size_t index, size_t cap)
500{
501 size_t _index = index;
502
503 struct filter_block *curr;
504 size_t i;
505
506 for (curr = head; curr; curr = curr->next) {
507 for (i = 0; i < curr->len; i++) {
508 if (_index >= cap)
509 return -1;
510 filter[_index++] = curr->instrs[i];
511 }
512 }
513 return 0;
514}
515
Jorge Lucangeli Obesfc8ab532012-03-20 10:14:31 -0700516void free_block_list(struct filter_block *head)
517{
518 struct filter_block *current, *prev;
519
520 current = head;
521 while (current) {
522 free(current->instrs);
523 prev = current;
524 current = current->next;
525 free(prev);
526 }
527}