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 strncpy() for uns

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

2015-08-27 Thread Steven Rostedt
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 strncpy() > for unsafe kernel pointers. > > You p

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

2015-08-27 Thread David Miller
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 strncpy() for unsafe kernel pointers. You probably won't be the last person to want this, and it's silly to optimize it in o

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 David Miller
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--; > + for (;;) { > + i

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

2015-08-26 Thread Alexei Starovoitov
%s specifier makes bpf program and kernel debugging easier. To make sure that trace_printk won't crash the unsafe string is copied into stack and unsafe pointer is substituted. String is also sanitized for printable characters. The cost of swapping FS in probe_kernel_read is amortized over 4 chars