[llvm-bugs] [Bug 43843] New: clang BPF wrong code generation, if branch

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Oct 29 20:42:29 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43843

            Bug ID: 43843
           Summary: clang BPF wrong code generation, if branch
           Product: clang
           Version: 9.0
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: eugene.loh at oracle.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Created attachment 22746
  --> https://bugs.llvm.org/attachment.cgi?id=22746&action=edit
sample C code + script to see assembly + script to try with BPF verifier

A sample C code seems to lead to incorrect code generation.  The code is
basically

    int foo() {
        unsigned long long ptr1, ptr2, in[2];
        char out[256];

        ptr1 = ((unsigned long long) out) + 16;
        if (ptr1)
                bpf_probe_read((void *) ptr1, 16, (const void *) in);

        ptr2 = ((unsigned long long) out) + 32;
        if (ptr2)
                bpf_probe_read((void *) ptr2, 16, (const void *) in);

        return 0;
    }

The "if (ptr)" branches should always be taken.  These code paths seem to be
generated correctly.

If either "ptr*" is 0, however, the generated code is bad.  That shouldn't
matter, but for BPF the BPF verifier analyzes those paths and ends up rejecting
legitimate code.

I'm attaching an example.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191030/a2ff063b/attachment.html>


More information about the llvm-bugs mailing list