From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5209CC433F5 for ; Wed, 24 Nov 2021 08:49:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233104AbhKXIw5 (ORCPT ); Wed, 24 Nov 2021 03:52:57 -0500 Received: from szxga08-in.huawei.com ([45.249.212.255]:28101 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229825AbhKXIw5 (ORCPT ); Wed, 24 Nov 2021 03:52:57 -0500 Received: from dggpeml500025.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4HzZPs5w9Vz1DJWN; Wed, 24 Nov 2021 16:47:13 +0800 (CST) Received: from [10.174.176.117] (10.174.176.117) by dggpeml500025.china.huawei.com (7.185.36.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 24 Nov 2021 16:49:45 +0800 Subject: Re: [RFC] [PATCH bpf-next 1/1] bpf: Clear the noisy tail buffer for bpf_d_path() helper To: xufeng zhang , , CC: , , , , , References: <20211120051839.28212-1-yunbo.xufeng@linux.alibaba.com> <20211120051839.28212-2-yunbo.xufeng@linux.alibaba.com> <9c83d1c1-f8da-8c5b-74dc-d763ab444774@linux.alibaba.com> From: Hou Tao Message-ID: <26009981-d1a4-ff37-ca60-f21a43fc7a8c@huawei.com> Date: Wed, 24 Nov 2021 16:49:45 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <9c83d1c1-f8da-8c5b-74dc-d763ab444774@linux.alibaba.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.174.176.117] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500025.china.huawei.com (7.185.36.35) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Hi, On 11/24/2021 12:15 PM, xufeng zhang wrote: > Jiri and KP, > > Any suggestion? > > > Thanks in advance! > > Xufeng > > 在 2021/11/20 下午1:18, Xufeng Zhang 写道: >> From: "Xufeng Zhang" >> >> The motivation behind this change is to use the returned full path >> for lookup keys in BPF_MAP_TYPE_HASH map. >> bpf_d_path() prepend the path string from the end of the input >> buffer, and call memmove() to copy the full path from the tail >> buffer to the head of buffer before return. So although the >> returned buffer string is NULL terminated, there is still >> noise data at the tail of buffer. >> If using the returned full path buffer as the key of hash map, >> the noise data is also calculated and makes map lookup failed. >> To resolve this problem, we could memset the noisy tail buffer >> before return. >> >> Signed-off-by: Xufeng Zhang >> --- >>   kernel/trace/bpf_trace.c | 2 ++ >>   1 file changed, 2 insertions(+) >> >> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c >> index 25ea521fb8f1..ec4a6823c024 100644 >> --- a/kernel/trace/bpf_trace.c >> +++ b/kernel/trace/bpf_trace.c >> @@ -903,6 +903,8 @@ BPF_CALL_3(bpf_d_path, struct path *, path, char *, buf, >> u32, sz) >>       } else { >>           len = buf + sz - p; >>           memmove(buf, p, len); >> +        /* Clear the noisy tail buffer before return */ >> +        memset(buf + len, 0, sz - len); Is implementing bpf_memset() helper a better idea ? So those who need to clear the buffer after the terminated null character can use the helper to do that. Regards, Tao >>       } >>         return len; > .