]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.4.129/mips-memset.s-eva-fault-support-for-small_memset.patch
3.18-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.4.129 / mips-memset.s-eva-fault-support-for-small_memset.patch
CommitLineData
c08aef14
GKH
1From 8a8158c85e1e774a44fbe81106fa41138580dfd1 Mon Sep 17 00:00:00 2001
2From: Matt Redfearn <matt.redfearn@mips.com>
3Date: Thu, 29 Mar 2018 10:28:23 +0100
4Subject: MIPS: memset.S: EVA & fault support for small_memset
5
6From: Matt Redfearn <matt.redfearn@mips.com>
7
8commit 8a8158c85e1e774a44fbe81106fa41138580dfd1 upstream.
9
10The MIPS kernel memset / bzero implementation includes a small_memset
11branch which is used when the region to be set is smaller than a long (4
12bytes on 32bit, 8 bytes on 64bit). The current small_memset
13implementation uses a simple store byte loop to write the destination.
14There are 2 issues with this implementation:
15
161. When EVA mode is active, user and kernel address spaces may overlap.
17Currently the use of the sb instruction means kernel mode addressing is
18always used and an intended write to userspace may actually overwrite
19some critical kernel data.
20
212. If the write triggers a page fault, for example by calling
22__clear_user(NULL, 2), instead of gracefully handling the fault, an OOPS
23is triggered.
24
25Fix these issues by replacing the sb instruction with the EX() macro,
26which will emit EVA compatible instuctions as required. Additionally
27implement a fault fixup for small_memset which sets a2 to the number of
28bytes that could not be cleared (as defined by __clear_user).
29
30Reported-by: Chuanhua Lei <chuanhua.lei@intel.com>
31Signed-off-by: Matt Redfearn <matt.redfearn@mips.com>
32Cc: Ralf Baechle <ralf@linux-mips.org>
33Cc: linux-mips@linux-mips.org
34Cc: stable@vger.kernel.org
35Patchwork: https://patchwork.linux-mips.org/patch/18975/
36Signed-off-by: James Hogan <jhogan@kernel.org>
37Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
38
39---
40 arch/mips/lib/memset.S | 7 ++++++-
41 1 file changed, 6 insertions(+), 1 deletion(-)
42
43--- a/arch/mips/lib/memset.S
44+++ b/arch/mips/lib/memset.S
45@@ -218,7 +218,7 @@
46 1: PTR_ADDIU a0, 1 /* fill bytewise */
47 R10KCBARRIER(0(ra))
48 bne t1, a0, 1b
49- sb a1, -1(a0)
50+ EX(sb, a1, -1(a0), .Lsmall_fixup\@)
51
52 2: jr ra /* done */
53 move a2, zero
54@@ -257,6 +257,11 @@
55 jr ra
56 andi v1, a2, STORMASK
57
58+.Lsmall_fixup\@:
59+ PTR_SUBU a2, t1, a0
60+ jr ra
61+ PTR_ADDIU a2, 1
62+
63 .endm
64
65 /*