Code Monkey home page Code Monkey logo

minimal-ebpf's Introduction

minimal-ebpf

Tiny repository containing work related to eBPF and Rust. The medium to long term objective is to use this repository to learn more about eBPF and how to use it with Rust.

For the time being this is mostly a scratchpad.

generic_file_open_example

Simple eBPF program that uses bpftrace to hook to the generic_file_open kprobe and print out details regarding which file was opened and by who. This currently filters by uid being 1000 which generally refers to the current user.

Attaching 2 probes...
uid, gid, filename 
1000, 1000, HEAD

Moving away from bpftrace

Decided to start recreating the program without using bpftrace in order to get a better understanding of the internal representations of eBPF programs.

We recreate the generic_file_open example in C and compile it to byte-code using clang.

clang -target bpf -Wall -O2 -c generic_file_open_example.c -o generic_file_open_example.o

We can now use the Rust library, aya to load our program.

Using aya

Extended the generic_file_open example to now use Aya to load our program into the kernel.

cargo b
sudo ./target/debug/generic-file-open

We can then use bpftool prog to validate that our program has loaded.

❯ sudo bpftool prog
2: cgroup_skb  name egress  tag b9d9f7a5d9d7e087  gpl
        loaded_at 2022-06-08T13:03:02+0100  uid 0
        xlated 360B  jited 206B  memlock 4096B  map_ids 6,4,3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.