netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: filter: initialize A and X registers
@ 2014-04-23  3:18 Alexei Starovoitov
  2014-04-23  3:57 ` David Miller
                   ` (2 more replies)
  0 siblings, 3 replies; 27+ messages in thread
From: Alexei Starovoitov @ 2014-04-23  3:18 UTC (permalink / raw)
  To: David S. Miller; +Cc: Daniel Borkmann, netdev

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>
---
 net/core/filter.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/net/core/filter.c b/net/core/filter.c
index cd58614..9d79ca0 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)
 {
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2014-04-25  8:23 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-23  3:18 [PATCH net] net: filter: initialize A and X registers Alexei Starovoitov
2014-04-23  3:57 ` David Miller
2014-04-23  4:59   ` Alexei Starovoitov
2014-04-23  7:02     ` Daniel Borkmann
2014-04-23 16:52       ` David Miller
2014-04-23 17:20         ` Daniel Borkmann
2014-04-23 16:50     ` David Miller
2014-04-23 20:38       ` Alexei Starovoitov
2014-04-23 21:39         ` Eric Dumazet
2014-04-23 22:19           ` Alexei Starovoitov
2014-04-24  2:55             ` Eric Dumazet
2014-04-24  3:22               ` Alexei Starovoitov
2014-04-25  8:23                 ` Daniel Borkmann
2014-04-24  7:07               ` Martin Schwidefsky
2014-04-23  5:13   ` Eric Dumazet
2014-04-23 11:45     ` Daniel Borkmann
2014-04-23 13:39       ` Eric Dumazet
2014-04-23 21:07         ` David Miller
2014-04-23 16:51     ` David Miller
2014-04-23 17:10       ` Daniel Borkmann
2014-04-23 17:14       ` Eric Dumazet
2014-04-24 17:24         ` David Miller
2014-04-24 18:11           ` Eric Dumazet
2014-04-24 22:18           ` Daniel Borkmann
2014-04-23  7:53 ` Daniel Borkmann
2014-04-23 16:13   ` Alexei Starovoitov
2014-04-23 19:35 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).