#include // Needed by all modules #include // for_each_process, pr_info #include // For proc filesystem #define TIMER_DELAY HZ/5 // Should be 200ms struct timer_list my_timer; bool disable = 1; #define BUFLEN 128 // We should probably find the maximum length of a process name char process_to_stop[BUFLEN] = "kpat"; static void send_signal(int sig_num, struct task_struct* task) { int ret; struct kernel_siginfo info; memset(&info, 0, sizeof(struct kernel_siginfo)); info.si_signo = sig_num; info.si_code = 0; info.si_int = 1234; ret = send_sig_info(sig_num, &info, task); if (ret < 0) { printk("error sending signal\n"); } } void stop_specified_process(void) { if(disable){ struct task_struct* task_list; for_each_process(task_list) { printk("Looking for process \"%s\"", process_to_stop); if(strstr(task_list->comm, process_to_stop)) { printk("Found process %s\n", task_list->comm); send_signal(9, task_list); } } } } static void my_timer_func(struct timer_list *timers) { stop_specified_process(); my_timer.expires = jiffies + TIMER_DELAY; add_timer(&my_timer); } ssize_t write_handler(struct file *filp, const char *buf, size_t count, loff_t *offp){ if(count >= 4 && !strncmp(buf, "stop", 4)) disable = 1; if(count >= 5 && !strncmp(buf, "start", 5)) disable = 0; if(count >= 5 && !strncmp(buf, "name ", 5)){ char* i = process_to_stop; printk("Setting name to %s", buf + 5); strncpy(process_to_stop, buf + 5, BUFLEN - 1); process_to_stop[BUFLEN - 1] = 0; for(; *i; i++) if(*i == '\n') *i = 0; } return count; } struct proc_ops proc_fops = { proc_write: write_handler }; int init_module(void) { timer_setup(&my_timer, my_timer_func, 0); my_timer.expires = jiffies + TIMER_DELAY; add_timer(&my_timer); proc_create("solstop", 0, NULL, &proc_fops); return 0; } void cleanup_module(void) { del_timer(&my_timer); remove_proc_entry("solstop", NULL); } MODULE_LICENSE("MIT");