Commit d4144ea6 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Linus Torvalds

tomoyo: reduce mmap_sem hold for mm->exe_file

The mm->exe_file is currently serialized with mmap_sem (shared) in order
to both safely (1) read the file and (2) compute the realpath by calling
tomoyo_realpath_from_path, making it an absolute overkill.  Good users
will, on the other hand, make use of the more standard get_mm_exe_file(),
requiring only holding the mmap_sem to read the value, and relying on
reference

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: default avatarDavidlohr Bueso <dbueso@suse.de>
Acked-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: James Morris <jmorris@namei.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent fd89a65f
...@@ -948,15 +948,18 @@ bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, ...@@ -948,15 +948,18 @@ bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
*/ */
const char *tomoyo_get_exe(void) const char *tomoyo_get_exe(void)
{ {
struct file *exe_file;
const char *cp;
struct mm_struct *mm = current->mm; struct mm_struct *mm = current->mm;
const char *cp = NULL;
if (!mm) if (!mm)
return NULL; return NULL;
down_read(&mm->mmap_sem); exe_file = get_mm_exe_file(mm);
if (mm->exe_file) if (!exe_file)
cp = tomoyo_realpath_from_path(&mm->exe_file->f_path); return NULL;
up_read(&mm->mmap_sem);
cp = tomoyo_realpath_from_path(&exe_file->f_path);
fput(exe_file);
return cp; return cp;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment