selftests/bpf: Fix test_attach_probe

Fix two issues in test_attach_probe:

1. it was not able to parse /proc/self/maps beyond the first line,
   since %s means parse string until white space.
2. offset has to be accounted for otherwise uprobed address is incorrect.

Fixes: 1e8611bbdf ("selftests/bpf: add kprobe/uprobe selftests")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20191219020442.1922617-1-ast@kernel.org
This commit is contained in:
Alexei Starovoitov 2019-12-18 18:04:42 -08:00 коммит произвёл Daniel Borkmann
Родитель 12dd14b230
Коммит 580205dd4f
1 изменённых файлов: 4 добавлений и 3 удалений

Просмотреть файл

@ -3,7 +3,7 @@
#include "test_attach_probe.skel.h"
ssize_t get_base_addr() {
size_t start;
size_t start, offset;
char buf[256];
FILE *f;
@ -11,10 +11,11 @@ ssize_t get_base_addr() {
if (!f)
return -errno;
while (fscanf(f, "%zx-%*x %s %*s\n", &start, buf) == 2) {
while (fscanf(f, "%zx-%*x %s %zx %*[^\n]\n",
&start, buf, &offset) == 3) {
if (strcmp(buf, "r-xp") == 0) {
fclose(f);
return start;
return start - offset;
}
}