Skip to content

Commit 5d52013

Browse files
Stuart MENEFYpmundt
authored andcommitted
sh: __copy_user function can corrupt the stack in case of exception
The __copy_user function can corrupt the stack in the case of a non-trivial length of data, and either of the first two move instructions cause an exception. This is because the fixup for these two instructions is mapped to the no_pop case, but these instructions execute after the stack is pushed. This change creates an explicit NO_POP exception mapping macro, and uses it for the two instructions executed in the trivial case where no stack pushes occur. More information at ST Linux bugzilla: https://bugzilla.stlinux.com/show_bug.cgi?id=4824 Signed-off-by: Dylan Reid <dylan_reid@bose.com> Signed-off-by: Stuart Menefy <stuart.menefy@st.com> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 2cd0ebc commit 5d52013

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎arch/sh/lib/copy_page.S‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ ENTRY(copy_page)
8080
.section __ex_table, "a"; \
8181
.long 9999b, 6000f ; \
8282
.previous
83+
#define EX_NO_POP(...) \
84+
9999: __VA_ARGS__ ; \
85+
.section __ex_table, "a"; \
86+
.long 9999b, 6005f ; \
87+
.previous
8388
ENTRY(__copy_user)
8489
! Check if small number of bytes
8590
mov #11,r0
@@ -139,9 +144,9 @@ EX( mov.b r1,@r4 )
139144
bt 1f
140145

141146
2:
142-
EX( mov.b @r5+,r0 )
147+
EX_NO_POP( mov.b @r5+,r0 )
143148
dt r6
144-
EX( mov.b r0,@r4 )
149+
EX_NO_POP( mov.b r0,@r4 )
145150
bf/s 2b
146151
add #1,r4
147152

@@ -150,7 +155,7 @@ EX( mov.b r0,@r4 )
150155

151156
# Exception handler:
152157
.section .fixup, "ax"
153-
6000:
158+
6005:
154159
mov.l 8000f,r1
155160
mov r3,r0
156161
jmp @r1

0 commit comments

Comments
 (0)