From: Jamal Hadi Salim <jhs@mojatatu.com>
To: Dominique Martinet <asmadeus@codewreck.org>
Cc: stephen@networkplumber.org, netdev@vger.kernel.org,
dsahern@gmail.com, aclaudi@redhat.com, daniel@iogearbox.net,
Jamal Hadi Salim <hadi@mojatatu.com>
Subject: Re: [PATCH iproute2 1/1] bpf: Fix segfault when custom pinning is used
Date: Wed, 22 Apr 2020 05:47:47 -0400 [thread overview]
Message-ID: <8766e548-5486-8228-f583-e5d501a41aec@mojatatu.com> (raw)
In-Reply-To: <20200422064215.GA17201@nautica>
On 2020-04-22 2:42 a.m., Dominique Martinet wrote:
> (random review)
>
Good review;->
> Jamal Hadi Salim wrote on Tue, Apr 21, 2020:
>> diff --git a/lib/bpf.c b/lib/bpf.c
>> index 10cf9bf4..cf636c9e 100644
>> --- a/lib/bpf.c
>> +++ b/lib/bpf.c
>> @@ -1509,12 +1509,12 @@ out:
>> static int bpf_make_custom_path(const struct bpf_elf_ctx *ctx,
>> const char *todo)
>> {
>> - char *tmp = NULL;
>> + char tmp[PATH_MAX] = {};
>> char *rem = NULL;
>> char *sub;
>> int ret;
>>
>> - ret = asprintf(&tmp, "%s/../", bpf_get_work_dir(ctx->type));
>> + ret = sprintf(tmp, "%s/../", bpf_get_work_dir(ctx->type));
>> if (ret < 0) {
>> fprintf(stderr, "asprintf failed: %s\n", strerror(errno));
>
> error check needs to be reworded,
Will reword.
and it probably needs to use snprintf
> instead of sprintf: bpf_get_work_dir() can be up to PATH_MAX long and as
> pointed out there are strcat() afterwards so it's still possible to
> overflow this one
>
and change to snprintf. The strcat afterwards is protected by the check
if (strlen(tmp) + strlen(sub) + 2 > PATH_MAX)
return -EINVAL;
However, since you looked at it now that i am paying closer attention
there's another bug there. The above check will return without freeing
earlier asprintf allocated "rem" variable. Sounds like separate patch.
cheers,
jamal
prev parent reply other threads:[~2020-04-22 9:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-21 18:04 [PATCH iproute2 1/1] bpf: Fix segfault when custom pinning is used Jamal Hadi Salim
2020-04-21 19:38 ` Andrea Claudi
2020-04-21 19:58 ` Jamal Hadi Salim
2020-04-21 22:10 ` Andrea Claudi
2020-04-22 6:42 ` Dominique Martinet
2020-04-22 9:47 ` Jamal Hadi Salim [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=8766e548-5486-8228-f583-e5d501a41aec@mojatatu.com \
--to=jhs@mojatatu.com \
--cc=aclaudi@redhat.com \
--cc=asmadeus@codewreck.org \
--cc=daniel@iogearbox.net \
--cc=dsahern@gmail.com \
--cc=hadi@mojatatu.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.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