arter97

lmkd --reinit hack

Sep 18th, 2021
695
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. commit eb8e5359f6c0a5deccb1a17a6fa130c042479519
  2. Author: Juhyung Park <qkrwngud825@gmail.com>
  3. Date:   Sun Sep 19 02:56:25 2021 +0900
  4.  
  5.     exec: add a hack to disable lmkd reloading props
  6.    
  7.     /vendor/etc/perf/perfconfigstore.xml enables ro.lmk.enable_userspace_lmk,
  8.     and when the lmkd properties are re-read, lmkd tries to honor it and ignores
  9.     the presence of in-kernel lmk and exits repeatedly, which causes init to
  10.     trigger a reboot.
  11.    
  12.     Signed-off-by: Juhyung Park <qkrwngud825@gmail.com>
  13.  
  14. diff --git a/fs/exec.c b/fs/exec.c
  15. index d713797fab9aa..be1e483b093a3 100644
  16. --- a/fs/exec.c
  17. +++ b/fs/exec.c
  18. @@ -1724,6 +1724,27 @@ static int exec_binprm(struct linux_binprm *bprm)
  19.     return ret;
  20.  }
  21.  
  22. +static noinline bool is_lmkd_reinit(struct user_arg_ptr *argv)
  23. +{
  24. +   const char __user *str;
  25. +   char buf[10];
  26. +   int len;
  27. +
  28. +   str = get_user_arg_ptr(*argv, 1);
  29. +   if (IS_ERR(str))
  30. +       return false;
  31. +
  32. +   // strnlen_user() counts NULL terminator
  33. +   len = strnlen_user(str, MAX_ARG_STRLEN);
  34. +   if (len != 9)
  35. +       return false;
  36. +
  37. +   if (copy_from_user(buf, str, len))
  38. +       return false;
  39. +
  40. +   return !strcmp(buf, "--reinit");
  41. +}
  42. +
  43.  /*
  44.   * sys_execve() executes a new program.
  45.   */
  46. @@ -1828,6 +1849,15 @@ static int __do_execve_file(int fd, struct filename *filename,
  47.     if (retval < 0)
  48.         goto out;
  49.  
  50. +   // Super nasty hack to disable lmkd reloading props
  51. +   if (unlikely(strcmp(bprm.filename, "/system/bin/lmkd") == 0)) {
  52. +       if (is_lmkd_reinit(&argv)) {
  53. +           pr_info("sys_execve(): prevented /system/bin/lmkd --reinit\n");
  54. +           retval = -ENOENT;
  55. +           goto out;
  56. +       }
  57. +   }
  58. +
  59.     retval = exec_binprm(&bprm);
  60.     if (retval < 0)
  61.         goto out;
  62.  
RAW Paste Data