Skip to content

Commit

Permalink
tomoyo: reduce mmap_sem hold for mm->exe_file
Browse files Browse the repository at this point in the history
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

[[email protected]: coding-style fixes]
Signed-off-by: Davidlohr Bueso <[email protected]>
Acked-by: Tetsuo Handa <[email protected]>
Cc: James Morris <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Davidlohr Bueso authored and torvalds committed Apr 17, 2015
1 parent fd89a65 commit d4144ea
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions security/tomoyo/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,15 +948,18 @@ bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
*/
const char *tomoyo_get_exe(void)
{
struct file *exe_file;
const char *cp;
struct mm_struct *mm = current->mm;
const char *cp = NULL;

if (!mm)
return NULL;
down_read(&mm->mmap_sem);
if (mm->exe_file)
cp = tomoyo_realpath_from_path(&mm->exe_file->f_path);
up_read(&mm->mmap_sem);
exe_file = get_mm_exe_file(mm);
if (!exe_file)
return NULL;

cp = tomoyo_realpath_from_path(&exe_file->f_path);
fput(exe_file);
return cp;
}

Expand Down

0 comments on commit d4144ea

Please sign in to comment.