[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <8766e548-5486-8228-f583-e5d501a41aec@mojatatu.com>
Date: Wed, 22 Apr 2020 05:47:47 -0400
From: Jamal Hadi Salim <jhs@...atatu.com>
To: Dominique Martinet <asmadeus@...ewreck.org>
Cc: stephen@...workplumber.org, netdev@...r.kernel.org,
dsahern@...il.com, aclaudi@...hat.com, daniel@...earbox.net,
Jamal Hadi Salim <hadi@...atatu.com>
Subject: Re: [PATCH iproute2 1/1] bpf: Fix segfault when custom pinning is
used
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
Powered by blists - more mailing lists