Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753944AbbH0XGT (ORCPT ); Thu, 27 Aug 2015 19:06:19 -0400 Received: from mail-yk0-f174.google.com ([209.85.160.174]:34692 "EHLO mail-yk0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752669AbbH0XGR (ORCPT ); Thu, 27 Aug 2015 19:06:17 -0400 Subject: Re: [PATCH net-next] bpf: add support for %s specifier to bpf_trace_printk() To: David Miller References: <1440656819-25622-1-git-send-email-ast@plumgrid.com> <20150827.153409.893765406170260565.davem@davemloft.net> Cc: mingo@kernel.org, rostedt@goodmis.org, wangnan0@huawei.com, hekuang@huawei.com, daniel@iogearbox.net, brendan.d.gregg@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org From: Alexei Starovoitov Message-ID: <55DF97E6.9050108@plumgrid.com> Date: Thu, 27 Aug 2015 16:06:14 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <20150827.153409.893765406170260565.davem@davemloft.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1353 Lines: 35 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--; >> + for (;;) { >> + if (probe_kernel_read(dst, (void *) unsafe_ptr, 4)) >> + break; > > I don't think this does the right thing when the string is not a multiple > of 3 and ends at the last byte of a page that ends a valid region of > kernel memory. > > Seeing this kind of error makes me skeptical to the overall value of > optimizing this :-/ I've considered the case when first two bytes are valid, but the other two are in a different page. In such case the probe_read_string() will trim the string and won't be printing these two valid bytes. I think that's very rare, so I'm picking higher performance for common case. The strings over > 64 bytes also will be trimmed to 64. It's a debugging facility, so I felt that's ok. Fair or you still think it should be per byte copy? -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/