Re: [PATCH 18/27] bpf: Restrict kernel image access functions when the kernel is locked down

2017-10-19 Thread Alexei Starovoitov
On Thu, Oct 19, 2017 at 11:48:34PM +0100, David Howells wrote: > Alexei Starovoitov wrote: > > > > @@ -65,6 +65,11 @@ BPF_CALL_3(bpf_probe_read, void *, dst, u32, size, > > > const void *, unsafe_ptr) > > > { > > > int ret; >

Re: [PATCH 1/2] bpf: add a bpf_override_function helper

2017-10-30 Thread Alexei Starovoitov
On 10/30/17 2:19 PM, Josef Bacik wrote: From: Josef Bacik Error injection is sloppy and very ad-hoc. BPF could fill this niche perfectly with it's kprobe functionality. We could make sure errors are only triggered in specific call chains that we care about with very specific situations. Acco

Re: [PATCH 2/2] samples/bpf: add a test for bpf_override_return

2017-10-30 Thread Alexei Starovoitov
On 10/30/17 2:19 PM, Josef Bacik wrote: + +rm -f testfile.img +dd if=/dev/zero of=testfile.img bs=1M seek=1000 count=1 +DEVICE=$(losetup --show -f testfile.img) +mkfs.btrfs -f $DEVICE +mkdir tmpmnt +./tracex7 $DEVICE +if [ $? -eq 0 ] +then + echo "SUCCESS!" +else + echo "FAILED!" +fi

[PATCH net-next 0/2] bpf: unprivileged

2015-10-05 Thread Alexei Starovoitov
ing and TC classifiers/actions will stay root only. In parallel the bpf fuzzing effort is ongoing and so far we've found only one verifier bug and that was already fixed. The 'constant blinding' pass also being worked on. It will obfuscate constant-like values that are part of eBPF ISA

[PATCH net-next 2/2] bpf: charge user for creation of BPF maps and programs

2015-10-05 Thread Alexei Starovoitov
p of perf_event. Signed-off-by: Alexei Starovoitov --- The charging is agressive and even basic test_maps, test_verifier are hitting memlock limit, so alternatively we can drop charging for cap_sys_admin. --- include/linux/bpf.h |3 +++ include/linux/sched.h |2 +- kernel/bpf/arraymap.c |

[PATCH net-next 1/2] bpf: enable non-root eBPF programs

2015-10-05 Thread Alexei Starovoitov
on stack 2 OK unpriv: read pointer from stack in small chunks OK unpriv: write pointer into ctx OK unpriv: write pointer into map elem value OK unpriv: partial copy of pointer OK Signed-off-by: Alexei Starovoitov --- include/linux/bpf.h |3 + kernel/bpf/syscall.c|

Re: [PATCH net-next 1/2] bpf: enable non-root eBPF programs

2015-10-05 Thread Alexei Starovoitov
On 10/5/15 2:00 PM, Kees Cook wrote: On Mon, Oct 5, 2015 at 1:48 PM, Alexei Starovoitov wrote: >In order to let unprivileged users load and execute eBPF programs >teach verifier to prevent pointer leaks. >Verifier will prevent >- any arithmetic on pointers > (except R10+Imm w

Re: [PATCH net-next 1/2] bpf: enable non-root eBPF programs

2015-10-05 Thread Alexei Starovoitov
On 10/5/15 2:16 PM, Andy Lutomirski wrote: On Mon, Oct 5, 2015 at 2:12 PM, Alexei Starovoitov wrote: On 10/5/15 2:00 PM, Kees Cook wrote: On Mon, Oct 5, 2015 at 1:48 PM, Alexei Starovoitov wrote: In order to let unprivileged users load and execute eBPF programs teach verifier to prevent

Re: [PATCH net-next 1/2] bpf: enable non-root eBPF programs

2015-10-05 Thread Alexei Starovoitov
On 10/5/15 3:02 PM, Kees Cook wrote: the array maps that hold FDs (BPF_MAP_TYPE_PROG_ARRAY and >BPF_MAP_TYPE_PERF_EVENT_ARRAY) don't have lookup/update accessors >from the program side, so programs cannot see or manipulate >those pointers. >For the former only bpf_tail_call() is allowed that take

Re: [PATCH net-next 1/2] bpf: enable non-root eBPF programs

2015-10-05 Thread Alexei Starovoitov
On 10/5/15 3:14 PM, Daniel Borkmann wrote: One scenario that comes to mind ... what happens when there are kernel pointers stored in skb->cb[] (either from the current layer or an old one from a different layer that the skb went through previously, but which did not get overwritten)? Socket filt

Re: [PATCH net-next 1/2] bpf: enable non-root eBPF programs

2015-10-06 Thread Alexei Starovoitov
On 10/6/15 1:39 AM, Daniel Borkmann wrote: [...] Also classic BPF would then need to test for it, since a socket filter doesn't really know whether native eBPF is loaded there or a classic-to-eBPF transformed one, and classic never makes use of this. Anyway, it could be done by adding a bit flag

Re: [PATCH net-next 1/2] bpf: enable non-root eBPF programs

2015-10-06 Thread Alexei Starovoitov
On 10/6/15 10:56 AM, Eric Dumazet wrote: On Tue, 2015-10-06 at 10:50 -0700, Alexei Starovoitov wrote: was also thinking that we can do it only in paths that actually have multiple protocol layers, since today bpf is mainly used with tcpdump(raw_socket) and new af_packet fanout both have cb

Re: [PATCH net-next 1/2] bpf: enable non-root eBPF programs

2015-10-07 Thread Alexei Starovoitov
On 10/6/15 5:45 AM, Daniel Borkmann wrote: Should instead something similar be adapted on bpf(2) as well? Or, would that even be more painful for application developers shipping their stuff through distros in the end (where they might then decide to just setup everything BPF-related and then drop

Re: [PATCH net-next 1/2] bpf: enable non-root eBPF programs

2015-10-07 Thread Alexei Starovoitov
On 10/7/15 3:22 PM, Kees Cook wrote: Yes, I agree with you that there would be a CVE regardless. I still >like the option of configurable access, not a big fan of the sysctl >either. Thinking out loudly, what about a Kconfig option? We started >out like this on bpf(2) itself (initially under expe

Re: [PATCH net-next 1/2] bpf: enable non-root eBPF programs

2015-10-07 Thread Alexei Starovoitov
On 10/5/15 1:48 PM, Alexei Starovoitov wrote: Unprivileged socket filter bpf programs have access to the following helper functions: - map lookup/update/delete (but they cannot store kernel pointers into them) - get_random (it's already exposed to unprivileged user space) - get_smp_process

[PATCH v2 net-next 1/3] bpf: enable non-root eBPF programs

2015-10-07 Thread Alexei Starovoitov
nprivileged_bpf_disabled. This toggle defaults to off (0), but can be set true (1). Once true, bpf programs and maps cannot be accessed from unprivileged process, and the toggle cannot be set back to false. Signed-off-by: Alexei Starovoitov --- v1->v2: - sysctl_unprivileged_bpf_disabled - dr

[PATCH v2 net-next 2/3] bpf: charge user for creation of BPF maps and programs

2015-10-07 Thread Alexei Starovoitov
p of perf_event. Signed-off-by: Alexei Starovoitov --- The charging is agressive and even basic test_maps, test_verifier are hitting memlock limit, so alternatively we can drop charging for cap_sys_admin. --- include/linux/bpf.h |3 +++ include/linux/sched.h |2 +- kernel/bpf/arraymap.c |

[PATCH v2 net-next 0/3] bpf: unprivileged

2015-10-07 Thread Alexei Starovoitov
fixed. The 'constant blinding' pass also being worked on. It will obfuscate constant-like values that are part of eBPF ISA to make jit spraying attacks even harder. Alexei Starovoitov (3): bpf: enable non-root eBPF programs bpf: charge user for creation of BPF maps and programs

[PATCH v2 net-next 3/3] bpf: add unprivileged bpf tests

2015-10-07 Thread Alexei Starovoitov
Rx -= imm is not Signed-off-by: Alexei Starovoitov --- v1-v2: - split tests into separate patch - add tail_call and other tests and explain tests in commit log --- samples/bpf/libbpf.h|8 + samples/bpf/test_verifier.c | 357 +-- 2 files change

Re: [PATCH net-next 1/2] bpf: enable non-root eBPF programs

2015-10-07 Thread Alexei Starovoitov
On 10/7/15 11:21 PM, Ingo Molnar wrote: so I see no reason why unprivileged eBPF couldn't have a sysctl too - with the default value set to permissive. agreed. sent out v2 follows 'modules_disabled' style. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of

Re: [PATCH net-next] bpf: add support for %s specifier to bpf_trace_printk()

2015-08-27 Thread Alexei Starovoitov
On 8/27/15 3:34 PM, David Miller wrote: From: Alexei Starovoitov Date: Wed, 26 Aug 2015 23:26:59 -0700 +/* similar to strncpy_from_user() but with extra checks */ +static void probe_read_string(char *buf, int size, long unsafe_ptr) +{ + char dst[4]; + int i = 0; + + size

Re: [PATCH net-next] bpf: add support for %s specifier to bpf_trace_printk()

2015-08-27 Thread Alexei Starovoitov
On 8/27/15 4:43 PM, Steven Rostedt wrote: On Thu, 27 Aug 2015 16:20:39 -0700 (PDT) David Miller wrote: From: Alexei Starovoitov Date: Thu, 27 Aug 2015 16:06:14 -0700 Fair or you still think it should be per byte copy? I'm terribly surprised we don't have an equivalent of str

[PATCH v2 net-next 2/2] bpf: add support for %s specifier to bpf_trace_printk()

2015-08-28 Thread Alexei Starovoitov
ct2 collect2-13497 [000] d..1 3251.012941: : executed /usr/bin/ld Suggested-by: Brendan Gregg Signed-off-by: Alexei Starovoitov --- v1->v2: use generalized strncpy_from_unsafe() and fix the case of multiple '%s' per format string. kernel/trace/bpf_trace.c | 32 +

[PATCH v2 net-next 0/2] support for '%s' in bpf_trace_printk

2015-08-28 Thread Alexei Starovoitov
v1->v2: patch 1: generalize FETCH_FUNC_NAME(memory, string) into strncpy_from_unsafe() patch 2: use it in bpf_trace_printk Alexei Starovoitov (2): lib: introduce strncpy_from_unsafe() bpf: add support for %s specifier to bpf_trace_printk() include/linux/uaccess.h |2 ++ kernel/tr

[PATCH v2 net-next 1/2] lib: introduce strncpy_from_unsafe()

2015-08-28 Thread Alexei Starovoitov
generalize FETCH_FUNC_NAME(memory, string) into strncpy_from_unsafe() and fix sparse warnings that were present in original implementation. Signed-off-by: Alexei Starovoitov --- include/linux/uaccess.h |2 ++ kernel/trace/trace_kprobe.c | 20 lib

Re: [PATCH v2 net-next 1/2] lib: introduce strncpy_from_unsafe()

2015-08-28 Thread Alexei Starovoitov
On 8/28/15 2:48 PM, Steven Rostedt wrote: * On success, returns the length of the string (not including the trailing >+ * NUL). I think it includes the NUL. oops. yes. that was a copy paste from strncpy_from_user comment. trace_kprobe usage wants NUL to be counted, so I intended to have it c

Re: [PATCH v2 net-next 1/2] lib: introduce strncpy_from_unsafe()

2015-08-28 Thread Alexei Starovoitov
On 8/28/15 3:11 PM, Steven Rostedt wrote: I personally prefer counting the NUL. I've had issues in the past with the strncpy_from_user() not counting it :-p agreed. will respin with comment fixed. thank you much for review! -- To unsubscribe from this list: send the line "unsubscribe linux-ker

[PATCH v3 net-next 2/2] bpf: add support for %s specifier to bpf_trace_printk()

2015-08-28 Thread Alexei Starovoitov
ct2 collect2-13497 [000] d..1 3251.012941: : executed /usr/bin/ld Suggested-by: Brendan Gregg Signed-off-by: Alexei Starovoitov --- v1->v2: use generalized strncpy_from_unsafe() and fix the case of multiple '%s' per format string. v2->v3: no changes kernel/trace/bpf_trace.c

[PATCH v3 net-next 0/2] support for '%s' in bpf_trace_printk

2015-08-28 Thread Alexei Starovoitov
v2->v3: fix the comment to mention that strncpy_from_unsafe() returns the length of the string including the trailing NUL. v1->v2: patch 1: generalize FETCH_FUNC_NAME(memory, string) into strncpy_from_unsafe() patch 2: use it in bpf_trace_printk Alexei Starovoitov (2): lib: int

[PATCH v3 net-next 1/2] lib: introduce strncpy_from_unsafe()

2015-08-28 Thread Alexei Starovoitov
generalize FETCH_FUNC_NAME(memory, string) into strncpy_from_unsafe() and fix sparse warnings that were present in original implementation. Signed-off-by: Alexei Starovoitov --- include/linux/uaccess.h |2 ++ kernel/trace/trace_kprobe.c | 20 lib

Re: [GIT PULL 00/32] perf tools: filtering events using eBPF programs

2015-08-28 Thread Alexei Starovoitov
On 8/28/15 12:05 AM, Wang Nan wrote: Hi Arnaldo, This time I adjust all Cc and Link field in each patch. Four new patches (1,2,3,12/32) is newly introduced for fixing a bug related to '--filter' option. Patch 06/32 is also modified. Please keep an eye on it. Arnaldo, what is the latest news o

Re: [PATCH 31/32] tools lib traceevent: Support function __get_dynamic_array_len

2015-08-28 Thread Alexei Starovoitov
allocated length of the dynamic array is embedded in the top half of __data_loc_##item field. This patch adds new arg type PRINT_DYNAMIC_ARRAY_LEN to return the length to eval_num_arg(), Signed-off-by: He Kuang Acked-by: Namhyung Kim Tested-by: Alexei Starovoitov this patch fixes the perf crash

Re: [PATCH 32/32] bpf: Introduce function for outputing data to perf event

2015-08-28 Thread Alexei Starovoitov
On 8/28/15 12:06 AM, Wang Nan wrote: his patch adds a new trace event to establish infrastruction for bpf to output data to perf. Userspace perf tools can detect and use this event as using the existing tracepoint events. New bpf trace event entry in debugfs: /sys/kernel/debug/tracing/eve

Re: [RFC PATCH 0/4] perf tools: Use the new ability of eBPF programs to access hardware PMU counter

2015-08-28 Thread Alexei Starovoitov
On 8/27/15 3:42 AM, Kaixu Xia wrote: An example is pasted at the bottom of this cover letter. In that example, we can get the cpu_cycles and exception taken in sys_write. $ cat /sys/kernel/debug/tracing/trace_pipe $ ./perf record --event perf-bpf.o ls ... cat-1653 [003

Re: [PATCH 32/32] bpf: Introduce function for outputing data to perf event

2015-08-28 Thread Alexei Starovoitov
On 8/28/15 6:19 PM, Wangnan (F) wrote: For me, I use bpf_output_trace_data() to output information like PMU count value. Perf is the only receiver, so global collector is perfect. Could you please describe your usecase in more detail? there is a special receiver in user space that only wants th

Re: [PATCH 32/32] bpf: Introduce function for outputing data to perf event

2015-08-28 Thread Alexei Starovoitov
On 8/28/15 7:15 PM, Wangnan (F) wrote: I'd like to see whether it is possible to create dynamic tracepoints so different receivers can listen on different tracepoints. see my proposal A. I think ftrace instances might work for this. I'm not sure about 'format' part though. Kernel side shouldn'

Re: [RFC PATCH 0/4] perf tools: Use the new ability of eBPF programs to access hardware PMU counter

2015-08-28 Thread Alexei Starovoitov
On 8/28/15 7:14 PM, xiakaixu wrote: Right, this is just a little example. Actually, I have tested this ability on kernel side and user space side, that is kprobe and uprobe. great to hear. At this time i wish to get your comment on the current chosen implementation. Now the struct perf_event_

Re: [PATCH 32/32] bpf: Introduce function for outputing data to perf event

2015-08-28 Thread Alexei Starovoitov
On 8/28/15 7:36 PM, Wangnan (F) wrote: For current patch 32/32, I think it is useful enough for some simple cases, and we have already start using it internally. What about keep it as what it is now and create a independent method for your usecase? well, though the patch is small and contained,

Re: linux-next: Tree for Aug 31 (new arm, arm64, s390 failures)

2015-08-31 Thread Alexei Starovoitov
On 8/31/15 7:17 AM, Guenter Roeck wrote: s390: kernel/built-in.o: In function `bpf_trace_printk': bpf_trace.c:(.text+0x116a5c): undefined reference to `strncpy_from_unsafe' kernel/built-in.o: In function `fetch_memory_string': trace_kprobe.c:(.text+0x118ee0): undefined reference to `strncpy_from

[PATCH net-next] lib: move strncpy_from_unsafe() into mm/maccess.c

2015-08-31 Thread Alexei Starovoitov
m_unsafe' move strncpy_from_unsafe() next to probe_kernel_read/write() which use the same memory access style. Reported-by: Fengguang Wu Reported-by: Guenter Roeck Fixes: 1a6877b9c0c2 ("lib: introduce strncpy_from_unsafe()") Signed-off-by: Alexei Starovoitov --- For configs without kprobes a

Re: [RFC PATCH 1/2] perf: Add the flag sample_disable not to output data on samples

2015-10-12 Thread Alexei Starovoitov
On 10/12/15 2:02 AM, Kaixu Xia wrote: diff --git a/include/linux/bpf.h b/include/linux/bpf.h index f57d7fe..25e073d 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -39,6 +39,7 @@ struct bpf_map { u32 max_entries; const struct bpf_map_ops *ops; struct work_str

Re: [RFC PATCH 2/2] bpf: Implement bpf_perf_event_sample_enable/disable() helpers

2015-10-12 Thread Alexei Starovoitov
On 10/12/15 2:02 AM, Kaixu Xia wrote: +extern const struct bpf_func_proto bpf_perf_event_sample_enable_proto; +extern const struct bpf_func_proto bpf_perf_event_sample_disable_proto; externs are unnecessary. Just make them static. Also I prefer single helper that takes a flag, so we can extend

Re: [RFC PATCH 1/2] perf: Add the flag sample_disable not to output data on samples

2015-10-12 Thread Alexei Starovoitov
On 10/12/15 7:30 PM, xiakaixu wrote: The proper perf_event_enable/disable are so heavy that another >mechanism needed? cpu_function_call is probably too much to do >from bpf program, but that can be simplified? >Based on the use case from cover letter, sounds like you want >something like soft_di

Re: [RFC PATCH 2/2] bpf: Implement bpf_perf_event_sample_enable/disable() helpers

2015-10-12 Thread Alexei Starovoitov
On 10/12/15 8:27 PM, Wangnan (F) wrote: Then how to avoid racing? For example, when one core disabling all events in a map, another core is enabling all of them. This racing may causes sereval perf events in a map dump samples while other events not. To avoid such racing I think some locking must

Re: [RFC PATCH 2/2] bpf: Implement bpf_perf_event_sample_enable/disable() helpers

2015-10-12 Thread Alexei Starovoitov
On 10/12/15 8:51 PM, Wangnan (F) wrote: why 'set disable' is needed ? the example given in cover letter shows the use case where you want to receive samples only within sys_write() syscall. The example makes sense, but sys_write() is running on this cpu, so just disabling it on the current one is

Re: [RFC PATCH 2/2] bpf: Implement bpf_perf_event_sample_enable/disable() helpers

2015-10-12 Thread Alexei Starovoitov
On 10/12/15 9:34 PM, Wangnan (F) wrote: On 2015/10/13 12:16, Alexei Starovoitov wrote: On 10/12/15 8:51 PM, Wangnan (F) wrote: why 'set disable' is needed ? the example given in cover letter shows the use case where you want to receive samples only within sys_write() syscall. T

Re: [RFC PATCH 2/2] bpf: Implement bpf_perf_event_sample_enable/disable() helpers

2015-10-13 Thread Alexei Starovoitov
On 10/13/15 3:54 AM, He Kuang wrote: If we want perf to reflect as soon as our sample event be generated, --no-buffering should be used, but this option has a greater impact on performance. no_buffering doesn't have to be applied to all events obviously. -- To unsubscribe from this list: send

Re: [PATCH 5/6] seccomp: add a way to attach a filter via eBPF fd

2015-09-09 Thread Alexei Starovoitov
On Wed, Sep 09, 2015 at 08:47:24AM -0600, Tycho Andersen wrote: > On Tue, Sep 08, 2015 at 05:07:03PM -0700, Kees Cook wrote: > > > > Yeah, bpf's union looks good. Let's add a "command" flag, though: > > > > seccomp(SECCOMP_MODE_FILTER_EBPF, int cmd, union, size); > > > > And this cmd could be ADD

Re: [PATCH 1/6] ebpf: add a seccomp program type

2015-09-09 Thread Alexei Starovoitov
On Wed, Sep 09, 2015 at 09:50:35AM -0600, Tycho Andersen wrote: > > > > > > That's effectively what this patch does; when the eBPF is loaded via > > > bpf(), you tell bpf() you want a BPF_PROG_TYPE_SECCOMP, and it invokes > > > this validation/translation code, i.e. it uses > > > seccomp_is_valid_a

Re: [PATCH 1/6] ebpf: add a seccomp program type

2015-09-09 Thread Alexei Starovoitov
On Wed, Sep 09, 2015 at 09:37:51AM -0700, Kees Cook wrote: > On Wed, Sep 9, 2015 at 9:09 AM, Daniel Borkmann wrote: > > On 09/09/2015 06:07 PM, Alexei Starovoitov wrote: > >> > >> On Wed, Sep 09, 2015 at 09:50:35AM -0600, Tycho Andersen wrote: > &g

Re: [PATCH V2 1/2] bpf: control the trace data output on current cpu when perf sampling

2015-10-14 Thread Alexei Starovoitov
On 10/14/15 5:37 AM, Kaixu Xia wrote: This patch adds the flag sample_disable to control the trace data output process when perf sampling. By setting this flag and integrating with ebpf, we can control the data output process and get the samples we are most interested in. The bpf helper bpf_perf

Re: [PATCH V2 2/2] bpf: control a set of perf events by creating a new ioctl PERF_EVENT_IOC_SET_ENABLER

2015-10-14 Thread Alexei Starovoitov
On 10/14/15 5:37 AM, Kaixu Xia wrote: + event->p_sample_disable = &enabler_event->sample_disable; I don't like it as a concept and it's buggy implementation. What happens here when enabler is alive, but other event is destroyed? --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trac

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-16 Thread Alexei Starovoitov
On 10/16/15 3:25 AM, Hannes Frederic Sowa wrote: Namespaces at some point dealt with the same problem, they nowadays use bind mounts of/proc/$$/ns/* to some place in the file hierarchy to keep the namespace alive. This at least allows someone to build up its own hierarchy with normal unix tools a

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-16 Thread Alexei Starovoitov
On 10/16/15 9:43 AM, Hannes Frederic Sowa wrote: Hi Alexei, On Fri, Oct 16, 2015, at 18:18, Alexei Starovoitov wrote: On 10/16/15 3:25 AM, Hannes Frederic Sowa wrote: Namespaces at some point dealt with the same problem, they nowadays use bind mounts of/proc/$$/ns/* to some place in the file

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-16 Thread Alexei Starovoitov
On 10/16/15 10:27 AM, Daniel Borkmann wrote: but don't know how flexible we are in terms of adding S_IFBPF to the UAPI. I don't think it should be a problem. You referred to POSIX Standard in your other mail but I can't see any reason why not to establish a new file mode. Anyway, FreeBSD (e.g.

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-16 Thread Alexei Starovoitov
On 10/16/15 10:21 AM, Hannes Frederic Sowa wrote: Another question: Should multiple mount of the filesystem result in an empty fs (a new instance) or in one were one can see other ebpf-fs entities? I think Daniel wanted to already use the mountpoint as some kind of hierarchy delimiter. I would ha

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-16 Thread Alexei Starovoitov
On 10/16/15 11:41 AM, Eric W. Biederman wrote: Daniel Borkmann writes: On 10/16/2015 07:42 PM, Alexei Starovoitov wrote: On 10/16/15 10:21 AM, Hannes Frederic Sowa wrote: Another question: Should multiple mount of the filesystem result in an empty fs (a new instance) or in one were one can

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-16 Thread Alexei Starovoitov
On 10/16/15 12:53 PM, Eric W. Biederman wrote: Alexei Starovoitov writes: On 10/16/15 11:41 AM, Eric W. Biederman wrote: [...] I am missing something. When I suggested using a filesystem it was my thought there would be exactly one superblock per map, and the map would be specified at

Re: [PATCH V3 1/2] bpf: control the trace data output on current cpu when perf sampling

2015-10-16 Thread Alexei Starovoitov
On 10/16/15 12:42 AM, Kaixu Xia wrote: This patch adds the flag dump_enable to control the trace data output process when perf sampling. By setting this flag and integrating with ebpf, we can control the data output process and get the samples we are most interested in. The bpf helper bpf_perf_e

Re: [PATCH V3 2/2] bpf: control all the perf events stored in PERF_EVENT_ARRAY maps

2015-10-16 Thread Alexei Starovoitov
On 10/16/15 12:42 AM, Kaixu Xia wrote: This patch implements the function that controlling all the perf events stored in PERF_EVENT_ARRAY maps by setting the parameter 'index' to maps max_entries. Signed-off-by: Kaixu Xia --- kernel/trace/bpf_trace.c | 20 ++-- 1 file changed

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-16 Thread Alexei Starovoitov
On 10/16/15 4:44 PM, Eric W. Biederman wrote: Alexei Starovoitov writes: We can argue about api for 2nd, whether it's mount with fd=1234 string or else, but for the first mount style doesn't make sense. Why does mount not make sense? It is exactly what you are looking for so w

Re: [PATCH] mm/maccess.c: actually return -EFAULT from strncpy_from_unsafe

2015-10-17 Thread Alexei Starovoitov
the length of the, possibly truncated, destination string. Signed-off-by: Rasmus Villemoes --- Probably not -stable-worthy. I can only find two callers, one of which ignores the return value. good catch. Acked-by: Alexei Starovoitov cc-ing original authors where I copy pasted that part from

Re: [RFC PATCH 0/7] perf tools: Config BPF maps through perf cmdline

2015-10-17 Thread Alexei Starovoitov
On 10/17/15 3:48 AM, Wang Nan wrote: In these 7 patches: 1. perf is able to put values into map: # perf record -e mybpf.c/maps.values.value=1234/ ... 2. perf is able to control different slots in a map separately: # perf record -e mybpf.c/maps.values.value[1,4-6]=1234,maps.values.val

Re: [RFC PATCH 0/7] perf tools: Config BPF maps through perf cmdline

2015-10-17 Thread Alexei Starovoitov
On 10/17/15 4:58 PM, Wangnan (F) wrote: Can I translate these words into an acked-by? sorry nope. acks for implementation, but I didn't review it yet. And what's your PERF_COUNT_SW_BPF_OUTPUT going on? I think based on this patchset you can test it with perf now. few more lines would still

Re: [PATCH V5 1/1] bpf: control events stored in PERF_EVENT_ARRAY maps trace data output when perf sampling

2015-10-20 Thread Alexei Starovoitov
On 10/20/15 12:22 AM, Kaixu Xia wrote: diff --git a/kernel/events/core.c b/kernel/events/core.c index b11756f..5219635 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6337,6 +6337,9 @@ static int __perf_event_overflow(struct perf_event *event, irq_work_queue(&even

[PATCH net-next 0/3] bpf_perf_event_output helper

2015-10-20 Thread Alexei Starovoitov
takes different approach by letting user space open independent PERF_COUNT_SW_BPF_OUTPUT events, so that program output won't collide. Wangnan is working on corresponding perf patches. Alexei Starovoitov (3): perf: pad raw data samples automatically bpf: introduce bpf_perf_event_output() h

[PATCH net-next 2/3] bpf: introduce bpf_perf_event_output() helper

2015-10-20 Thread Alexei Starovoitov
dedicated channel into user space for post-processing of the raw data collected. Signed-off-by: Alexei Starovoitov --- include/uapi/linux/bpf.h| 11 ++ include/uapi/linux/perf_event.h |1 + kernel/bpf/arraymap.c |2 ++ kernel/bpf/verifier.c |3

[PATCH net-next 3/3] samples: bpf: add bpf_perf_event_output example

2015-10-20 Thread Alexei Starovoitov
Performance test and example of bpf_perf_event_output(). kprobe is attached to sys_write() and trivial bpf program streams pid+cookie into userspace via PERF_COUNT_SW_BPF_OUTPUT event. Usage: $ sudo ./bld_x64/samples/bpf/trace_output recv 2968913 events per sec Signed-off-by: Alexei Starovoitov

[PATCH net-next 1/3] perf: pad raw data samples automatically

2015-10-20 Thread Alexei Starovoitov
Instead of WARN_ON in perf_event_output() on unpaded raw samples, pad them automatically. Signed-off-by: Alexei Starovoitov --- kernel/events/core.c | 15 ++- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index

Re: [PATCH net-next 2/3] bpf: introduce bpf_perf_event_output() helper

2015-10-21 Thread Alexei Starovoitov
On 10/21/15 5:06 AM, Peter Zijlstra wrote: PERF_COUNT_SW_DUMMY = 9, >+ PERF_COUNT_SW_BPF_OUTPUT= 10, > >PERF_COUNT_SW_MAX, /* non-ABI */ > }; Do you really need the new type? Can't you use DUMMY for this? It works fine wit

Re: [RFC PATCH] bpf: Add new bpf map type for timer

2015-10-21 Thread Alexei Starovoitov
On 10/21/15 3:02 AM, He Kuang wrote: Here's a hypothetical scenario to illustrate the use of timer map. A video frame is updated between frame_refresh_start() and frame_refresh_end(), in most cases, the interval between these two functions is less than 40ms, but occasionally over 200ms. We can

Re: [PATCH net-next 2/3] bpf: introduce bpf_perf_event_output() helper

2015-10-21 Thread Alexei Starovoitov
On 10/21/15 4:05 AM, Wangnan (F) wrote: I think we can make perf output raw data hexadamically at first. that would be my suggestion as well. print it as hex first and when llvm type info is available you can teach perf to be smarter. We're working on support for this feature in iovisor/bcc wit

Re: [PATCH V5 1/1] bpf: control events stored in PERF_EVENT_ARRAY maps trace data output when perf sampling

2015-10-21 Thread Alexei Starovoitov
On 10/21/15 9:57 AM, Peter Zijlstra wrote: In summary, your either-or logic doesn't hold in BPF world. A BPF >program can only access perf event in a highly restricted way. We >don't allow it calling perf_event_read_local() across core, so it >can't. That's actually broken. My fault as well, si

[PATCH net-next] bpf: fix bpf_perf_event_read() helper

2015-10-21 Thread Alexei Starovoitov
quot;bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter") Signed-off-by: Alexei Starovoitov --- This patch is on top of http://patchwork.ozlabs.org/patch/533585/ to avoid conflicts. Even in the worst case the crash is not possible. Only warn_on_once, so imo n

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-21 Thread Alexei Starovoitov
On 10/21/15 11:34 AM, Thomas Graf wrote: So far, during this discussion, it was proposed to modify the file system >to a single-mount one and to stick this under/sys/kernel/bpf/. This >will not have "real" namespace support either, but it was proposed to >have a following structure: > > /sys/ke

[PATCH v2 net-next] bpf: fix bpf_perf_event_read() helper

2015-10-21 Thread Alexei Starovoitov
quot;bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter") Signed-off-by: Alexei Starovoitov --- v1->v2: fix compile in case of !CONFIG_PERF_EVENTS This patch is on top of http://patchwork.ozlabs.org/patch/533585/ to avoid conflicts. Even in the worst c

Re: [PATCH V5 1/1] bpf: control events stored in PERF_EVENT_ARRAY maps trace data output when perf sampling

2015-10-21 Thread Alexei Starovoitov
On 10/21/15 6:56 PM, Wangnan (F) wrote: One alternative solution I can image is to attach a BPF program at sampling like kprobe, and return 0 if we don't want sampling take action. Thought? Do you think attaching BPF programs to sampling is an acceptable idea? If you mean to extend 'filter' c

Re: [PATCH V5 1/1] bpf: control events stored in PERF_EVENT_ARRAY maps trace data output when perf sampling

2015-10-21 Thread Alexei Starovoitov
On 10/21/15 8:12 PM, Wangnan (F) wrote: On 2015/10/22 11:09, Alexei Starovoitov wrote: On 10/21/15 6:56 PM, Wangnan (F) wrote: One alternative solution I can image is to attach a BPF program at sampling like kprobe, and return 0 if we don't want sampling take action. Thought? Do you

Re: [PATCH v2 net-next] bpf: fix bpf_perf_event_read() helper

2015-10-21 Thread Alexei Starovoitov
On 10/21/15 9:49 PM, Wangnan (F) wrote: After applying this patch I'm unable to use perf passing perf_event again like this: please do not top post and trim your replies. # perf record -a -e evt=cycles -e ./test_config_map.c/maps.pmu_map.event=evt/ --exclude-perf ls With -v it output: ...

Re: [PATCH v2 net-next] bpf: fix bpf_perf_event_read() helper

2015-10-21 Thread Alexei Starovoitov
On 10/21/15 10:31 PM, Wangnan (F) wrote: +if ((attr->type != PERF_TYPE_RAW && + !(attr->type == PERF_TYPE_SOFTWARE && + attr->config == PERF_COUNT_SW_BPF_OUTPUT) && + attr->type != PERF_TYPE_HARDWARE) || +attr->inherit) { This 'if' statement is so complex.

Re: [PATCH net-next 2/3] bpf: introduce bpf_perf_event_output() helper

2015-10-22 Thread Alexei Starovoitov
On 10/22/15 6:59 AM, Peter Zijlstra wrote: + if (unlikely(event->oncpu != smp_processor_id())) >+ return -EOPNOTSUPP; >+ >+ perf_sample_data_init(&sample_data, 0, 0); >+ sample_data.raw = &raw; >+ perf_event_output(event, &sample_data, regs); >+ return 0; >+} Note that th

Re: [PATCH v2 net-next] bpf: fix bpf_perf_event_read() helper

2015-10-22 Thread Alexei Starovoitov
On 10/22/15 12:39 AM, Wangnan (F) wrote: ... if (!perf_event_can_insert_to_map(attr)) Do you think redability is improved? yes. makes sense. will respin. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.

Re: [PATCH v2 net-next] bpf: fix bpf_perf_event_read() helper

2015-10-22 Thread Alexei Starovoitov
On 10/22/15 6:57 AM, Peter Zijlstra wrote: On Wed, Oct 21, 2015 at 03:58:03PM -0700, Alexei Starovoitov wrote: diff --git a/kernel/events/core.c b/kernel/events/core.c index 64754bfecd70..0b6333265872 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3258,7 +3258,7 @@ static

[PATCH v3 net-next] bpf: fix bpf_perf_event_read() helper

2015-10-22 Thread Alexei Starovoitov
ter perf_event_attrs() and remove redundant 'extern'. Fixes: 35578d798400 ("bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter") Signed-off-by: Alexei Starovoitov --- v2->v3: . refactor checks based on Wangnan's and Peter's feed

Re: eBPF / seccomp globals?

2015-09-03 Thread Alexei Starovoitov
On Fri, Sep 04, 2015 at 01:01:20AM +, Michael Tirado wrote: > Hiyall, > > I have created a seccomp white list filter for a program that launches > other less trustworthy programs. It's working great so far, but I > have run into a little roadblock. the launcher program needs to call > execve

Re: [PATCH 1/6] ebpf: add a seccomp program type

2015-09-04 Thread Alexei Starovoitov
On Fri, Sep 04, 2015 at 10:04:19AM -0600, Tycho Andersen wrote: > seccomp uses eBPF as its underlying storage and execution format, and eBPF > has features that seccomp would like to make use of in the future. This > patch adds a formal seccomp type to the eBPF verifier. > > The current implementa

Re: [PATCH 3/6] ebpf: add a way to dump an eBPF program

2015-09-04 Thread Alexei Starovoitov
; > Signed-off-by: Tycho Andersen > CC: Kees Cook > CC: Will Drewry > CC: Oleg Nesterov > CC: Andy Lutomirski > CC: Pavel Emelyanov > CC: Serge E. Hallyn > CC: Alexei Starovoitov > CC: Daniel Borkmann > --- > include/uapi/linux/b

Re: [PATCH 4/6] seccomp: add a way to access filters via bpf fds

2015-09-04 Thread Alexei Starovoitov
On Fri, Sep 04, 2015 at 01:26:42PM -0700, Kees Cook wrote: > On Fri, Sep 4, 2015 at 9:04 AM, Tycho Andersen > wrote: > > This patch adds a way for a process that is "real root" to access the > > seccomp filters of another process. The process first does a > > PTRACE_SECCOMP_GET_FILTER_FD to get an

Re: [PATCH 5/6] seccomp: add a way to attach a filter via eBPF fd

2015-09-04 Thread Alexei Starovoitov
On Fri, Sep 04, 2015 at 10:04:23AM -0600, Tycho Andersen wrote: > This is the final bit needed to support seccomp filters created via the bpf > syscall. > > One concern with this patch is exactly what the interface should look like > for users, since seccomp()'s second argument is a pointer, we co

Re: [PATCH 3/6] ebpf: add a way to dump an eBPF program

2015-09-04 Thread Alexei Starovoitov
On Fri, Sep 04, 2015 at 01:50:55PM -0700, Kees Cook wrote: > On Fri, Sep 4, 2015 at 1:45 PM, Tycho Andersen > wrote: > > On Fri, Sep 04, 2015 at 01:17:30PM -0700, Kees Cook wrote: > >> On Fri, Sep 4, 2015 at 9:04 AM, Tycho Andersen > >> wrote: > >> > This commit adds a way to dump eBPF programs.

Re: [PATCH 6/6] ebpf: allow BPF_REG_X in src_reg conditional jumps

2015-09-04 Thread Alexei Starovoitov
On Fri, Sep 04, 2015 at 10:04:24AM -0600, Tycho Andersen wrote: > The classic converter generates conditional jumps with: > > if (BPF_SRC(fp->code) == BPF_K && (int) fp->k < 0) { > ... > } else { > insn->dst_reg = BPF_REG_A; > insn->src_reg = BPF_REG_X; > insn->imm

Re: [PATCH 6/6] ebpf: allow BPF_REG_X in src_reg conditional jumps

2015-09-04 Thread Alexei Starovoitov
On Fri, Sep 04, 2015 at 04:43:50PM -0600, Tycho Andersen wrote: > > The fix should be something like this: > > diff --git a/net/core/filter.c b/net/core/filter.c > > index 13079f03902e..05a04ea87172 100644 > > --- a/net/core/filter.c > > +++ b/net/core/filter.c > > @@ -478,9 +478,9 @@ do_pass: > >

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-17 Thread Alexei Starovoitov
On 10/17/15 5:28 AM, Daniel Borkmann wrote: Anyway, another idea I've been brainstorming with Hannes today a bit is about the following: We register two major numbers, one for eBPF maps (X), one for eBPF progs (Y). A user can either via cmdline call something like ... mknod /dev/bpf/maps/map_pk

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-18 Thread Alexei Starovoitov
On 10/18/15 9:49 AM, Daniel Borkmann wrote: Okay, I have pushed some rough working proof of concept here: https://git.breakpoint.cc/cgit/dborkman/net-next.git/log/?h=ebpf-fds-final5 So the idea eventually had to be slightly modified after giving this further thoughts and is the following: We h

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-19 Thread Alexei Starovoitov
On 10/19/15 7:23 AM, Daniel Borkmann wrote: The mknod is not the holder but rather the kobject which should be represented in sysfs will be. So you can still get the map major:minor by looking up the /dev file in the correspdonding sysfs directory or I think we should provide a 'unbind' file, whi

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-19 Thread Alexei Starovoitov
On 10/19/15 10:37 AM, Daniel Borkmann wrote: An eBPF program or map loading/destruction is *not* by any means to be considered fast-path. We currently hold a global mutex during loading. So, how can that be considered fast-path? Similarly, socket creation/ destruction is also not fast-path, etc.

Re: [RFC] bpf: change bpf syacall to use u64 temp variables

2015-10-19 Thread Alexei Starovoitov
On Mon, Oct 19, 2015 at 03:10:46PM +0800, yalin wang wrote: > This patch change map_lookup_elem() and map_update_elem() function > to use u64 temp variable if the key_size or value_size is less than > u64, we don't need use kmalloc() for these small variables. > > Signed-off-by: yalin wang > ---

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-19 Thread Alexei Starovoitov
On 10/19/15 11:46 AM, Hannes Frederic Sowa wrote: Hi, On Mon, Oct 19, 2015, at 20:15, Alexei Starovoitov wrote: On 10/19/15 10:37 AM, Daniel Borkmann wrote: An eBPF program or map loading/destruction is *not* by any means to be considered fast-path. We currently hold a global mutex during

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-19 Thread Alexei Starovoitov
On 10/19/15 1:03 PM, Hannes Frederic Sowa wrote: I doubt it will stay a lightweight feature as it should not be in the responsibility of user space to provide those debug facilities. It feels we're talking past each other. I want to solve 'persistent map' problem. debugging of maps/progs, hier

Re: [PATCH net-next 3/4] bpf: add support for persistent maps/progs

2015-10-19 Thread Alexei Starovoitov
On 10/19/15 3:17 PM, Daniel Borkmann wrote: On 10/19/2015 10:48 PM, Alexei Starovoitov wrote: On 10/19/15 1:03 PM, Hannes Frederic Sowa wrote: I doubt it will stay a lightweight feature as it should not be in the responsibility of user space to provide those debug facilities. It feels we&#x

<    1   2   3   4   5   6   7   8   9   10   >