Giter VIP home page Giter VIP logo

k-hacks's Introduction

k-hacks

kernel hack samples collection

GDB direct debug

  • compile kernel with debug info
  • replace kernel & modules

sudo gdb vmlinux /proc/kcore

kcore相当于一个物理内存的备份

Compile kernel with debug info

kernel hacking -> compile-time checks and compiler options -> Compile the kernel with debug info(GDB scripts may leads to compile failure)

ebpf不能调用内核函数,只能调用bpf helper!!!!

Linux Extended BPF (eBPF) Tracing Tools

bpftrace Reference Guide

linux/samples/bpf/

VariableDescription
pidProcess ID
tidThread ID
uidUser ID
usernameUsername
commProcess or command name
curtaskCurrent task_struct as a u64
nsecsCurrent time in nanoseconds
elapsedTime in nanoseconds since bpftrace start
kstackKernel stack trace
ustackUser-level stack trace
arg0...argNFunction arguments
argsTracepoint arguments
retvalFunction return value
funcFunction name
probeFull probe name
$1...$NPositional parameters
cgroupDefault cgroup v2 ID

FunctionDescription
printf("...")Print formatted string
time("...")Print formatted time
join(char *arr[])Join array of strings with a space
str(char *s [, int length])Return string from s pointer
buf(void *p [, int length])Return a hexadecimal string from p pointer
strncmp(char *s1, char *s2, int length)Compares two strings up to length
sizeof(expression)Returns the size of the expression
kstack([limit])Kernel stack trace up to limit frames
ustack([limit])User-level stack trace up to limit frames
ksym(void *p)Resolve kernel address to symbol
usym(void *p)Resolve user-space address to symbol
kaddr(char *name)Resolve kernel symbol name to address
uaddr(char *name)Resolve user-space symbol name to address
ntop([int af,]int|char[4:16] addr)Convert IP address data to text
reg(char *name)Return register value
cgroupid(char *path)Return cgroupid for /sys/fs/cgroup/... path
time("...")Print formatted time
system("...")Run shell command
cat(char *filename)Print file content
signal(char[] sig | int sig)Send a signal to the current task
override(u64 rc)Override a kernel function return value
exit()Exits bpftrace
@ = count()Count events
@ = sum(x)Sum the value
@ = hist(x)Power-of-2 histogram for x
@ = lhist(x, min, max, step)Linear histogram for x
@ = min(x)Record the minimum value seen
@ = max(x)Record the maximum value seen
@ = stats(x)Return the count, average, and total for this value
delete(@x[key])Delete the map element
clear(@x)Delete all keys from the map

k-hacks's People

Contributors

purplewall1206 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.