]> git.baikalelectronics.ru Git - kernel.git/commit
samples: bpf: fix: error handling regarding kprobe_events
authorDaniel T. Lee <danieltimlee@gmail.com>
Thu, 22 Nov 2018 22:14:32 +0000 (07:14 +0900)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 23 Nov 2018 21:39:09 +0000 (22:39 +0100)
commit62a47d2d24398824aae9e2c3e9e6570d28e9e00f
tree72fea5da76482d9ac423333018aa6868839d98ab
parentd2c716de7512e84211783889e45300a9f4335572
samples: bpf: fix: error handling regarding kprobe_events

Currently, kprobe_events failure won't be handled properly.
Due to calling system() indirectly to write to kprobe_events,
it can't be identified whether an error is derived from kprobe or system.

    // buf = "echo '%c:%s %s' >> /s/k/d/t/kprobe_events"
    err = system(buf);
    if (err < 0) {
        printf("failed to create kprobe ..");
        return -1;
    }

For example, running ./tracex7 sample in ext4 partition,
"echo p:open_ctree open_ctree >> /s/k/d/t/kprobe_events"
gets 256 error code system() failure.
=> The error comes from kprobe, but it's not handled correctly.

According to man of system(3), it's return value
just passes the termination status of the child shell
rather than treating the error as -1. (don't care success)

Which means, currently it's not working as desired.
(According to the upper code snippet)

    ex) running ./tracex7 with ext4 env.
    # Current Output
    sh: echo: I/O error
    failed to open event open_ctree

    # Desired Output
    failed to create kprobe 'open_ctree' error 'No such file or directory'

The problem is, error can't be verified whether from child ps
or system. But using write() directly can verify the command
failure, and it will treat all error as -1. So I suggest using
write() directly to 'kprobe_events' rather than calling system().

Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
samples/bpf/bpf_load.c