From: Alexei Starovoitov <ast@fb.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next] bpftool: Add debug mode for gen_loader.
Date: Sun, 5 Dec 2021 13:37:55 -0800 [thread overview]
Message-ID: <a4030b10-c7c7-cf3f-59df-34601300c7ff@fb.com> (raw)
In-Reply-To: <CAEf4BzZz=QSEqGWQaqjh73Mjd0Zk+f2vsDN0Goa+k3ooefHYDA@mail.gmail.com>
On 12/5/21 11:42 AM, Andrii Nakryiko wrote:
>>
>> diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
>> index e47e8b06cc3d..b9f42e9e9067 100644
>> --- a/tools/bpf/bpftool/prog.c
>> +++ b/tools/bpf/bpftool/prog.c
>> @@ -1779,12 +1779,14 @@ static int try_loader(struct gen_loader_opts *gen)
>> ctx = alloca(ctx_sz);
>> memset(ctx, 0, ctx_sz);
>> ctx->sz = ctx_sz;
>> - ctx->log_level = 1;
>> - ctx->log_size = log_buf_sz;
>> - log_buf = malloc(log_buf_sz);
>> - if (!log_buf)
>> - return -ENOMEM;
>> - ctx->log_buf = (long) log_buf;
>> + if (verifier_logs) {
>> + ctx->log_level = 1 + 2 + 4;
>> + ctx->log_size = log_buf_sz;
>> + log_buf = malloc(log_buf_sz);
>
> if verifier_logs is false, log_buf will now be left uninitialized and
> passed like that into free(log_buf), crashing or corrupting memory.
> I've fixed it up by NULL initializaing and pushed to bpf-next.
Indeed. Weird that compiler didn't complain and bpftool didn't crash.
Thanks!
prev parent reply other threads:[~2021-12-05 21:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-04 19:46 [PATCH bpf-next] bpftool: Add debug mode for gen_loader Alexei Starovoitov
2021-12-05 19:42 ` Andrii Nakryiko
2021-12-05 21: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=a4030b10-c7c7-cf3f-59df-34601300c7ff@fb.com \
--to=ast@fb.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=kernel-team@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