]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
tomoyo: reduce mmap_sem hold for mm->exe_file
authorDavidlohr Bueso <dave@stgolabs.net>
Tue, 7 Apr 2015 23:57:05 +0000 (09:57 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 9 Apr 2015 09:07:11 +0000 (19:07 +1000)
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

Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Acked-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: James Morris <jmorris@namei.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
security/tomoyo/util.c

index 2952ba576fb9ceed3f64c23663a2b40f3cfbe13e..29f3b65284c725b65a3735e9690f23a674dad732 100644 (file)
@@ -948,16 +948,19 @@ bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
  */
 const char *tomoyo_get_exe(void)
 {
-       struct mm_struct *mm = current->mm;
-       const char *cp = NULL;
+       struct file *exe_file;
+       const char *cp;
+       struct mm_struct *mm = current->mm;
 
-       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);
-       return cp;
+       if (!mm)
+              return NULL;
+       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;
 }
 
 /**