All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 1/2] samples/bpf: fix sockex2 example
@ 2016-11-23  0:52 Alexei Starovoitov
  2016-11-23  0:52 ` [PATCH net-next 2/2] samples/bpf: fix bpf loader Alexei Starovoitov
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2016-11-23  0:52 UTC (permalink / raw)
  To: David S . Miller; +Cc: Daniel Borkmann, netdev

since llvm commit "Do not expand UNDEF SDNode during insn selection lowering"
llvm will generate code that uses uninitialized registers for cases
where C code is actually uses uninitialized data.
So this sockex2 example is technically broken.
Fix it by initializing on the stack variable fully.
Also increase verifier buffer limit, since verifier output
may not fit in 64k for this sockex2 code depending on llvm version.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 samples/bpf/libbpf.h       | 2 +-
 samples/bpf/sockex2_kern.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/samples/bpf/libbpf.h b/samples/bpf/libbpf.h
index ac6edb61b64a..de96a935068d 100644
--- a/samples/bpf/libbpf.h
+++ b/samples/bpf/libbpf.h
@@ -18,7 +18,7 @@ int bpf_prog_load(enum bpf_prog_type prog_type,
 int bpf_obj_pin(int fd, const char *pathname);
 int bpf_obj_get(const char *pathname);
 
-#define LOG_BUF_SIZE 65536
+#define LOG_BUF_SIZE (256 * 1024)
 extern char bpf_log_buf[LOG_BUF_SIZE];
 
 /* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */
diff --git a/samples/bpf/sockex2_kern.c b/samples/bpf/sockex2_kern.c
index 44e5846c988f..f58acfc92556 100644
--- a/samples/bpf/sockex2_kern.c
+++ b/samples/bpf/sockex2_kern.c
@@ -198,7 +198,7 @@ struct bpf_map_def SEC("maps") hash_map = {
 SEC("socket2")
 int bpf_prog2(struct __sk_buff *skb)
 {
-	struct bpf_flow_keys flow;
+	struct bpf_flow_keys flow = {};
 	struct pair *value;
 	u32 key;
 
-- 
2.8.0

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

* [PATCH net-next 2/2] samples/bpf: fix bpf loader
  2016-11-23  0:52 [PATCH net-next 1/2] samples/bpf: fix sockex2 example Alexei Starovoitov
@ 2016-11-23  0:52 ` Alexei Starovoitov
  2016-11-23  9:57   ` Daniel Borkmann
  2016-11-24 21:05   ` David Miller
  2016-11-23  9:58 ` [PATCH net-next 1/2] samples/bpf: fix sockex2 example Daniel Borkmann
  2016-11-24 21:05 ` David Miller
  2 siblings, 2 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2016-11-23  0:52 UTC (permalink / raw)
  To: David S . Miller; +Cc: Daniel Borkmann, netdev

llvm can emit relocations into sections other than program code
(like debug info sections). Ignore them during parsing of elf file

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 samples/bpf/bpf_load.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c
index 97913e109b14..62f54d6eb8bf 100644
--- a/samples/bpf/bpf_load.c
+++ b/samples/bpf/bpf_load.c
@@ -317,6 +317,10 @@ int load_bpf_file(char *path)
 				    &shdr_prog, &data_prog))
 				continue;
 
+			if (shdr_prog.sh_type != SHT_PROGBITS ||
+			    !(shdr_prog.sh_flags & SHF_EXECINSTR))
+				continue;
+
 			insns = (struct bpf_insn *) data_prog->d_buf;
 
 			processed_sec[shdr.sh_info] = true;
-- 
2.8.0

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

* Re: [PATCH net-next 2/2] samples/bpf: fix bpf loader
  2016-11-23  0:52 ` [PATCH net-next 2/2] samples/bpf: fix bpf loader Alexei Starovoitov
@ 2016-11-23  9:57   ` Daniel Borkmann
  2016-11-24 21:05   ` David Miller
  1 sibling, 0 replies; 6+ messages in thread
From: Daniel Borkmann @ 2016-11-23  9:57 UTC (permalink / raw)
  To: Alexei Starovoitov, David S . Miller; +Cc: netdev

On 11/23/2016 01:52 AM, Alexei Starovoitov wrote:
> llvm can emit relocations into sections other than program code
> (like debug info sections). Ignore them during parsing of elf file
>
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Acked-by: Daniel Borkmann <daniel@iogearbox.net>

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

* Re: [PATCH net-next 1/2] samples/bpf: fix sockex2 example
  2016-11-23  0:52 [PATCH net-next 1/2] samples/bpf: fix sockex2 example Alexei Starovoitov
  2016-11-23  0:52 ` [PATCH net-next 2/2] samples/bpf: fix bpf loader Alexei Starovoitov
@ 2016-11-23  9:58 ` Daniel Borkmann
  2016-11-24 21:05 ` David Miller
  2 siblings, 0 replies; 6+ messages in thread
From: Daniel Borkmann @ 2016-11-23  9:58 UTC (permalink / raw)
  To: Alexei Starovoitov, David S . Miller; +Cc: netdev

On 11/23/2016 01:52 AM, Alexei Starovoitov wrote:
> since llvm commit "Do not expand UNDEF SDNode during insn selection lowering"
> llvm will generate code that uses uninitialized registers for cases
> where C code is actually uses uninitialized data.
> So this sockex2 example is technically broken.
> Fix it by initializing on the stack variable fully.
> Also increase verifier buffer limit, since verifier output
> may not fit in 64k for this sockex2 code depending on llvm version.
>
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Acked-by: Daniel Borkmann <daniel@iogearbox.net>

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

* Re: [PATCH net-next 1/2] samples/bpf: fix sockex2 example
  2016-11-23  0:52 [PATCH net-next 1/2] samples/bpf: fix sockex2 example Alexei Starovoitov
  2016-11-23  0:52 ` [PATCH net-next 2/2] samples/bpf: fix bpf loader Alexei Starovoitov
  2016-11-23  9:58 ` [PATCH net-next 1/2] samples/bpf: fix sockex2 example Daniel Borkmann
@ 2016-11-24 21:05 ` David Miller
  2 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2016-11-24 21:05 UTC (permalink / raw)
  To: ast; +Cc: daniel, netdev

From: Alexei Starovoitov <ast@fb.com>
Date: Tue, 22 Nov 2016 16:52:08 -0800

> since llvm commit "Do not expand UNDEF SDNode during insn selection lowering"
> llvm will generate code that uses uninitialized registers for cases
> where C code is actually uses uninitialized data.
> So this sockex2 example is technically broken.
> Fix it by initializing on the stack variable fully.
> Also increase verifier buffer limit, since verifier output
> may not fit in 64k for this sockex2 code depending on llvm version.
> 
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Applied.

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

* Re: [PATCH net-next 2/2] samples/bpf: fix bpf loader
  2016-11-23  0:52 ` [PATCH net-next 2/2] samples/bpf: fix bpf loader Alexei Starovoitov
  2016-11-23  9:57   ` Daniel Borkmann
@ 2016-11-24 21:05   ` David Miller
  1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2016-11-24 21:05 UTC (permalink / raw)
  To: ast; +Cc: daniel, netdev

From: Alexei Starovoitov <ast@fb.com>
Date: Tue, 22 Nov 2016 16:52:09 -0800

> llvm can emit relocations into sections other than program code
> (like debug info sections). Ignore them during parsing of elf file
> 
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Applied.

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

end of thread, other threads:[~2016-11-24 21:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-23  0:52 [PATCH net-next 1/2] samples/bpf: fix sockex2 example Alexei Starovoitov
2016-11-23  0:52 ` [PATCH net-next 2/2] samples/bpf: fix bpf loader Alexei Starovoitov
2016-11-23  9:57   ` Daniel Borkmann
2016-11-24 21:05   ` David Miller
2016-11-23  9:58 ` [PATCH net-next 1/2] samples/bpf: fix sockex2 example Daniel Borkmann
2016-11-24 21:05 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.