[Bug runtime/30408] New: Always fail to read userland memory (read faults) inside perf event probes with 6.2 kernels

agentzh at gmail dot com sourceware-bugzilla@sourceware.org
Sun Apr 30 06:28:35 GMT 2023


https://sourceware.org/bugzilla/show_bug.cgi?id=30408

            Bug ID: 30408
           Summary: Always fail to read userland memory (read faults)
                    inside perf event probes with 6.2 kernels
           Product: systemtap
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: runtime
          Assignee: systemtap at sourceware dot org
          Reporter: agentzh at gmail dot com
  Target Milestone: ---

I've noted a regression of stap when using Fedora 36 x86_64's latest 6.2.12
kernel. It always fails to read userland memory inside a perf event probe
handler. It can be demonstrated by the following minimal example.

First prepare a small C program as the tracing target:

```
#include <stdio.h>

unsigned long a = 0;

void foo (void) {
    FILE *f = fopen("/dev/null", "w");
    fputs("hello world!\n", f);
    fclose(f);
}

int main (void) {
    while (1) {
        a++;
        for (int i = 0; i < 100; i++) {
            foo();
            foo();
        }
    }
    return 0;
}
```

Then we compile it with debug symbols:

```
gcc -g a.c
```

And we copy the resulting `./a.out` program file to `/tmp/`:

```
cp a.out /tmp/
```

Now we prepare a small stap script file named c.stp:

```
global fails = 0;

probe perf.type(1).config(0).sample(1000000) {
    if (execname() == "a.out") {
        ok = 1;
        val = 0;
        try {
            val = @var("a", "/tmp/a.out");
        } catch {
            ok = 0;
            fails++;
        }
        if (ok) {
            printf("a = %d\n", val);
            exit();
        }
    }
}

probe begin {
    warn("Start tracing...");
}

probe timer.s(2) {
    printf("failed %ld times\n", fails);
}
```

And we run it like this:

```
/opt/stap/bin/stap -c /tmp/a.out c.stp
WARNING: Start tracing...
failed 3927 times
failed 7854 times
failed 11769 times
failed 15741 times
failed 19705 times
failed 23671 times
failed 27668 times
failed 31639 times
failed 35613 times
failed 39563 times
failed 43491 times
failed 47463 times
failed 51465 times
...
```

No matter how long we wait, it always fails to read anything from `@var()`.

For comparison, I also ran this example on an older kernel (5.0.16) of an older
Fedora system and it works fine:

```
$ /opt/stap/bin/stap -c ./a.out c.stp
WARNING: Start tracing...
a = 150746
```

So it's definitely a behavior regression with the new kernel.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the Systemtap mailing list