<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/samples/bpf/tracex5_user.c, branch v4.4.112</title>
<subtitle>Linux kernel for Apalis and Colibri modules</subtitle>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/'/>
<entry>
<title>samples/bpf: bpf_tail_call example for tracing</title>
<updated>2015-05-21T21:07:59+00:00</updated>
<author>
<name>Alexei Starovoitov</name>
<email>ast@plumgrid.com</email>
</author>
<published>2015-05-19T23:59:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=5bacd7805ab4f07a69c7ef4b1d45ce553d2b1c3a'/>
<id>5bacd7805ab4f07a69c7ef4b1d45ce553d2b1c3a</id>
<content type='text'>
kprobe example that demonstrates how future seccomp programs may look like.
It attaches to seccomp_phase1() function and tail-calls other BPF programs
depending on syscall number.

Existing optimized classic BPF seccomp programs generated by Chrome look like:
if (sd.nr &lt; 121) {
  if (sd.nr &lt; 57) {
    if (sd.nr &lt; 22) {
      if (sd.nr &lt; 7) {
        if (sd.nr &lt; 4) {
          if (sd.nr &lt; 1) {
            check sys_read
          } else {
            if (sd.nr &lt; 3) {
              check sys_write and sys_open
            } else {
              check sys_close
            }
          }
        } else {
      } else {
    } else {
  } else {
} else {
}

the future seccomp using native eBPF may look like:
  bpf_tail_call(&amp;sd, &amp;syscall_jmp_table, sd.nr);
which is simpler, faster and leaves more room for per-syscall checks.

Usage:
$ sudo ./tracex5
&lt;...&gt;-366   [001] d...     4.870033: : read(fd=1, buf=00007f6d5bebf000, size=771)
&lt;...&gt;-369   [003] d...     4.870066: : mmap
&lt;...&gt;-369   [003] d...     4.870077: : syscall=110 (one of get/set uid/pid/gid)
&lt;...&gt;-369   [003] d...     4.870089: : syscall=107 (one of get/set uid/pid/gid)
   sh-369   [000] d...     4.891740: : read(fd=0, buf=00000000023d1000, size=512)
   sh-369   [000] d...     4.891747: : write(fd=1, buf=00000000023d3000, size=512)
   sh-369   [000] d...     4.891747: : read(fd=1, buf=00000000023d3000, size=512)

Signed-off-by: Alexei Starovoitov &lt;ast@plumgrid.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
kprobe example that demonstrates how future seccomp programs may look like.
It attaches to seccomp_phase1() function and tail-calls other BPF programs
depending on syscall number.

Existing optimized classic BPF seccomp programs generated by Chrome look like:
if (sd.nr &lt; 121) {
  if (sd.nr &lt; 57) {
    if (sd.nr &lt; 22) {
      if (sd.nr &lt; 7) {
        if (sd.nr &lt; 4) {
          if (sd.nr &lt; 1) {
            check sys_read
          } else {
            if (sd.nr &lt; 3) {
              check sys_write and sys_open
            } else {
              check sys_close
            }
          }
        } else {
      } else {
    } else {
  } else {
} else {
}

the future seccomp using native eBPF may look like:
  bpf_tail_call(&amp;sd, &amp;syscall_jmp_table, sd.nr);
which is simpler, faster and leaves more room for per-syscall checks.

Usage:
$ sudo ./tracex5
&lt;...&gt;-366   [001] d...     4.870033: : read(fd=1, buf=00007f6d5bebf000, size=771)
&lt;...&gt;-369   [003] d...     4.870066: : mmap
&lt;...&gt;-369   [003] d...     4.870077: : syscall=110 (one of get/set uid/pid/gid)
&lt;...&gt;-369   [003] d...     4.870089: : syscall=107 (one of get/set uid/pid/gid)
   sh-369   [000] d...     4.891740: : read(fd=0, buf=00000000023d1000, size=512)
   sh-369   [000] d...     4.891747: : write(fd=1, buf=00000000023d3000, size=512)
   sh-369   [000] d...     4.891747: : read(fd=1, buf=00000000023d3000, size=512)

Signed-off-by: Alexei Starovoitov &lt;ast@plumgrid.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</pre>
</div>
</content>
</entry>
</feed>
