linux-2.6.30_proc_self_exe.patch 966 B

12345678910111213141516171819202122232425262728293031323334
  1. This patch makes /proc/self/exe executable even if proc
  2. is not mounted. It is especially useful on NOMMU arches.
  3. diff -urp ../linux-2.6.30.org/fs/exec.c linux-2.6.30/fs/exec.c
  4. --- ../linux-2.6.30.org/fs/exec.c 2009-06-10 05:05:27.000000000 +0200
  5. +++ linux-2.6.30/fs/exec.c 2009-06-25 00:20:13.000000000 +0200
  6. @@ -652,9 +652,25 @@ struct file *open_exec(const char *name)
  7. file = do_filp_open(AT_FDCWD, name,
  8. O_LARGEFILE | O_RDONLY | FMODE_EXEC, 0,
  9. MAY_EXEC | MAY_OPEN);
  10. - if (IS_ERR(file))
  11. - goto out;
  12. + if (IS_ERR(file)) {
  13. + if ((PTR_ERR(file) == -ENOENT || PTR_ERR(file) == -EACCES)
  14. + && strcmp(name, "/proc/self/exe") == 0
  15. + ) {
  16. + struct file *sv = file;
  17. + struct mm_struct *mm;
  18. + mm = get_task_mm(current);
  19. + if (!mm)
  20. + goto out;
  21. + file = get_mm_exe_file(mm);
  22. + mmput(mm);
  23. + if (file)
  24. + goto ok;
  25. + file = sv;
  26. + }
  27. + goto out;
  28. + }
  29. +ok:
  30. err = -EACCES;
  31. if (!S_ISREG(file->f_path.dentry->d_inode->i_mode))
  32. goto exit;