lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 12 Dec 2013 22:41:18 -0500
From:	Rik van Riel <riel@...hat.com>
To:	Kees Cook <keescook@...omium.org>
Cc:	linux-kernel@...r.kernel.org,
	Andrew Morton <akpm@...ux-foundation.org>,
	Michel Lespinasse <walken@...gle.com>,
	Cyrill Gorcunov <gorcunov@...nvz.org>,
	Hugh Dickins <hughd@...gle.com>, linux-mm@...ck.org,
	PaX Team <pageexec@...email.hu>,
	Dmitry Vyukov <dvyukov@...gle.com>
Subject: Re: [PATCH] mm: fix use-after-free in sys_remap_file_pages

On Thu, 12 Dec 2013 14:07:57 -0800
Kees Cook <keescook@...omium.org> wrote:

> From: PaX Team <pageexec@...email.hu>
> 
> http://lkml.org/lkml/2013/9/17/30
> 
> SyS_remap_file_pages() calls mmap_region(), which calls remove_vma_list(),
> which calls remove_vma(), which frees the vma.  Later (after out label)
> SyS_remap_file_pages() accesses the freed vma in vm_flags = vma->vm_flags.

> index 5bff08147768..afad07b85ef2 100644
> --- a/mm/fremap.c
> +++ b/mm/fremap.c
> @@ -218,6 +218,8 @@ get_write_lock:
>  				BUG_ON(addr != start);
>  				err = 0;
>  			}
> +			vm_flags = vma->vm_flags;
> +			vma = NULL;
>  			goto out;


If the vma has been freed by the time the code jumps to the
out label (because it was freed by a function called from
mmap_region), surely it will also already have been freed
by the time this patch dereferences it?

Also, setting vma = NULL to avoid the if (vma) branch at
the out: label is unnecessarily obfuscated. Lets make things
clear by documenting what is going on, and having a label
after that dereference.

Maybe something like this patch:

---8<---

Subject: [PATCH] mm: fix use-after-free in sys_remap_file_pages

remap_file_pages calls mmap_region, which may merge the VMA with other existing
VMAs, and free "vma". This can lead to a use-after-free bug. Avoid the bug by
remembering vm_flags before calling mmap_region, and not trying to dereference
vma later.

Signed-off-by: Rik van Riel <riel@...hat.com>
Reported-by: Dmitry Vyukov <dvyukov@...gle.com>
Cc: stable@...r.kernel.org
---
 mm/fremap.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/fremap.c b/mm/fremap.c
index 87da359..d28ede5 100644
--- a/mm/fremap.c
+++ b/mm/fremap.c
@@ -203,6 +203,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
 		if (mapping_cap_account_dirty(mapping)) {
 			unsigned long addr;
 			struct file *file = get_file(vma->vm_file);
+			vm_flags = vma->vm_flags;
 
 			addr = mmap_region(file, start, size,
 					vma->vm_flags, pgoff);
@@ -213,7 +214,8 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
 				BUG_ON(addr != start);
 				err = 0;
 			}
-			goto out;
+			/* mmap_region may have freed vma */
+			goto out_freed;
 		}
 		mutex_lock(&mapping->i_mmap_mutex);
 		flush_dcache_mmap_lock(mapping);
@@ -248,6 +250,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
 out:
 	if (vma)
 		vm_flags = vma->vm_flags;
+out_freed:
 	if (likely(!has_write_lock))
 		up_read(&mm->mmap_sem);
 	else
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists