From: Lorenz Bauer <lmb@cloudflare.com>
To: bpf@vger.kernel.org, netdev@vger.kernel.org, ast@kernel.org,
daniel@iogearbox.net, kafai@fb.com
Cc: Lorenz Bauer <lmb@cloudflare.com>
Subject: [PATCH bpf v2] selftests: bpf: initialize bpf_object pointers where needed
Date: Wed, 8 May 2019 17:49:32 +0100 [thread overview]
Message-ID: <20190508164932.28729-1-lmb@cloudflare.com> (raw)
In-Reply-To: <20190502154932.14698-1-lmb@cloudflare.com>
There are a few tests which call bpf_object__close on uninitialized
bpf_object*, which may segfault. Explicitly zero-initialise these pointers
to avoid this.
Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
---
tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c | 2 +-
tools/testing/selftests/bpf/prog_tests/task_fd_query_tp.c | 2 +-
tools/testing/selftests/bpf/prog_tests/tp_attach_query.c | 3 +++
3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c b/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c
index 23b159d95c3f..b74e2f6e96d0 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c
@@ -15,7 +15,7 @@ static int libbpf_debug_print(enum libbpf_print_level level,
static int check_load(const char *file)
{
struct bpf_prog_load_attr attr;
- struct bpf_object *obj;
+ struct bpf_object *obj = NULL;
int err, prog_fd;
memset(&attr, 0, sizeof(struct bpf_prog_load_attr));
diff --git a/tools/testing/selftests/bpf/prog_tests/task_fd_query_tp.c b/tools/testing/selftests/bpf/prog_tests/task_fd_query_tp.c
index d636a4f39476..f9b70e81682b 100644
--- a/tools/testing/selftests/bpf/prog_tests/task_fd_query_tp.c
+++ b/tools/testing/selftests/bpf/prog_tests/task_fd_query_tp.c
@@ -9,7 +9,7 @@ static void test_task_fd_query_tp_core(const char *probe_name,
struct perf_event_attr attr = {};
__u64 probe_offset, probe_addr;
__u32 len, prog_id, fd_type;
- struct bpf_object *obj;
+ struct bpf_object *obj = NULL;
__u32 duration = 0;
char buf[256];
diff --git a/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c b/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c
index a2f476f91637..fb095e5cd9af 100644
--- a/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c
+++ b/tools/testing/selftests/bpf/prog_tests/tp_attach_query.c
@@ -13,6 +13,9 @@ void test_tp_attach_query(void)
struct bpf_prog_info prog_info;
char buf[256];
+ for (i = 0; i < num_progs; i++)
+ obj[i] = NULL;
+
snprintf(buf, sizeof(buf),
"/sys/kernel/debug/tracing/events/sched/sched_switch/id");
efd = open(buf, O_RDONLY, 0);
--
2.19.1
next prev parent reply other threads:[~2019-05-08 16:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-02 15:49 [PATCH bpf] libbpf: always NULL out pobj in bpf_prog_load_xattr Lorenz Bauer
2019-05-02 16:03 ` Martin Lau
2019-05-07 9:09 ` Lorenz Bauer
2019-05-08 16:49 ` Lorenz Bauer [this message]
2019-05-09 15:56 ` [PATCH bpf v2] selftests: bpf: initialize bpf_object pointers where needed Martin Lau
2019-05-09 23:01 ` Alexei Starovoitov
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=20190508164932.28729-1-lmb@cloudflare.com \
--to=lmb@cloudflare.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kafai@fb.com \
--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).