Skip to content

create-diff-object segfault #1257

@liu-song-6

Description

@liu-song-6

We hit a weird segfault on create-diff-object with a simple patch (attached at the end). It happens for gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-3), but not clang. After digging into it a little bit, I think it was caused by the following rela entry.

readelf -W -r btf.o
...
0000000000025342  0000000c00000001 R_X86_64_64            0000000000000000 .text.btf_show_name + 0
000000000002534a  0000000c00000001 R_X86_64_64            0000000000000000 .text.btf_show_name + e0
0000000000025355  000001df00000001 R_X86_64_64            000000000000000c .LC3 + 14            <<<   this one
000000000002535e  0000000c00000001 R_X86_64_64            0000000000000000 .text.btf_show_name + e0
0000000000025366  0000000c00000001 R_X86_64_64            0000000000000000 .text.btf_show_name + 1c4

How should we fix this case?

Thanks,
Song

The patch:

diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 7a7be8c057f2..5fc160288fa0 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -566,9 +566,11 @@ static inline u32 type_flag(u32 type)
        return type & ~BPF_BASE_TYPE_MASK;
 }

+/* only use after check_attach_btf_id() */
 static inline enum bpf_prog_type resolve_prog_type(struct bpf_prog *prog)
 {
-       return prog->aux->dst_prog ? prog->aux->dst_prog->type : prog->type;
+       return prog->type == BPF_PROG_TYPE_EXT ?
+               prog->aux->dst_prog->type : prog->type;
 }

 #endif /* _LINUX_BPF_VERIFIER_H */

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions