diff options
author | Alexei Starovoitov <ast@plumgrid.com> | 2014-04-22 20:18:57 -0700 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-04-23 15:34:41 -0400 |
commit | 83d5b7ef99c9f05e87333b334a638de1264ab8e4 (patch) | |
tree | f95ec9cdb441ecfcd32cafe96c1d30a865c9ba35 /net | |
parent | c06cbcb6052edd8f4ee00d65f874b26404ac8f96 (diff) | |
download | linux-stable-83d5b7ef99c9f05e87333b334a638de1264ab8e4.tar.gz linux-stable-83d5b7ef99c9f05e87333b334a638de1264ab8e4.tar.bz2 linux-stable-83d5b7ef99c9f05e87333b334a638de1264ab8e4.zip |
net: filter: initialize A and X registers
exisiting BPF verifier allows uninitialized access to registers,
'ret A' is considered to be a valid filter.
So initialize A and X to zero to prevent leaking kernel memory
In the future BPF verifier will be rejecting such filters
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Cc: Daniel Borkmann <dborkman@redhat.com>
Acked-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/core/filter.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/net/core/filter.c b/net/core/filter.c index cd58614660cf..9d79ca0a6e8e 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -122,6 +122,13 @@ noinline u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) return 0; } +/* Register mappings for user programs. */ +#define A_REG 0 +#define X_REG 7 +#define TMP_REG 8 +#define ARG2_REG 2 +#define ARG3_REG 3 + /** * __sk_run_filter - run a filter on a given context * @ctx: buffer to run the filter on @@ -242,6 +249,8 @@ unsigned int __sk_run_filter(void *ctx, const struct sock_filter_int *insn) regs[FP_REG] = (u64) (unsigned long) &stack[ARRAY_SIZE(stack)]; regs[ARG1_REG] = (u64) (unsigned long) ctx; + regs[A_REG] = 0; + regs[X_REG] = 0; select_insn: goto *jumptable[insn->code]; @@ -643,13 +652,6 @@ static u64 __get_raw_cpu_id(u64 ctx, u64 A, u64 X, u64 r4, u64 r5) return raw_smp_processor_id(); } -/* Register mappings for user programs. */ -#define A_REG 0 -#define X_REG 7 -#define TMP_REG 8 -#define ARG2_REG 2 -#define ARG3_REG 3 - static bool convert_bpf_extensions(struct sock_filter *fp, struct sock_filter_int **insnp) { |