bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	kernel-team@fb.com
Subject: Re: [PATCH bpf 2/2] selftests/bpf: add a fexit/bpf2bpf test with target bpf prog no callees
Date: Wed, 4 Dec 2019 21:37:02 -0800	[thread overview]
Message-ID: <20191205053700.7e6oxm77zjypbrik@ast-mbp.dhcp.thefacebook.com> (raw)
In-Reply-To: <20191205010607.177904-1-yhs@fb.com>

On Wed, Dec 04, 2019 at 05:06:07PM -0800, Yonghong Song wrote:
>  
> -	obj = bpf_object__open_file("./fexit_bpf2bpf.o", &opts);
> +	obj = bpf_object__open_file(obj_file, &opts);
>  	if (CHECK(IS_ERR_OR_NULL(obj), "obj_open",
>  		  "failed to open fexit_bpf2bpf: %ld\n",
>  		  PTR_ERR(obj)))
> @@ -38,7 +34,14 @@ void test_fexit_bpf2bpf(void)
>  	if (CHECK(err, "obj_load", "err %d\n", err))
>  		goto close_prog;
>  
> -	for (i = 0; i < PROG_CNT; i++) {
> +	link = calloc(sizeof(struct bpf_link *), prog_cnt);
> +	prog = calloc(sizeof(struct bpf_program *), prog_cnt);
> +	result = malloc(prog_cnt * sizeof(u64));
> +	if (CHECK(!link || !prog || !result, "alloc_memory",
> +		  "failed to alloc memory"))
> +		goto close_prog;

bpf_object__open_file() can fail when jit is off and for() loop in close_prog
will segfault. I fixed it up by moving above 3 mallocs before
bpf_object__open_file() and applied both patches. Thanks!


      reply	other threads:[~2019-12-05  5:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-05  1:06 [PATCH bpf 0/2] fix a verifier bug in check_attach_btf_id() Yonghong Song
2019-12-05  1:06 ` [PATCH bpf 1/2] bpf: fix a bug when getting subprog 0 jited image in check_attach_btf_id Yonghong Song
2019-12-05  5:33   ` Alexei Starovoitov
2019-12-05  1:06 ` [PATCH bpf 2/2] selftests/bpf: add a fexit/bpf2bpf test with target bpf prog no callees Yonghong Song
2019-12-05  5:37   ` Alexei Starovoitov [this message]

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=20191205053700.7e6oxm77zjypbrik@ast-mbp.dhcp.thefacebook.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=yhs@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).