netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stanislav Fomichev <sdf@google.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, ast@kernel.org, daniel@iogearbox.net,
	songliubraving@fb.com, Stanislav Fomichev <sdf@google.com>
Subject: [PATCH bpf v2 1/3] bpf: don't assume build-id length is always 20 bytes
Date: Wed, 16 Jan 2019 10:11:19 -0800	[thread overview]
Message-ID: <20190116181119.96117-1-sdf@google.com> (raw)
In-Reply-To: <0FC05078-4DF7-453E-8F36-7C0F5AF81F69@fb.com>

Build-id length is not fixed to 20, it can be (`man ld` /--build-id):
  * 128-bit (uuid)
  * 160-bit (sha1)
  * any length specified in ld --build-id=0xhexstring

To fix the issue of missing BPF_STACK_BUILD_ID_VALID for shorter build-ids,
assume that build-id is somewhere in the range of 1 .. 20.
Set the remaining bytes to zero.

v2:
* don't introduce new "len = min(BPF_BUILD_ID_SIZE, nhdr->n_descsz)",
  we already know that nhdr->n_descsz <= BPF_BUILD_ID_SIZE if we enter
  this 'if' condition

Fixes: 615755a77b24 ("bpf: extend stackmap to save binary_build_id+offset instead of address")
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 kernel/bpf/stackmap.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c
index d9e2483669d0..f9df545e92f6 100644
--- a/kernel/bpf/stackmap.c
+++ b/kernel/bpf/stackmap.c
@@ -180,11 +180,14 @@ static inline int stack_map_parse_build_id(void *page_addr,
 
 		if (nhdr->n_type == BPF_BUILD_ID &&
 		    nhdr->n_namesz == sizeof("GNU") &&
-		    nhdr->n_descsz == BPF_BUILD_ID_SIZE) {
+		    nhdr->n_descsz > 0 &&
+		    nhdr->n_descsz <= BPF_BUILD_ID_SIZE) {
 			memcpy(build_id,
 			       note_start + note_offs +
 			       ALIGN(sizeof("GNU"), 4) + sizeof(Elf32_Nhdr),
-			       BPF_BUILD_ID_SIZE);
+			       nhdr->n_descsz);
+			memset(build_id + nhdr->n_descsz, 0,
+			       BPF_BUILD_ID_SIZE - nhdr->n_descsz);
 			return 0;
 		}
 		new_offs = note_offs + sizeof(Elf32_Nhdr) +
-- 
2.20.1.97.g81188d93c3-goog


  parent reply	other threads:[~2019-01-16 18:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-15 22:54 [PATCH bpf 1/3] bpf: don't assume build-id length is always 20 bytes Stanislav Fomichev
2019-01-15 22:54 ` [PATCH bpf 2/3] bpf: zero out build_id for BPF_STACK_BUILD_ID_IP Stanislav Fomichev
2019-01-16 17:48   ` Song Liu
2019-01-15 22:54 ` [PATCH bpf 3/3] selftests/bpf: retry tests that expect build-id Stanislav Fomichev
2019-01-16 17:49   ` Song Liu
2019-01-16 17:45 ` [PATCH bpf 1/3] bpf: don't assume build-id length is always 20 bytes Song Liu
2019-01-16 17:50   ` Stanislav Fomichev
2019-01-16 18:11   ` Stanislav Fomichev [this message]
2019-01-16 18:20     ` [PATCH bpf v2 " Song Liu
2019-01-16 21:59     ` Daniel Borkmann
2019-01-16 22:01       ` Stanislav Fomichev
  -- strict thread matches above, loose matches on Subject: below --
2019-01-16 22:03 Stanislav Fomichev
2019-01-17 15:55 ` Daniel Borkmann

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=20190116181119.96117-1-sdf@google.com \
    --to=sdf@google.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    /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).