bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xufeng Zhang <yunbo.xufeng@linux.alibaba.com>
To: jolsa@kernel.org, kpsingh@google.com, andriin@fb.com,
	ast@kernel.org, daniel@iogearbox.net, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: netdev@vger.kernel.org, yunbo.xufeng@linux.alibaba.com
Subject: [RFC] [PATCH bpf-next 1/1] bpf: Clear the noisy tail buffer for bpf_d_path() helper
Date: Sat, 20 Nov 2021 13:18:39 +0800	[thread overview]
Message-ID: <20211120051839.28212-2-yunbo.xufeng@linux.alibaba.com> (raw)
In-Reply-To: <20211120051839.28212-1-yunbo.xufeng@linux.alibaba.com>

From: "Xufeng Zhang" <yunbo.xufeng@linux.alibaba.com>

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 <yunbo.xufeng@linux.alibaba.com>
---
 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);
 	}
 
 	return len;
-- 
2.20.1 (Apple Git-117)


  reply	other threads:[~2021-11-20  5:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-20  5:18 [RFC] [PATCH bpf-next 0/1] Enhancement for bpf_do_path() helper Xufeng Zhang
2021-11-20  5:18 ` Xufeng Zhang [this message]
2021-11-24  4:15   ` [RFC] [PATCH bpf-next 1/1] bpf: Clear the noisy tail buffer for bpf_d_path() helper xufeng zhang
2021-11-24  8:49     ` Hou Tao
2021-11-25  1:47       ` xufeng zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211120051839.28212-2-yunbo.xufeng@linux.alibaba.com \
    --to=yunbo.xufeng@linux.alibaba.com \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).