summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTudor Brindus <me@tbrindus.ca>2020-06-17 14:42:11 -0400
committerPaul Moore <paul@paul-moore.com>2020-06-27 16:43:59 -0400
commit12cf0074be3fa87ef33eecde6848176f03cd1460 (patch)
tree5fe0e4d1f27e46443bf8c3eedbab528ed0f07a1c
parentdde533bb490e73ccf1595196137c68cc8128cdbe (diff)
downloadlibseccomp-12cf0074be3fa87ef33eecde6848176f03cd1460.tar.gz
bpf: propagate errors from _gen_bpf_build_bpf helpers
Prior to this commit, _gen_bpf_build_bpf would mask some errors that occurred in helper functions as EFAULT, even if they were not EFAULT to begin with. See https://github.com/seccomp/libseccomp/issues/240 for additional information. Signed-off-by: Tudor Brindus <me@tbrindus.ca> [PM: fixed GitHub reference] Signed-off-by: Paul Moore <paul@paul-moore.com>
-rw-r--r--src/gen_bpf.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/gen_bpf.c b/src/gen_bpf.c
index a8b3314..2ed8abd 100644
--- a/src/gen_bpf.c
+++ b/src/gen_bpf.c
@@ -2144,6 +2144,7 @@ static int _gen_bpf_build_bpf(struct bpf_state *state,
break;
default:
/* fatal error */
+ rc = -EFAULT;
goto build_bpf_free_blks;
}
switch (i_iter->jf.type) {
@@ -2161,6 +2162,7 @@ static int _gen_bpf_build_bpf(struct bpf_state *state,
break;
default:
/* fatal error */
+ rc = -EFAULT;
goto build_bpf_free_blks;
}
}
@@ -2182,8 +2184,10 @@ static int _gen_bpf_build_bpf(struct bpf_state *state,
jmp_len += b_jmp->blk_cnt;
b_jmp = b_jmp->next;
}
- if (b_jmp == NULL || jmp_len > _BPF_JMP_MAX)
+ if (b_jmp == NULL || jmp_len > _BPF_JMP_MAX) {
+ rc = -EFAULT;
goto build_bpf_free_blks;
+ }
i_iter->jt = _BPF_JMP_IMM(jmp_len);
}
if (i_iter->jf.type == TGT_PTR_HSH) {
@@ -2194,8 +2198,10 @@ static int _gen_bpf_build_bpf(struct bpf_state *state,
jmp_len += b_jmp->blk_cnt;
b_jmp = b_jmp->next;
}
- if (b_jmp == NULL || jmp_len > _BPF_JMP_MAX)
+ if (b_jmp == NULL || jmp_len > _BPF_JMP_MAX) {
+ rc = -EFAULT;
goto build_bpf_free_blks;
+ }
i_iter->jf = _BPF_JMP_IMM(jmp_len);
}
if (i_iter->k.type == TGT_PTR_HSH) {
@@ -2209,14 +2215,17 @@ static int _gen_bpf_build_bpf(struct bpf_state *state,
jmp_len += b_jmp->blk_cnt;
b_jmp = b_jmp->prev;
}
- if (b_jmp == NULL)
+ if (b_jmp == NULL) {
+ rc = -EFAULT;
goto build_bpf_free_blks;
+ }
i_iter->k = _BPF_K(state->arch, jmp_len);
}
}
/* build the bpf program */
- if (_bpf_append_blk(state->bpf, b_iter) < 0)
+ rc = _bpf_append_blk(state->bpf, b_iter);
+ if (rc < 0)
goto build_bpf_free_blks;
/* we're done with the block, free it */
@@ -2234,7 +2243,7 @@ build_bpf_free_blks:
__blk_free(state, b_iter);
b_iter = b_jmp;
}
- return -EFAULT;
+ return rc;
}
/**