netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ebpf: emit correct src_reg for conditional jumps
@ 2015-09-11  0:25 Tycho Andersen
  2015-09-11  8:45 ` Daniel Borkmann
  2015-09-11 21:53 ` David Miller
  0 siblings, 2 replies; 7+ messages in thread
From: Tycho Andersen @ 2015-09-11  0:25 UTC (permalink / raw)
  To: Alexei Starovoitov, David S. Miller
  Cc: netdev, Tycho Andersen, Daniel Borkmann

Instead of always emitting BPF_REG_X, let's emit BPF_REG_X only when the
source actually is BPF_X. This causes programs generated by the classic
converter to not be importable via bpf(), as the eBPF verifier checks that
the src_reg is correct or 0. While not a problem yet, this will be a
problem when BPF_PROG_DUMP lands, and we can potentially dump and re-import
programs generated by the converter.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
CC: Alexei Starovoitov <ast@kernel.org>
CC: Daniel Borkmann <daniel@iogearbox.net>
---
 net/core/filter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/core/filter.c b/net/core/filter.c
index 13079f0..05a04ea 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -478,9 +478,9 @@ do_pass:
 				bpf_src = BPF_X;
 			} else {
 				insn->dst_reg = BPF_REG_A;
-				insn->src_reg = BPF_REG_X;
 				insn->imm = fp->k;
 				bpf_src = BPF_SRC(fp->code);
+				insn->src_reg = bpf_src == BPF_X ? BPF_REG_X : 0;
 			}
 
 			/* Common case where 'jump_false' is next insn. */
-- 
2.1.4

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

end of thread, other threads:[~2015-09-11 21:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-11  0:25 [PATCH] ebpf: emit correct src_reg for conditional jumps Tycho Andersen
2015-09-11  8:45 ` Daniel Borkmann
2015-09-11  9:28   ` Daniel Borkmann
2015-09-11 15:40     ` Alexei Starovoitov
2015-09-11 15:50       ` Tycho Andersen
2015-09-11 16:53         ` Daniel Borkmann
2015-09-11 21:53 ` 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).