Skip to content

Commit b81ff10

Browse files
Hugh Dickinssuryasaimadhu
authored andcommitted
x86/fpu: Use fault_in_pages_writeable() for pre-faulting
Since commit d9c9ce3 ("x86/fpu: Fault-in user stack if copy_fpstate_to_sigframe() fails") get_user_pages_unlocked() pre-faults user's memory if a write generates a page fault while the handler is disabled. This works in general and uncovered a bug as reported by Mike Rapoport¹. It has been pointed out that this function may be fragile and a simple pre-fault as in fault_in_pages_writeable() would be a better solution. Better as in taste and simplicity: that write (as performed by the alternative function) performs exactly the same faulting of memory as before. This was suggested by Hugh Dickins and Andrew Morton. Use fault_in_pages_writeable() for pre-faulting user's stack. [ bigeasy: Write commit message. ] [ bp: Massage some. ] ¹ https://lkml.kernel.org/r/[email protected] Fixes: d9c9ce3 ("x86/fpu: Fault-in user stack if copy_fpstate_to_sigframe() fails") Suggested-by: Andrew Morton <[email protected]> Signed-off-by: Hugh Dickins <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Tested-by: Chris Wilson <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Dave Hansen <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jann Horn <[email protected]> Cc: linux-mm <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Pavel Machek <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: x86-ml <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent e35faeb commit b81ff10

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

arch/x86/kernel/fpu/signal.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <linux/compat.h>
77
#include <linux/cpu.h>
8+
#include <linux/pagemap.h>
89

910
#include <asm/fpu/internal.h>
1011
#include <asm/fpu/signal.h>
@@ -189,15 +190,7 @@ int copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size)
189190
fpregs_unlock();
190191

191192
if (ret) {
192-
int aligned_size;
193-
int nr_pages;
194-
195-
aligned_size = offset_in_page(buf_fx) + fpu_user_xstate_size;
196-
nr_pages = DIV_ROUND_UP(aligned_size, PAGE_SIZE);
197-
198-
ret = get_user_pages_unlocked((unsigned long)buf_fx, nr_pages,
199-
NULL, FOLL_WRITE);
200-
if (ret == nr_pages)
193+
if (!fault_in_pages_writeable(buf_fx, fpu_user_xstate_size))
201194
goto retry;
202195
return -EFAULT;
203196
}

0 commit comments

Comments
 (0)