• Kirill Smelkov's avatar
    bpf_probe_read*: src argument should be const void *. · e628b509
    Kirill Smelkov authored
    For the following program:
    
        #include <linux/interrupt.h>
    
        // remember t(last-interrupt) on interface
        int kprobe__handle_irq_event_percpu(struct pt_regs *ctx, struct irq_desc *desc) {
            const char *irqname = desc->action->name;
    
            char c;
    
            bpf_probe_read(&c, 1, &irqname[0]);
            if (c != 'e') return 0;
    
            bpf_probe_read(&c, 1, &irqname[1]);
            if (c != 't') return 0;
    
            ...
    
    LLVM gives warnings because irqaction->name is `const char *`:
    
        /virtual/main.c:10:27: warning: passing 'const char *' to parameter of type 'void *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
            bpf_probe_read(&c, 1, &irqname[0]);
                                  ^~~~~~~~~~~
        /virtual/main.c:13:27: warning: passing 'const char *' to parameter of type 'void *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
            bpf_probe_read(&c, 1, &irqname[1]);
                                  ^~~~~~~~~~~
        ...
    
    Instead of adding casts in source everywhere fix bpf_probe_read* signature to
    indicate the memory referenced by src won't be modified, as it should be.
    
    P.S.
    
    bpf_probe_read_str was in fact already marked so in several places in comments
    but not in actual signature.
    e628b509
bpf.h 23.8 KB