18c2ecf20Sopenharmony_ci/* Copyright (c) 2016 Facebook 28c2ecf20Sopenharmony_ci * 38c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or 48c2ecf20Sopenharmony_ci * modify it under the terms of version 2 of the GNU General Public 58c2ecf20Sopenharmony_ci * License as published by the Free Software Foundation. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci#include <linux/version.h> 88c2ecf20Sopenharmony_ci#include <linux/ptrace.h> 98c2ecf20Sopenharmony_ci#include <uapi/linux/bpf.h> 108c2ecf20Sopenharmony_ci#include <bpf/bpf_helpers.h> 118c2ecf20Sopenharmony_ci#include <bpf/bpf_tracing.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define _(P) \ 148c2ecf20Sopenharmony_ci ({ \ 158c2ecf20Sopenharmony_ci typeof(P) val = 0; \ 168c2ecf20Sopenharmony_ci bpf_probe_read_kernel(&val, sizeof(val), &(P)); \ 178c2ecf20Sopenharmony_ci val; \ 188c2ecf20Sopenharmony_ci }) 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ciSEC("kprobe/__set_task_comm") 218c2ecf20Sopenharmony_ciint prog(struct pt_regs *ctx) 228c2ecf20Sopenharmony_ci{ 238c2ecf20Sopenharmony_ci struct signal_struct *signal; 248c2ecf20Sopenharmony_ci struct task_struct *tsk; 258c2ecf20Sopenharmony_ci char oldcomm[16] = {}; 268c2ecf20Sopenharmony_ci char newcomm[16] = {}; 278c2ecf20Sopenharmony_ci u16 oom_score_adj; 288c2ecf20Sopenharmony_ci u32 pid; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci tsk = (void *)PT_REGS_PARM1(ctx); 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci pid = _(tsk->pid); 338c2ecf20Sopenharmony_ci bpf_probe_read_kernel(oldcomm, sizeof(oldcomm), &tsk->comm); 348c2ecf20Sopenharmony_ci bpf_probe_read_kernel(newcomm, sizeof(newcomm), 358c2ecf20Sopenharmony_ci (void *)PT_REGS_PARM2(ctx)); 368c2ecf20Sopenharmony_ci signal = _(tsk->signal); 378c2ecf20Sopenharmony_ci oom_score_adj = _(signal->oom_score_adj); 388c2ecf20Sopenharmony_ci return 0; 398c2ecf20Sopenharmony_ci} 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ciSEC("kprobe/urandom_read") 428c2ecf20Sopenharmony_ciint prog2(struct pt_regs *ctx) 438c2ecf20Sopenharmony_ci{ 448c2ecf20Sopenharmony_ci return 0; 458c2ecf20Sopenharmony_ci} 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cichar _license[] SEC("license") = "GPL"; 488c2ecf20Sopenharmony_ciu32 _version SEC("version") = LINUX_VERSION_CODE; 49