daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest May 16th, 2018 177 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <linux/module.h>
  2. #include <linux/skbuff.h>
  3. #include <linux/file.h>
  4. #include <linux/pid.h>
  5. #include <net/sock.h>
  6. #include <linux/netfilter/x_tables.h>
  7. #include "xt_stupidpid.h"
  8.  
  9. static bool
  10. stupidpid_mt(const struct sk_buff *skb, struct xt_action_param *par)
  11. {
  12.     const struct xt_stupidpid_match_info *info = par->matchinfo;
  13.     const struct file *filp;
  14.  
  15.     if (skb->sk == NULL || skb->sk->sk_socket == NULL)
  16.         return (info->match ^ info->invert) == 0;
  17.  
  18.     filp = skb->sk->sk_socket->file;
  19.     if (filp == NULL)
  20.         return ((info->match ^ info->invert) &
  21.                (XT_STUPIDPID_PID)) == 0;
  22.    
  23.     if (info->match & XT_STUPIDPID_PID)
  24.         if ((pid_nr(filp->f_owner.pid) == (pid_t) info->pid )^
  25.             !(info->invert & XT_STUPIDPID_PID)
  26.             )
  27.             return false;
  28.  
  29.     return true;
  30. }
  31.  
  32. static struct xt_match stupidpid_mt_reg __read_mostly = {
  33.     .name       = "stupidpid",
  34.     .revision   = 1,
  35.     .family     = NFPROTO_UNSPEC,
  36.     .match      = stupidpid_mt,
  37.     .matchsize  = sizeof(struct xt_stupidpid_match_info),
  38.     .hooks      = (1 << NF_INET_LOCAL_OUT) |
  39.                   (1 << NF_INET_POST_ROUTING),
  40.     .me         = THIS_MODULE,
  41. };
  42.  
  43. static int __init stupidpid_mt_init(void)
  44. {
  45.     return xt_register_match(&stupidpid_mt_reg);
  46. }
  47.  
  48. static void __exit stupidpid_mt_exit(void)
  49. {
  50.     xt_unregister_match(&stupidpid_mt_reg);
  51. }
  52.  
  53. module_init(stupidpid_mt_init);
  54. module_exit(stupidpid_mt_exit);
  55. MODULE_AUTHOR("Daniele Iamartino <danieleiamartino@gmail.com>");
  56. MODULE_DESCRIPTION("Xtables: pid owner matching");
  57. MODULE_LICENSE("GPL");
  58. MODULE_ALIAS("ipt_owner");
  59. MODULE_ALIAS("ip6t_owner");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top