From: Yonghong Song <yonghong.song@linux.dev>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: lsf-pc <lsf-pc@lists.linux-foundation.org>,
bpf <bpf@vger.kernel.org>, "Eddy Z" <eddyz87@gmail.com>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Marc Suñé" <marc.sune@isovalent.com>
Subject: Re: [LSF/MM/BPF TOPIC] Uninitialized Variable In BPF Programs
Date: Wed, 29 Jan 2025 23:24:35 -0800 [thread overview]
Message-ID: <c1ed2a75-1978-4af5-801b-82d5fb911cae@linux.dev> (raw)
In-Reply-To: <CAADnVQKmi0+_=BMLXXyv5YaUrfDoHVb+zW1Ns6mx40wYLH83Zw@mail.gmail.com>
On 1/29/25 4:53 PM, Alexei Starovoitov wrote:
> On Tue, Jan 28, 2025 at 1:42 PM Yonghong Song <yonghong.song@linux.dev> wrote:
>> If bpf program has an uninitialized variable, clang compiler
>> may take advantage of it to do some optimization. The resulted
>> bpf program may still survive verification but get wrong result.
>> Users then may take quite some time to understand the real
>> reason by inspecting asm codes.
>>
>> The compiler flags '-Wall -Werror' are supposed to issue errors
>> if an uninitialized variable impacts the final result. But in
>> reality, since compiler may not be 100% sure a variable is
>> uninitalized due to limited analysis, the error may not be emitted.
>> gcc has '-Wmaybe-uninitialized' flag to issue warnings for some
>> possible uninit variables but still may miss some others.
>> clang does not support '-Wmaybe-uninitialized' flag.
>>
>> There are already some discussion in llvm community for this ([1]).
>> I would like to elaborate more with some examples, e.g. how llvm
>> internal handle uninit variables, and discuss how we could do
>> something to expose harmful uninit variable earlier.
>>
>> [1] https://discourse.llvm.org/t/detect-undefined-behavior-due-to-uninitialized-variables-in-bpf-programs/84116?u=yonghong-song
>>
> Compilers maliciously making advantage of unint vars is a tip
> of the iceberg. They do equally nasty "optimizations" for all
> undefined things. It's a real issue for all backends.
> We can experiment -ftrivial-auto-var-init=zero and/or
> introduce similar workarounds.
> The problem is clearly not limited to bpf.
>
> But the main concern is that this discussion cannot happen without
> llvm and gcc involvement, but only gcc folks might be present at lsfmm.
>
> We also still have an issue of missing suffixes when llvm optimizes
> funcs, compilers doing things that messes with the verifier,
> gcc is still missing decl_tag support, etc.
>
> I suggest to fold the status update (not a discussion) into one
> slot that will cover all outstanding gcc and llvm issues.
Good point. Let us discuss the progress of various compiler
related issues at once. Will coordinate with Jose etc.
prev parent reply other threads:[~2025-01-30 7:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-28 21:41 [LSF/MM/BPF TOPIC] Uninitialized Variable In BPF Programs Yonghong Song
2025-01-30 0:53 ` Alexei Starovoitov
2025-01-30 7:24 ` Yonghong Song [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=c1ed2a75-1978-4af5-801b-82d5fb911cae@linux.dev \
--to=yonghong.song@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=lsf-pc@lists.linux-foundation.org \
--cc=marc.sune@isovalent.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