* [PATCH bpf-next] bpf: arm64: fix uninitialized variable
@ 2017-12-18 18:09 Alexei Starovoitov
2017-12-18 18:19 ` Daniel Borkmann
0 siblings, 1 reply; 4+ messages in thread
From: Alexei Starovoitov @ 2017-12-18 18:09 UTC (permalink / raw)
To: David S . Miller; +Cc: Daniel Borkmann, Arnd Bergmann, netdev, kernel-team
From: Alexei Starovoitov <ast@fb.com>
fix the following issue:
arch/arm64/net/bpf_jit_comp.c: In function 'bpf_int_jit_compile':
arch/arm64/net/bpf_jit_comp.c:982:18: error: 'image_size' may be used
uninitialized in this function [-Werror=maybe-uninitialized]
Fixes: db496944fdaa ("bpf: arm64: add JIT support for multi-function programs")
Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
arch/arm64/net/bpf_jit_comp.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 396490cf7316..acaa935ed977 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -897,6 +897,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
image_ptr = jit_data->image;
header = jit_data->header;
extra_pass = true;
+ image_size = sizeof(u32) * ctx.idx;
goto skip_init_ctx;
}
memset(&ctx, 0, sizeof(ctx));
--
2.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] bpf: arm64: fix uninitialized variable
2017-12-18 18:09 [PATCH bpf-next] bpf: arm64: fix uninitialized variable Alexei Starovoitov
@ 2017-12-18 18:19 ` Daniel Borkmann
2017-12-18 18:36 ` Alexei Starovoitov
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Borkmann @ 2017-12-18 18:19 UTC (permalink / raw)
To: Alexei Starovoitov, David S . Miller; +Cc: Arnd Bergmann, netdev, kernel-team
On 12/18/2017 07:09 PM, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@fb.com>
>
> fix the following issue:
> arch/arm64/net/bpf_jit_comp.c: In function 'bpf_int_jit_compile':
> arch/arm64/net/bpf_jit_comp.c:982:18: error: 'image_size' may be used
> uninitialized in this function [-Werror=maybe-uninitialized]
>
> Fixes: db496944fdaa ("bpf: arm64: add JIT support for multi-function programs")
> Reported-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> ---
> arch/arm64/net/bpf_jit_comp.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> index 396490cf7316..acaa935ed977 100644
> --- a/arch/arm64/net/bpf_jit_comp.c
> +++ b/arch/arm64/net/bpf_jit_comp.c
> @@ -897,6 +897,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
> image_ptr = jit_data->image;
> header = jit_data->header;
> extra_pass = true;
> + image_size = sizeof(u32) * ctx.idx;
> goto skip_init_ctx;
> }
> memset(&ctx, 0, sizeof(ctx));
>
I don't really mind, but it feels more complex than it needs to be
imho, since in the initial pass you fetch 'image_size' in fake pass
from ctx.idx, then we set ctx.idx to 0 again, do another pass and
use the cached ctx.idx from that second pass instead of the first
one where we set 'image_size' originally, so we definitely need to
take that into consideration in future reviews at least.
Thanks,
Daniel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] bpf: arm64: fix uninitialized variable
2017-12-18 18:19 ` Daniel Borkmann
@ 2017-12-18 18:36 ` Alexei Starovoitov
2017-12-19 0:34 ` Daniel Borkmann
0 siblings, 1 reply; 4+ messages in thread
From: Alexei Starovoitov @ 2017-12-18 18:36 UTC (permalink / raw)
To: Daniel Borkmann, Alexei Starovoitov, David S . Miller
Cc: Arnd Bergmann, netdev, kernel-team
On 12/18/17 10:19 AM, Daniel Borkmann wrote:
> On 12/18/2017 07:09 PM, Alexei Starovoitov wrote:
>> From: Alexei Starovoitov <ast@fb.com>
>>
>> fix the following issue:
>> arch/arm64/net/bpf_jit_comp.c: In function 'bpf_int_jit_compile':
>> arch/arm64/net/bpf_jit_comp.c:982:18: error: 'image_size' may be used
>> uninitialized in this function [-Werror=maybe-uninitialized]
>>
>> Fixes: db496944fdaa ("bpf: arm64: add JIT support for multi-function programs")
>> Reported-by: Arnd Bergmann <arnd@arndb.de>
>> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
>> ---
>> arch/arm64/net/bpf_jit_comp.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
>> index 396490cf7316..acaa935ed977 100644
>> --- a/arch/arm64/net/bpf_jit_comp.c
>> +++ b/arch/arm64/net/bpf_jit_comp.c
>> @@ -897,6 +897,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
>> image_ptr = jit_data->image;
>> header = jit_data->header;
>> extra_pass = true;
>> + image_size = sizeof(u32) * ctx.idx;
>> goto skip_init_ctx;
>> }
>> memset(&ctx, 0, sizeof(ctx));
>>
>
> I don't really mind, but it feels more complex than it needs to be
> imho, since in the initial pass you fetch 'image_size' in fake pass
> from ctx.idx, then we set ctx.idx to 0 again, do another pass and
> use the cached ctx.idx from that second pass instead of the first
> one where we set 'image_size' originally, so we definitely need to
> take that into consideration in future reviews at least.
not sure what you mean.
This check: ctx.idx != jit_data->ctx.idx matters the most.
After first alloc the 'image_size' variable used for dumping only.
That's why the JITing itself worked fine. We could have removed it
since it's computable from idx, but imo it's fine this way.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] bpf: arm64: fix uninitialized variable
2017-12-18 18:36 ` Alexei Starovoitov
@ 2017-12-19 0:34 ` Daniel Borkmann
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2017-12-19 0:34 UTC (permalink / raw)
To: Alexei Starovoitov, Alexei Starovoitov, David S . Miller
Cc: Arnd Bergmann, netdev, kernel-team
On 12/18/2017 07:36 PM, Alexei Starovoitov wrote:
> On 12/18/17 10:19 AM, Daniel Borkmann wrote:
>> On 12/18/2017 07:09 PM, Alexei Starovoitov wrote:
>>> From: Alexei Starovoitov <ast@fb.com>
>>>
>>> fix the following issue:
>>> arch/arm64/net/bpf_jit_comp.c: In function 'bpf_int_jit_compile':
>>> arch/arm64/net/bpf_jit_comp.c:982:18: error: 'image_size' may be used
>>> uninitialized in this function [-Werror=maybe-uninitialized]
>>>
>>> Fixes: db496944fdaa ("bpf: arm64: add JIT support for multi-function programs")
>>> Reported-by: Arnd Bergmann <arnd@arndb.de>
>>> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
>>> ---
>>> arch/arm64/net/bpf_jit_comp.c | 1 +
>>> 1 file changed, 1 insertion(+)
>>>
>>> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
>>> index 396490cf7316..acaa935ed977 100644
>>> --- a/arch/arm64/net/bpf_jit_comp.c
>>> +++ b/arch/arm64/net/bpf_jit_comp.c
>>> @@ -897,6 +897,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
>>> image_ptr = jit_data->image;
>>> header = jit_data->header;
>>> extra_pass = true;
>>> + image_size = sizeof(u32) * ctx.idx;
>>> goto skip_init_ctx;
>>> }
>>> memset(&ctx, 0, sizeof(ctx));
>>
>> I don't really mind, but it feels more complex than it needs to be
>> imho, since in the initial pass you fetch 'image_size' in fake pass
>> from ctx.idx, then we set ctx.idx to 0 again, do another pass and
>> use the cached ctx.idx from that second pass instead of the first
>> one where we set 'image_size' originally, so we definitely need to
>> take that into consideration in future reviews at least.
>
> not sure what you mean.
> This check: ctx.idx != jit_data->ctx.idx matters the most.
> After first alloc the 'image_size' variable used for dumping only.
> That's why the JITing itself worked fine. We could have removed it
> since it's computable from idx, but imo it's fine this way.
Fair enough, given final ctx.idx value must be guaranteed to never change
in future between pass#1 and pass#2 from the first bpf_int_jit_compile()
run, then lets go with this smaller version; applied to bpf-next, thanks
Alexei!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-12-19 0:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-18 18:09 [PATCH bpf-next] bpf: arm64: fix uninitialized variable Alexei Starovoitov
2017-12-18 18:19 ` Daniel Borkmann
2017-12-18 18:36 ` Alexei Starovoitov
2017-12-19 0:34 ` Daniel Borkmann
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).