Whamcloud - gitweb
LU-5179 libcfs: do not leak mm_struct 59/10759/2
authorOleg Drokin <oleg.drokin@intel.com>
Thu, 19 Jun 2014 20:20:43 +0000 (16:20 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 20 Jun 2014 17:35:38 +0000 (17:35 +0000)
cfs_get_environ might leak an mm_struct if LU-1735 race condition
hits.
Make sure to mmput in such a case.

Change-Id: I49499c14027358961743d8928ab2edbe54bf72f7
Signed-off-by: Oleg Drokin <oleg.drokin@intel.com>
Reviewed-on: http://review.whamcloud.com/10759
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Jinshan Xiong <jinshan.xiong@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
libcfs/libcfs/linux/linux-curproc.c

index 1452f14..525cebc 100644 (file)
@@ -206,10 +206,9 @@ int cfs_get_environ(const char *key, char *value, int *val_len)
         * which is already holding mmap_sem for writes.  If some other
         * thread gets the write lock in the meantime, this thread will
         * block, but at least it won't deadlock on itself.  LU-1735 */
         * which is already holding mmap_sem for writes.  If some other
         * thread gets the write lock in the meantime, this thread will
         * block, but at least it won't deadlock on itself.  LU-1735 */
-       if (down_read_trylock(&mm->mmap_sem) == 0) {
-               kfree(buffer);
-               return -EDEADLK;
-       }
+       if (down_read_trylock(&mm->mmap_sem) == 0)
+               GOTO(out, rc = -EDEADLK);
+
        up_read(&mm->mmap_sem);
 
        addr = mm->env_start;
        up_read(&mm->mmap_sem);
 
        addr = mm->env_start;