From 53dcfa3ff0eadd09adc0925e676f8ba320a1ca30 Mon Sep 17 00:00:00 2001 From: Paul Moore Date: Fri, 18 Oct 2013 16:17:59 -0400 Subject: all: assorted formatting fixes Since we have a tool to verify the source code style/formatting, let's put it to good use. Signed-off-by: Paul Moore --- include/seccomp.h.in | 2 +- src/arch-arm-syscalls.c | 3 +- src/arch-x86-syscalls.c | 3 +- src/arch-x86_64-syscalls.c | 3 +- src/db.c | 112 +++++++------ src/db.h | 8 +- src/gen_bpf.c | 61 +++---- src/gen_pfc.c | 28 ++-- tests/11-basic-basic_errors.c | 10 +- tests/13-basic-attrs.c | 2 +- tests/24-live-arg_allow.c | 2 +- tests/util.c | 2 +- tools/scmp_arch_detect.c | 2 +- tools/scmp_bpf_disasm.c | 370 +++++++++++++++++++++--------------------- tools/scmp_bpf_sim.c | 7 +- tools/scmp_sys_resolver.c | 2 +- 16 files changed, 313 insertions(+), 304 deletions(-) diff --git a/include/seccomp.h.in b/include/seccomp.h.in index 7897cbf..e150fbd 100644 --- a/include/seccomp.h.in +++ b/include/seccomp.h.in @@ -46,7 +46,7 @@ extern "C" { /** * Filter context/handle */ -typedef void * scmp_filter_ctx; +typedef void *scmp_filter_ctx; /** * Filter attributes diff --git a/src/arch-arm-syscalls.c b/src/arch-arm-syscalls.c index 8083486..66db33b 100644 --- a/src/arch-arm-syscalls.c +++ b/src/arch-arm-syscalls.c @@ -37,8 +37,7 @@ #endif /* NOTE: based on Linux 3.8.0-rc5 */ -const struct arch_syscall_def arm_syscall_table[] = \ -{ +const struct arch_syscall_def arm_syscall_table[] = { \ /* NOTE: arm_sync_file_range() and sync_file_range2() share values */ { "accept", (__NR_SYSCALL_BASE + 285) }, { "accept4", (__NR_SYSCALL_BASE + 366) }, diff --git a/src/arch-x86-syscalls.c b/src/arch-x86-syscalls.c index c44eb06..79f1b91 100644 --- a/src/arch-x86-syscalls.c +++ b/src/arch-x86-syscalls.c @@ -27,8 +27,7 @@ #include "arch-x86.h" /* NOTE: based on Linux 3.4.7 */ -static const struct arch_syscall_def x86_syscall_table[] = \ -{ +static const struct arch_syscall_def x86_syscall_table[] = { \ { "accept", __PNR_accept }, { "accept4", __PNR_accept4 }, { "access", 33 }, diff --git a/src/arch-x86_64-syscalls.c b/src/arch-x86_64-syscalls.c index 2f5253a..af095b8 100644 --- a/src/arch-x86_64-syscalls.c +++ b/src/arch-x86_64-syscalls.c @@ -27,8 +27,7 @@ #include "arch-x86_64.h" /* NOTE: based on Linux 3.4.7 */ -const struct arch_syscall_def x86_64_syscall_table[] = \ -{ +const struct arch_syscall_def x86_64_syscall_table[] = { \ { "accept", 43 }, { "accept4", 288 }, { "access", 21 }, diff --git a/src/db.c b/src/db.c index cf090d9..345a654 100644 --- a/src/db.c +++ b/src/db.c @@ -200,9 +200,9 @@ static int _db_tree_act_check(struct db_arg_chain_tree *tree, uint32_t action) * */ static int _db_tree_sub_prune(struct db_arg_chain_tree **prev, - struct db_arg_chain_tree *existing, - struct db_arg_chain_tree *new, - struct db_prune_state *state) + struct db_arg_chain_tree *existing, + struct db_arg_chain_tree *new, + struct db_prune_state *state) { int rc = 0; int rc_tmp; @@ -292,10 +292,10 @@ static int _db_tree_sub_prune(struct db_arg_chain_tree **prev, if (ec_iter->nxt_t) { rc_tmp = _db_tree_sub_prune((prev ? - &ec_iter : NULL), - ec_iter->nxt_t, - c_iter, - &state_new); + &ec_iter : NULL), + ec_iter->nxt_t, + c_iter, + &state_new); rc += (rc_tmp > 0 ? rc_tmp : 0); } if (ec_iter->nxt_f) { @@ -542,6 +542,8 @@ int db_col_arch_exist(struct db_filter_col *col, uint32_t arch_token) int db_col_attr_get(const struct db_filter_col *col, enum scmp_filter_attr attr, uint32_t *value) { + int rc = 0; + switch (attr) { case SCMP_FLTATR_ACT_DEFAULT: *value = col->attr.act_default; @@ -553,11 +555,11 @@ int db_col_attr_get(const struct db_filter_col *col, *value = col->attr.nnp_enable; break; default: - return -EEXIST; + rc = -EEXIST; break; } - return 0; + return rc; } /** @@ -573,6 +575,8 @@ int db_col_attr_get(const struct db_filter_col *col, int db_col_attr_set(struct db_filter_col *col, enum scmp_filter_attr attr, uint32_t value) { + int rc = 0; + switch (attr) { case SCMP_FLTATR_ACT_DEFAULT: /* read only */ @@ -588,11 +592,11 @@ int db_col_attr_set(struct db_filter_col *col, col->attr.nnp_enable = (value ? 1 : 0); break; default: - return -EEXIST; + rc = -EEXIST; break; } - return 0; + return rc; } /** @@ -876,30 +880,30 @@ static struct db_sys_list *_db_rule_gen_64(const struct arch_def *arch, c_iter_lo->arg_offset = arch_arg_offset_lo(arch, c_iter_lo->arg); switch (chain[iter].op) { - case SCMP_CMP_GT: - c_iter_hi->op = SCMP_CMP_GE; - c_iter_lo->op = SCMP_CMP_GT; - tf_flag = true; - break; - case SCMP_CMP_NE: - c_iter_hi->op = SCMP_CMP_EQ; - c_iter_lo->op = SCMP_CMP_EQ; - tf_flag = false; - break; - case SCMP_CMP_LT: - c_iter_hi->op = SCMP_CMP_GE; - c_iter_lo->op = SCMP_CMP_GE; - tf_flag = false; - break; - case SCMP_CMP_LE: - c_iter_hi->op = SCMP_CMP_GE; - c_iter_lo->op = SCMP_CMP_GT; - tf_flag = false; - break; - default: - c_iter_hi->op = chain[iter].op; - c_iter_lo->op = chain[iter].op; - tf_flag = true; + case SCMP_CMP_GT: + c_iter_hi->op = SCMP_CMP_GE; + c_iter_lo->op = SCMP_CMP_GT; + tf_flag = true; + break; + case SCMP_CMP_NE: + c_iter_hi->op = SCMP_CMP_EQ; + c_iter_lo->op = SCMP_CMP_EQ; + tf_flag = false; + break; + case SCMP_CMP_LT: + c_iter_hi->op = SCMP_CMP_GE; + c_iter_lo->op = SCMP_CMP_GE; + tf_flag = false; + break; + case SCMP_CMP_LE: + c_iter_hi->op = SCMP_CMP_GE; + c_iter_lo->op = SCMP_CMP_GT; + tf_flag = false; + break; + default: + c_iter_hi->op = chain[iter].op; + c_iter_lo->op = chain[iter].op; + tf_flag = true; } c_iter_hi->mask = D64_HI(chain[iter].mask); c_iter_lo->mask = D64_LO(chain[iter].mask); @@ -996,20 +1000,20 @@ static struct db_sys_list *_db_rule_gen_32(const struct arch_def *arch, /* rewrite the op to reduce the op/datum combos */ switch (c_iter->op) { - case SCMP_CMP_NE: - c_iter->op = SCMP_CMP_EQ; - tf_flag = false; - break; - case SCMP_CMP_LT: - c_iter->op = SCMP_CMP_GE; - tf_flag = false; - break; - case SCMP_CMP_LE: - c_iter->op = SCMP_CMP_GT; - tf_flag = false; - break; - default: - tf_flag = true; + case SCMP_CMP_NE: + c_iter->op = SCMP_CMP_EQ; + tf_flag = false; + break; + case SCMP_CMP_LT: + c_iter->op = SCMP_CMP_GE; + tf_flag = false; + break; + case SCMP_CMP_LE: + c_iter->op = SCMP_CMP_GT; + tf_flag = false; + break; + default: + tf_flag = true; } /* fixup the mask/datum */ @@ -1173,8 +1177,8 @@ add_reset: if (ec_iter->act_t_flg == ec_iter->act_f_flg && ec_iter->act_t == ec_iter->act_f) { n_cnt = _db_tree_remove( - &(s_iter->chains), - ec_iter); + &(s_iter->chains), + ec_iter); s_iter->node_cnt -= n_cnt; goto add_free_ok; } @@ -1217,7 +1221,8 @@ add_reset: /* add a new branch */ c_prev = c_iter; ec_iter->nxt_t = c_iter->nxt_t; - s_iter->node_cnt += (s_new->node_cnt-1); + s_iter->node_cnt += + (s_new->node_cnt - 1); goto add_free_match; } } else if (c_iter->nxt_f != NULL) { @@ -1236,7 +1241,8 @@ add_reset: /* add a new branch */ c_prev = c_iter; ec_iter->nxt_f = c_iter->nxt_f; - s_iter->node_cnt += (s_new->node_cnt-1); + s_iter->node_cnt += + (s_new->node_cnt - 1); goto add_free_match; } } else diff --git a/src/db.h b/src/db.h index d0d9ff1..c0472a5 100644 --- a/src/db.h +++ b/src/db.h @@ -70,16 +70,16 @@ struct db_arg_chain_tree { #define ARG_MASK_MAX ((uint32_t)-1) #define db_chain_lt(x,y) \ (((x)->arg < (y)->arg) || \ - (((x)->arg == (y)->arg) && (((x)->op < (y)->op) || \ - (((x)->mask & (y)->mask) == (y)->mask)))) + (((x)->arg == (y)->arg) && \ + (((x)->op < (y)->op) || (((x)->mask & (y)->mask) == (y)->mask)))) #define db_chain_eq(x,y) \ (((x)->arg == (y)->arg) && \ ((x)->op == (y)->op) && ((x)->datum == (y)->datum) && \ ((x)->mask == (y)->mask)) #define db_chain_gt(x,y) \ (((x)->arg > (y)->arg) || \ - (((x)->arg == (y)->arg) && (((x)->op > (y)->op) || \ - (((x)->mask & (y)->mask) != (y)->mask)))) + (((x)->arg == (y)->arg) && \ + (((x)->op > (y)->op) || (((x)->mask & (y)->mask) != (y)->mask)))) #define db_chain_action(x) \ (((x)->act_t_flg) || ((x)->act_f_flg)) #define db_chain_zombie(x) \ diff --git a/src/gen_bpf.c b/src/gen_bpf.c index e11e892..8c96f87 100644 --- a/src/gen_bpf.c +++ b/src/gen_bpf.c @@ -701,8 +701,8 @@ static struct bpf_blk *_gen_bpf_node(struct bpf_state *state, /* reload the accumulator */ a_state->offset = acc_offset; a_state->mask = ARG_MASK_MAX; - _BPF_INSTR(instr, BPF_LD+BPF_ABS, - _BPF_JMP_NO, _BPF_JMP_NO, _BPF_K(acc_offset)); + _BPF_INSTR(instr, BPF_LD + BPF_ABS, + _BPF_JMP_NO, _BPF_JMP_NO, _BPF_K(acc_offset)); blk = _blk_append(state, blk, &instr); if (blk == NULL) goto node_failure; @@ -710,8 +710,8 @@ static struct bpf_blk *_gen_bpf_node(struct bpf_state *state, if (acc_mask != a_state->mask) { /* apply the bitmask */ a_state->mask = acc_mask; - _BPF_INSTR(instr, BPF_ALU+BPF_AND, - _BPF_JMP_NO, _BPF_JMP_NO, _BPF_K(acc_mask)); + _BPF_INSTR(instr, BPF_ALU + BPF_AND, + _BPF_JMP_NO, _BPF_JMP_NO, _BPF_K(acc_mask)); blk = _blk_append(state, blk, &instr); if (blk == NULL) goto node_failure; @@ -721,15 +721,15 @@ static struct bpf_blk *_gen_bpf_node(struct bpf_state *state, switch (node->op) { case SCMP_CMP_MASKED_EQ: case SCMP_CMP_EQ: - _BPF_INSTR(instr, BPF_JMP+BPF_JEQ, + _BPF_INSTR(instr, BPF_JMP + BPF_JEQ, _BPF_JMP_NO, _BPF_JMP_NO, _BPF_K(node->datum)); - break; + break; case SCMP_CMP_GT: - _BPF_INSTR(instr, BPF_JMP+BPF_JGT, + _BPF_INSTR(instr, BPF_JMP + BPF_JGT, _BPF_JMP_NO, _BPF_JMP_NO, _BPF_K(node->datum)); break; case SCMP_CMP_GE: - _BPF_INSTR(instr, BPF_JMP+BPF_JGE, + _BPF_INSTR(instr, BPF_JMP + BPF_JGE, _BPF_JMP_NO, _BPF_JMP_NO, _BPF_K(node->datum)); break; case SCMP_CMP_NE: @@ -933,7 +933,8 @@ static struct bpf_blk *_gen_bpf_chain(struct bpf_state *state, if (b_next == NULL) i_iter->jt = *nxt_jump; else - i_iter->jt=_BPF_JMP_BLK(b_next); + i_iter->jt = + _BPF_JMP_BLK(b_next); } if (i_iter->jf.type == TGT_NXT) { if (i_iter->jf.tgt.nxt != 0) @@ -941,7 +942,8 @@ static struct bpf_blk *_gen_bpf_chain(struct bpf_state *state, if (b_next == NULL) i_iter->jf = *nxt_jump; else - i_iter->jf=_BPF_JMP_BLK(b_next); + i_iter->jf = + _BPF_JMP_BLK(b_next); } } b_iter = b_next; @@ -1019,8 +1021,8 @@ static struct bpf_blk *_gen_bpf_syscall(struct bpf_state *state, /* setup the accumulator state */ if (acc_reset) { - _BPF_INSTR(instr, BPF_LD+BPF_ABS, _BPF_JMP_NO, _BPF_JMP_NO, - _BPF_SYSCALL); + _BPF_INSTR(instr, BPF_LD + BPF_ABS, _BPF_JMP_NO, _BPF_JMP_NO, + _BPF_SYSCALL); blk_s = _blk_append(state, NULL, &instr); if (blk_s == NULL) return NULL; @@ -1038,7 +1040,7 @@ static struct bpf_blk *_gen_bpf_syscall(struct bpf_state *state, return NULL; /* syscall check */ - _BPF_INSTR(instr, BPF_JMP+BPF_JEQ, + _BPF_INSTR(instr, BPF_JMP + BPF_JEQ, _BPF_JMP_HSH(blk_c->hash), _BPF_JMP_HSH(nxt_hash), _BPF_K(sys->num)); blk_s = _blk_append(state, blk_s, &instr); @@ -1117,7 +1119,7 @@ static struct bpf_blk *_gen_bpf_arch(struct bpf_state *state, if (s_head != NULL) { s_iter_b = s_head; while ((s_iter_b->pri_nxt != NULL) && - (s_iter->priority <= s_iter_b->priority)) + (s_iter->priority <= s_iter_b->priority)) s_iter_b = s_iter_b->pri_nxt; if (s_iter->priority > s_iter_b->priority) { @@ -1127,8 +1129,10 @@ static struct bpf_blk *_gen_bpf_arch(struct bpf_state *state, s_head->pri_prv = s_iter; s_head = s_iter; } else { - s_iter->pri_prv->pri_nxt=s_iter; - s_iter->pri_nxt->pri_prv=s_iter; + s_iter->pri_prv->pri_nxt = + s_iter; + s_iter->pri_nxt->pri_prv = + s_iter; } } else { s_iter->pri_prv = s_tail; @@ -1160,7 +1164,8 @@ static struct bpf_blk *_gen_bpf_arch(struct bpf_state *state, b_new = _gen_bpf_syscall(state, s_iter, (b_head == NULL ? state->def_hsh : b_head->hash), - (s_iter == s_head ? acc_reset:false)); + (s_iter == s_head ? + acc_reset : false)); if (b_new == NULL) goto arch_failure; @@ -1183,25 +1188,25 @@ static struct bpf_blk *_gen_bpf_arch(struct bpf_state *state, /* additional ABI filtering */ if ((db->arch->token == SCMP_ARCH_X86_64 || db->arch->token == SCMP_ARCH_X32) && (db_secondary == NULL)) { - _BPF_INSTR(instr, BPF_LD+BPF_ABS, _BPF_JMP_NO, _BPF_JMP_NO, + _BPF_INSTR(instr, BPF_LD + BPF_ABS, _BPF_JMP_NO, _BPF_JMP_NO, _BPF_SYSCALL); b_new = _blk_append(state, NULL, &instr); if (b_new == NULL) goto arch_failure; if (db->arch->token == SCMP_ARCH_X86_64) { /* filter out x32 */ - _BPF_INSTR(instr, BPF_JMP+BPF_JGE, - _BPF_JMP_NXT(blk_cnt++), _BPF_JMP_NO, - _BPF_K(X32_SYSCALL_BIT)); + _BPF_INSTR(instr, BPF_JMP + BPF_JGE, + _BPF_JMP_NXT(blk_cnt++), _BPF_JMP_NO, + _BPF_K(X32_SYSCALL_BIT)); if (b_head != NULL) instr.jf = _BPF_JMP_HSH(b_head->hash); else instr.jf = _BPF_JMP_HSH(state->def_hsh); } else if (db->arch->token == SCMP_ARCH_X32) { /* filter out x86_64 */ - _BPF_INSTR(instr, BPF_JMP+BPF_JGE, - _BPF_JMP_NO, _BPF_JMP_NXT(blk_cnt++), - _BPF_K(X32_SYSCALL_BIT)); + _BPF_INSTR(instr, BPF_JMP + BPF_JGE, + _BPF_JMP_NO, _BPF_JMP_NXT(blk_cnt++), + _BPF_K(X32_SYSCALL_BIT)); if (b_head != NULL) instr.jt = _BPF_JMP_HSH(b_head->hash); else @@ -1222,7 +1227,7 @@ static struct bpf_blk *_gen_bpf_arch(struct bpf_state *state, } /* do the ABI/architecture check */ - _BPF_INSTR(instr, BPF_JMP+BPF_JEQ, + _BPF_INSTR(instr, BPF_JMP + BPF_JEQ, _BPF_JMP_NO, _BPF_JMP_NXT(blk_cnt++), _BPF_K(db->arch->token_bpf)); if (b_head != NULL) @@ -1411,7 +1416,7 @@ static int _gen_bpf_build_jmp(struct bpf_state *state, return -EFAULT; /* we need to insert a long jump - create one */ - _BPF_INSTR(instr, BPF_JMP+BPF_JA, + _BPF_INSTR(instr, BPF_JMP + BPF_JA, _BPF_JMP_NO, _BPF_JMP_NO, _BPF_JMP_HSH(tgt_hash)); b_new = _blk_append(state, NULL, &instr); if (b_new == NULL) @@ -1478,7 +1483,7 @@ static int _gen_bpf_build_bpf(struct bpf_state *state, state->def_hsh = b_default->hash; /* load the architecture token/number */ - _BPF_INSTR(instr, BPF_LD+BPF_ABS, _BPF_JMP_NO, _BPF_JMP_NO, + _BPF_INSTR(instr, BPF_LD + BPF_ABS, _BPF_JMP_NO, _BPF_JMP_NO, _BPF_K(offsetof(struct seccomp_data, arch))); b_head = _blk_append(state, NULL, &instr); if (b_head == NULL) @@ -1575,7 +1580,7 @@ static int _gen_bpf_build_bpf(struct bpf_state *state, b_jmp->next = b_iter->next; b_iter->next = b_jmp; if (b_jmp->next) - b_jmp->next->prev=b_jmp; + b_jmp->next->prev = b_jmp; } } if (b_jmp != NULL) { diff --git a/src/gen_pfc.c b/src/gen_pfc.c index 75c96d6..954feab 100644 --- a/src/gen_pfc.c +++ b/src/gen_pfc.c @@ -151,20 +151,20 @@ static void _gen_pfc_chain(const struct arch_def *arch, fprintf(fds, "if ("); _pfc_arg(fds, arch, c_iter); switch (c_iter->op) { - case SCMP_CMP_EQ: - fprintf(fds, " == "); - break; - case SCMP_CMP_GE: - fprintf(fds, " >= "); - break; - case SCMP_CMP_GT: - fprintf(fds, " > "); - break; - case SCMP_CMP_MASKED_EQ: - fprintf(fds, " & 0x%.8x == ", c_iter->mask); - break; - default: - fprintf(fds, " ??? "); + case SCMP_CMP_EQ: + fprintf(fds, " == "); + break; + case SCMP_CMP_GE: + fprintf(fds, " >= "); + break; + case SCMP_CMP_GT: + fprintf(fds, " > "); + break; + case SCMP_CMP_MASKED_EQ: + fprintf(fds, " & 0x%.8x == ", c_iter->mask); + break; + default: + fprintf(fds, " ??? "); } fprintf(fds, "%u)\n", c_iter->datum); diff --git a/tests/11-basic-basic_errors.c b/tests/11-basic-basic_errors.c index c328577..c695e8b 100644 --- a/tests/11-basic-basic_errors.c +++ b/tests/11-basic-basic_errors.c @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) scmp_filter_ctx ctx; /* seccomp_init errors */ - ctx = seccomp_init(SCMP_ACT_ALLOW+1); + ctx = seccomp_init(SCMP_ACT_ALLOW + 1); if (ctx != NULL) return -1; @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) ctx = NULL; /* seccomp_reset error */ - rc = seccomp_reset(ctx, SCMP_ACT_KILL+1); + rc = seccomp_reset(ctx, SCMP_ACT_KILL + 1); if (rc != -EINVAL) return -1; rc = seccomp_reset(ctx, SCMP_ACT_KILL); @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0); if (rc != -EPERM) return -1; - rc = seccomp_rule_add(ctx, SCMP_ACT_KILL-1, SCMP_SYS(read), 0); + rc = seccomp_rule_add(ctx, SCMP_ACT_KILL - 1, SCMP_SYS(read), 0); if (rc != -EINVAL) return -1; rc = seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(read), 6); @@ -141,7 +141,7 @@ int main(int argc, char *argv[]) if (ctx == NULL) return -1; else { - rc = seccomp_export_pfc(ctx, sysconf(_SC_OPEN_MAX)-1); + rc = seccomp_export_pfc(ctx, sysconf(_SC_OPEN_MAX) - 1); if (rc != EBADF) return -1; } @@ -157,7 +157,7 @@ int main(int argc, char *argv[]) if (ctx == NULL) return -1; else { - rc = seccomp_export_bpf(ctx, sysconf(_SC_OPEN_MAX)-1); + rc = seccomp_export_bpf(ctx, sysconf(_SC_OPEN_MAX) - 1); if (rc != -EBADF) return -1; } diff --git a/tests/13-basic-attrs.c b/tests/13-basic-attrs.c index 46518a5..99e8dcb 100644 --- a/tests/13-basic-attrs.c +++ b/tests/13-basic-attrs.c @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) { int rc; - uint32_t val = (uint32_t)-1; + uint32_t val = (uint32_t)(-1); scmp_filter_ctx ctx; ctx = seccomp_init(SCMP_ACT_ALLOW); diff --git a/tests/24-live-arg_allow.c b/tests/24-live-arg_allow.c index fd6e289..e071dda 100644 --- a/tests/24-live-arg_allow.c +++ b/tests/24-live-arg_allow.c @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) if (rc != 0) goto out; - fd = open("/dev/null", O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR); + fd = open("/dev/null", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (fd < 0) { rc = errno; goto out; diff --git a/tests/util.c b/tests/util.c index 02b0043..9c069d6 100644 --- a/tests/util.c +++ b/tests/util.c @@ -194,7 +194,7 @@ int util_file_write(const char *path) const char buf[] = "testing"; ssize_t buf_len = strlen(buf); - fd = open(path, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR); + fd = open(path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (fd < 0) return errno; if (write(fd, buf, buf_len) < buf_len) { diff --git a/tools/scmp_arch_detect.c b/tools/scmp_arch_detect.c index 0aca5a8..e90f92b 100644 --- a/tools/scmp_arch_detect.c +++ b/tools/scmp_arch_detect.c @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) uint32_t arch; /* parse the command line */ - while ((opt = getopt(argc, argv, "ht"))> 0) { + while ((opt = getopt(argc, argv, "ht")) > 0) { switch (opt) { case 't': token = 1; diff --git a/tools/scmp_bpf_disasm.c b/tools/scmp_bpf_disasm.c index 5b63fe8..8474eb1 100644 --- a/tools/scmp_bpf_disasm.c +++ b/tools/scmp_bpf_disasm.c @@ -44,125 +44,125 @@ static void bpf_decode_op(const bpf_instr_raw *bpf) { switch (bpf->code) { - case BPF_LD+BPF_W+BPF_IMM: - case BPF_LD+BPF_W+BPF_ABS: - case BPF_LD+BPF_W+BPF_IND: - case BPF_LD+BPF_W+BPF_MEM: - case BPF_LD+BPF_W+BPF_LEN: - case BPF_LD+BPF_W+BPF_MSH: - printf(_OP_FMT, "ld"); - break; - case BPF_LD+BPF_H+BPF_IMM: - case BPF_LD+BPF_H+BPF_ABS: - case BPF_LD+BPF_H+BPF_IND: - case BPF_LD+BPF_H+BPF_MEM: - case BPF_LD+BPF_H+BPF_LEN: - case BPF_LD+BPF_H+BPF_MSH: - printf(_OP_FMT, "ldh"); - break; - case BPF_LD+BPF_B+BPF_IMM: - case BPF_LD+BPF_B+BPF_ABS: - case BPF_LD+BPF_B+BPF_IND: - case BPF_LD+BPF_B+BPF_MEM: - case BPF_LD+BPF_B+BPF_LEN: - case BPF_LD+BPF_B+BPF_MSH: - printf(_OP_FMT, "ldb"); - break; - case BPF_LDX+BPF_W+BPF_IMM: - case BPF_LDX+BPF_W+BPF_ABS: - case BPF_LDX+BPF_W+BPF_IND: - case BPF_LDX+BPF_W+BPF_MEM: - case BPF_LDX+BPF_W+BPF_LEN: - case BPF_LDX+BPF_W+BPF_MSH: - case BPF_LDX+BPF_H+BPF_IMM: - case BPF_LDX+BPF_H+BPF_ABS: - case BPF_LDX+BPF_H+BPF_IND: - case BPF_LDX+BPF_H+BPF_MEM: - case BPF_LDX+BPF_H+BPF_LEN: - case BPF_LDX+BPF_H+BPF_MSH: - case BPF_LDX+BPF_B+BPF_IMM: - case BPF_LDX+BPF_B+BPF_ABS: - case BPF_LDX+BPF_B+BPF_IND: - case BPF_LDX+BPF_B+BPF_MEM: - case BPF_LDX+BPF_B+BPF_LEN: - case BPF_LDX+BPF_B+BPF_MSH: - printf(_OP_FMT, "ldx"); - break; - case BPF_ST: - printf(_OP_FMT, "st"); - break; - case BPF_STX: - printf(_OP_FMT, "stx"); - break; - case BPF_ALU+BPF_ADD+BPF_K: - case BPF_ALU+BPF_ADD+BPF_X: - printf(_OP_FMT, "add"); - break; - case BPF_ALU+BPF_SUB+BPF_K: - case BPF_ALU+BPF_SUB+BPF_X: - printf(_OP_FMT, "sub"); - break; - case BPF_ALU+BPF_MUL+BPF_K: - case BPF_ALU+BPF_MUL+BPF_X: - printf(_OP_FMT, "mul"); - break; - case BPF_ALU+BPF_DIV+BPF_K: - case BPF_ALU+BPF_DIV+BPF_X: - printf(_OP_FMT, "div"); - break; - case BPF_ALU+BPF_OR+BPF_K: - case BPF_ALU+BPF_OR+BPF_X: - printf(_OP_FMT, "or"); - break; - case BPF_ALU+BPF_AND+BPF_K: - case BPF_ALU+BPF_AND+BPF_X: - printf(_OP_FMT, "and"); - break; - case BPF_ALU+BPF_LSH+BPF_K: - case BPF_ALU+BPF_LSH+BPF_X: - printf(_OP_FMT, "lsh"); - break; - case BPF_ALU+BPF_RSH+BPF_K: - case BPF_ALU+BPF_RSH+BPF_X: - printf(_OP_FMT, "rsh"); - break; - case BPF_ALU+BPF_NEG+BPF_K: - case BPF_ALU+BPF_NEG+BPF_X: - printf(_OP_FMT, "neg"); - break; - case BPF_JMP+BPF_JA+BPF_K: - case BPF_JMP+BPF_JA+BPF_X: - printf(_OP_FMT, "jmp"); - break; - case BPF_JMP+BPF_JEQ+BPF_K: - case BPF_JMP+BPF_JEQ+BPF_X: - printf(_OP_FMT, "jeq"); - break; - case BPF_JMP+BPF_JGT+BPF_K: - case BPF_JMP+BPF_JGT+BPF_X: - printf(_OP_FMT, "jgt"); - break; - case BPF_JMP+BPF_JGE+BPF_K: - case BPF_JMP+BPF_JGE+BPF_X: - printf(_OP_FMT, "jge"); - break; - case BPF_JMP+BPF_JSET+BPF_K: - case BPF_JMP+BPF_JSET+BPF_X: - printf(_OP_FMT, "jset"); - break; - case BPF_RET+BPF_K: - case BPF_RET+BPF_X: - case BPF_RET+BPF_A: - printf(_OP_FMT, "ret"); - break; - case BPF_MISC+BPF_TAX: - printf(_OP_FMT, "tax"); - break; - case BPF_MISC+BPF_TXA: - printf(_OP_FMT, "txa"); - break; - default: - printf(_OP_FMT, "???"); + case BPF_LD+BPF_W+BPF_IMM: + case BPF_LD+BPF_W+BPF_ABS: + case BPF_LD+BPF_W+BPF_IND: + case BPF_LD+BPF_W+BPF_MEM: + case BPF_LD+BPF_W+BPF_LEN: + case BPF_LD+BPF_W+BPF_MSH: + printf(_OP_FMT, "ld"); + break; + case BPF_LD+BPF_H+BPF_IMM: + case BPF_LD+BPF_H+BPF_ABS: + case BPF_LD+BPF_H+BPF_IND: + case BPF_LD+BPF_H+BPF_MEM: + case BPF_LD+BPF_H+BPF_LEN: + case BPF_LD+BPF_H+BPF_MSH: + printf(_OP_FMT, "ldh"); + break; + case BPF_LD+BPF_B+BPF_IMM: + case BPF_LD+BPF_B+BPF_ABS: + case BPF_LD+BPF_B+BPF_IND: + case BPF_LD+BPF_B+BPF_MEM: + case BPF_LD+BPF_B+BPF_LEN: + case BPF_LD+BPF_B+BPF_MSH: + printf(_OP_FMT, "ldb"); + break; + case BPF_LDX+BPF_W+BPF_IMM: + case BPF_LDX+BPF_W+BPF_ABS: + case BPF_LDX+BPF_W+BPF_IND: + case BPF_LDX+BPF_W+BPF_MEM: + case BPF_LDX+BPF_W+BPF_LEN: + case BPF_LDX+BPF_W+BPF_MSH: + case BPF_LDX+BPF_H+BPF_IMM: + case BPF_LDX+BPF_H+BPF_ABS: + case BPF_LDX+BPF_H+BPF_IND: + case BPF_LDX+BPF_H+BPF_MEM: + case BPF_LDX+BPF_H+BPF_LEN: + case BPF_LDX+BPF_H+BPF_MSH: + case BPF_LDX+BPF_B+BPF_IMM: + case BPF_LDX+BPF_B+BPF_ABS: + case BPF_LDX+BPF_B+BPF_IND: + case BPF_LDX+BPF_B+BPF_MEM: + case BPF_LDX+BPF_B+BPF_LEN: + case BPF_LDX+BPF_B+BPF_MSH: + printf(_OP_FMT, "ldx"); + break; + case BPF_ST: + printf(_OP_FMT, "st"); + break; + case BPF_STX: + printf(_OP_FMT, "stx"); + break; + case BPF_ALU+BPF_ADD+BPF_K: + case BPF_ALU+BPF_ADD+BPF_X: + printf(_OP_FMT, "add"); + break; + case BPF_ALU+BPF_SUB+BPF_K: + case BPF_ALU+BPF_SUB+BPF_X: + printf(_OP_FMT, "sub"); + break; + case BPF_ALU+BPF_MUL+BPF_K: + case BPF_ALU+BPF_MUL+BPF_X: + printf(_OP_FMT, "mul"); + break; + case BPF_ALU+BPF_DIV+BPF_K: + case BPF_ALU+BPF_DIV+BPF_X: + printf(_OP_FMT, "div"); + break; + case BPF_ALU+BPF_OR+BPF_K: + case BPF_ALU+BPF_OR+BPF_X: + printf(_OP_FMT, "or"); + break; + case BPF_ALU+BPF_AND+BPF_K: + case BPF_ALU+BPF_AND+BPF_X: + printf(_OP_FMT, "and"); + break; + case BPF_ALU+BPF_LSH+BPF_K: + case BPF_ALU+BPF_LSH+BPF_X: + printf(_OP_FMT, "lsh"); + break; + case BPF_ALU+BPF_RSH+BPF_K: + case BPF_ALU+BPF_RSH+BPF_X: + printf(_OP_FMT, "rsh"); + break; + case BPF_ALU+BPF_NEG+BPF_K: + case BPF_ALU+BPF_NEG+BPF_X: + printf(_OP_FMT, "neg"); + break; + case BPF_JMP+BPF_JA+BPF_K: + case BPF_JMP+BPF_JA+BPF_X: + printf(_OP_FMT, "jmp"); + break; + case BPF_JMP+BPF_JEQ+BPF_K: + case BPF_JMP+BPF_JEQ+BPF_X: + printf(_OP_FMT, "jeq"); + break; + case BPF_JMP+BPF_JGT+BPF_K: + case BPF_JMP+BPF_JGT+BPF_X: + printf(_OP_FMT, "jgt"); + break; + case BPF_JMP+BPF_JGE+BPF_K: + case BPF_JMP+BPF_JGE+BPF_X: + printf(_OP_FMT, "jge"); + break; + case BPF_JMP+BPF_JSET+BPF_K: + case BPF_JMP+BPF_JSET+BPF_X: + printf(_OP_FMT, "jset"); + break; + case BPF_RET+BPF_K: + case BPF_RET+BPF_X: + case BPF_RET+BPF_A: + printf(_OP_FMT, "ret"); + break; + case BPF_MISC+BPF_TAX: + printf(_OP_FMT, "tax"); + break; + case BPF_MISC+BPF_TXA: + printf(_OP_FMT, "txa"); + break; + default: + printf(_OP_FMT, "???"); } } @@ -178,80 +178,80 @@ static void bpf_decode_op(const bpf_instr_raw *bpf) static void bpf_decode_args(const bpf_instr_raw *bpf, unsigned int line) { switch (BPF_CLASS(bpf->code)) { - case BPF_LD: - case BPF_LDX: - switch (BPF_MODE(bpf->code)) { - case BPF_ABS: - printf("$data[%u]", bpf->k); - break; - case BPF_MEM: - printf("$temp[%u]", bpf->k); - break; - } + case BPF_LD: + case BPF_LDX: + switch (BPF_MODE(bpf->code)) { + case BPF_ABS: + printf("$data[%u]", bpf->k); break; - case BPF_ST: - case BPF_STX: + case BPF_MEM: printf("$temp[%u]", bpf->k); break; - case BPF_ALU: - if (BPF_SRC(bpf->code) == BPF_K) { - switch (BPF_OP(bpf->code)) { - case BPF_OR: - case BPF_AND: - printf("0x%.8x", bpf->k); - break; - default: - printf("%u", bpf->k); - } - } else + } + break; + case BPF_ST: + case BPF_STX: + printf("$temp[%u]", bpf->k); + break; + case BPF_ALU: + if (BPF_SRC(bpf->code) == BPF_K) { + switch (BPF_OP(bpf->code)) { + case BPF_OR: + case BPF_AND: + printf("0x%.8x", bpf->k); + break; + default: printf("%u", bpf->k); - break; - case BPF_JMP: - if (BPF_OP(bpf->code) == BPF_JA) { - printf("%.4u", (line + 1) + bpf->k); - } else { - printf("%-4u true:%.4u false:%.4u", - bpf->k, - (line + 1) + bpf->jt, - (line + 1) + bpf->jf); } - break; - case BPF_RET: - if (BPF_RVAL(bpf->code) == BPF_A) { - /* XXX - accumulator? */ - printf("$acc"); - } else if (BPF_SRC(bpf->code) == BPF_K) { - uint32_t act = bpf->k & SECCOMP_RET_ACTION; - uint32_t data = bpf->k & SECCOMP_RET_DATA; + } else + printf("%u", bpf->k); + break; + case BPF_JMP: + if (BPF_OP(bpf->code) == BPF_JA) { + printf("%.4u", (line + 1) + bpf->k); + } else { + printf("%-4u true:%.4u false:%.4u", + bpf->k, + (line + 1) + bpf->jt, + (line + 1) + bpf->jf); + } + break; + case BPF_RET: + if (BPF_RVAL(bpf->code) == BPF_A) { + /* XXX - accumulator? */ + printf("$acc"); + } else if (BPF_SRC(bpf->code) == BPF_K) { + uint32_t act = bpf->k & SECCOMP_RET_ACTION; + uint32_t data = bpf->k & SECCOMP_RET_DATA; - switch (act) { - case SECCOMP_RET_KILL: - printf("KILL"); - break; - case SECCOMP_RET_TRAP: - printf("TRAP"); - break; - case SECCOMP_RET_ERRNO: - printf("ERRNO(%u)", data); - break; - case SECCOMP_RET_TRACE: - printf("TRACE(%u)", data); - break; - case SECCOMP_RET_ALLOW: - printf("ALLOW"); - break; - default: - printf("0x%.8x", bpf->k); - } - } else if (BPF_SRC(bpf->code) == BPF_X) { - /* XXX - any idea? */ - printf("???"); + switch (act) { + case SECCOMP_RET_KILL: + printf("KILL"); + break; + case SECCOMP_RET_TRAP: + printf("TRAP"); + break; + case SECCOMP_RET_ERRNO: + printf("ERRNO(%u)", data); + break; + case SECCOMP_RET_TRACE: + printf("TRACE(%u)", data); + break; + case SECCOMP_RET_ALLOW: + printf("ALLOW"); + break; + default: + printf("0x%.8x", bpf->k); } - break; - case BPF_MISC: - break; - default: + } else if (BPF_SRC(bpf->code) == BPF_X) { + /* XXX - any idea? */ printf("???"); + } + break; + case BPF_MISC: + break; + default: + printf("???"); } } diff --git a/tools/scmp_bpf_sim.c b/tools/scmp_bpf_sim.c index 94c6648..1b46cc9 100644 --- a/tools/scmp_bpf_sim.c +++ b/tools/scmp_bpf_sim.c @@ -59,9 +59,10 @@ static unsigned int opt_verbose = 0; */ static void exit_usage(const char *program) { - fprintf(stderr, "usage: %s -f [-v]" - " -a -s [-0 ] ... [-5 ]\n", - program); + fprintf(stderr, + "usage: %s -f [-v]" + " -a -s [-0 ] ... [-5 ]\n", + program); exit(EINVAL); } diff --git a/tools/scmp_sys_resolver.c b/tools/scmp_sys_resolver.c index 7e627d4..e86b400 100644 --- a/tools/scmp_sys_resolver.c +++ b/tools/scmp_sys_resolver.c @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) const char *sys_name; /* parse the command line */ - while ((opt = getopt(argc, argv, "a:ht"))> 0) { + while ((opt = getopt(argc, argv, "a:ht")) > 0) { switch (opt) { case 'a': if (strcmp(optarg, "x86") == 0) -- cgit v1.2.1