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  linux-hardening  linux-cve-announce  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]
Message-ID: <20190501090048.emqugoplr4sajnqc@linutronix.de>
Date:   Wed, 1 May 2019 11:00:48 +0200
From:   Sebastian Andrzej Siewior <bigeasy@...utronix.de>
To:     Qian Cai <cai@....pw>
Cc:     dave.hansen@...el.com, bp@...e.de, tglx@...utronix.de,
        x86@...nel.org, "linux-mm@...ck.org" <linux-mm@...ck.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        luto@...capital.net, hpa@...or.com, mingo@...nel.org,
        Vlastimil Babka <vbabka@...e.cz>
Subject: [RFC PATCH] x86/fpu: Use get_user_pages_unlocked() to fault-in pages

Using get_user_pages() seems to be problematic: KASAN reports
use-after-free in LTP's signal06 testcase.
The test invokes the signal handler with a provided stack and changes
the RW/WO page flags of the stack while the signal is invoked.  A crash
due to a NULL pointer has also been observed.

get_user_pages() may be invoked (or so I assumed) without holding the
mmap_sem for pre-faulting. KASAN probably slows down processing that we
can observe the user-after-free while page-flags are changed. It does
not happen without KASAN.

Use get_user_pages_unlocked() which holds the mm_sem around while
paging-in user memory.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
---

While this fixes the problem and the crash later on, I would like to
hear from MM folks if it is intended to invoke get_user_pages() without
holding the mmap_sem. Without passing lockde & pages we only do:
  __get_user_pages_locked()
    - __get_user_pages()
    - if (!pages)
	/* If it's a prefault don't insist harder
	 */
	return ret;
Which was my intention. 
The comment above faultin_page() says "mmap_sem must be held on entry"
so this makes me thing that one must hold it…

 arch/x86/kernel/fpu/signal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c
index eaddb185cac95..3a94e3d2e3bdf 100644
--- a/arch/x86/kernel/fpu/signal.c
+++ b/arch/x86/kernel/fpu/signal.c
@@ -172,8 +172,8 @@ int copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size)
 		aligned_size = offset_in_page(buf_fx) + fpu_user_xstate_size;
 		nr_pages = DIV_ROUND_UP(aligned_size, PAGE_SIZE);
 
-		ret = get_user_pages((unsigned long)buf_fx, nr_pages,
-				     FOLL_WRITE, NULL, NULL);
+		ret = get_user_pages_unlocked((unsigned long)buf_fx, nr_pages,
+					      NULL, FOLL_WRITE);
 		if (ret == nr_pages)
 			goto retry;
 		return -EFAULT;
-- 
2.20.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ