ARM: 8813/1: Make aligned 2-byte getuser()/putuser() atomic on ARMv6+
authorVincent Whitchurch <vincent.whitchurch@axis.com>
Fri, 9 Nov 2018 09:12:30 +0000 (10:12 +0100)
committerRussell King <rmk+kernel@armlinux.org.uk>
Mon, 12 Nov 2018 10:52:04 +0000 (10:52 +0000)
getuser() and putuser() (and there underscored variants) use two
strb[t]/ldrb[t] instructions when they are asked to get/put 16-bits.
This means that the read/write is not atomic even when performed to a
16-bit-aligned address.

This leads to problems with vhost: vhost uses __getuser() to read the
vring's 16-bit avail.index field, and if it happens to observe a partial
update of the index, wrong descriptors will be used which will lead to a
breakdown of the virtio communication.  A similar problem exists for
__putuser() which is used to write to the vring's used.index field.

The reason these functions use strb[t]/ldrb[t] is because strht/ldrht
instructions did not exist until ARMv6T2/ARMv7.  So we should be easily
able to fix this on ARMv7.  Also, since all ARMv6 processors also don't
actually use the unprivileged instructions anymore for uaccess (since
CONFIG_CPU_USE_DOMAINS is not used) we can easily fix them too.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
arch/arm/include/asm/uaccess.h
arch/arm/lib/getuser.S
arch/arm/lib/putuser.S

index c136eef8f690be60bba14f6a871dff286a5942f0..6390a40f16e733e061b1d3abfc01a92a46384a8b 100644 (file)
@@ -349,6 +349,13 @@ do {                                                                       \
 #define __get_user_asm_byte(x, addr, err)                      \
        __get_user_asm(x, addr, err, ldrb)
 
+#if __LINUX_ARM_ARCH__ >= 6
+
+#define __get_user_asm_half(x, addr, err)                      \
+       __get_user_asm(x, addr, err, ldrh)
+
+#else
+
 #ifndef __ARMEB__
 #define __get_user_asm_half(x, __gu_addr, err)                 \
 ({                                                             \
@@ -367,6 +374,8 @@ do {                                                                        \
 })
 #endif
 
+#endif /* __LINUX_ARM_ARCH__ >= 6 */
+
 #define __get_user_asm_word(x, addr, err)                      \
        __get_user_asm(x, addr, err, ldr)
 #endif
@@ -442,6 +451,13 @@ do {                                                                       \
 #define __put_user_asm_byte(x, __pu_addr, err)                 \
        __put_user_asm(x, __pu_addr, err, strb)
 
+#if __LINUX_ARM_ARCH__ >= 6
+
+#define __put_user_asm_half(x, __pu_addr, err)                 \
+       __put_user_asm(x, __pu_addr, err, strh)
+
+#else
+
 #ifndef __ARMEB__
 #define __put_user_asm_half(x, __pu_addr, err)                 \
 ({                                                             \
@@ -458,6 +474,8 @@ do {                                                                        \
 })
 #endif
 
+#endif /* __LINUX_ARM_ARCH__ >= 6 */
+
 #define __put_user_asm_word(x, __pu_addr, err)                 \
        __put_user_asm(x, __pu_addr, err, str)
 
index 746e7801dcdf70fed9e339c2d6800b3f275c49b7..b2e4bc3a635e22002fd90eaf4d802b528f6dab32 100644 (file)
@@ -42,6 +42,12 @@ _ASM_NOKPROBE(__get_user_1)
 
 ENTRY(__get_user_2)
        check_uaccess r0, 2, r1, r2, __get_user_bad
+#if __LINUX_ARM_ARCH__ >= 6
+
+2: TUSER(ldrh) r2, [r0]
+
+#else
+
 #ifdef CONFIG_CPU_USE_DOMAINS
 rb     .req    ip
 2:     ldrbt   r2, [r0], #1
@@ -56,6 +62,9 @@ rb    .req    r0
 #else
        orr     r2, rb, r2, lsl #8
 #endif
+
+#endif /* __LINUX_ARM_ARCH__ >= 6 */
+
        mov     r0, #0
        ret     lr
 ENDPROC(__get_user_2)
@@ -145,7 +154,9 @@ _ASM_NOKPROBE(__get_user_bad8)
 .pushsection __ex_table, "a"
        .long   1b, __get_user_bad
        .long   2b, __get_user_bad
+#if __LINUX_ARM_ARCH__ < 6
        .long   3b, __get_user_bad
+#endif
        .long   4b, __get_user_bad
        .long   5b, __get_user_bad8
        .long   6b, __get_user_bad8
index 38d660d3705f4f259c5299d2cc8c1126f0a1dbb4..515eeaa9975c6cbf75b8aba01d85df7deb063b25 100644 (file)
@@ -41,16 +41,13 @@ ENDPROC(__put_user_1)
 
 ENTRY(__put_user_2)
        check_uaccess r0, 2, r1, ip, __put_user_bad
-       mov     ip, r2, lsr #8
-#ifdef CONFIG_THUMB2_KERNEL
-#ifndef __ARMEB__
-2: TUSER(strb) r2, [r0]
-3: TUSER(strb) ip, [r0, #1]
+#if __LINUX_ARM_ARCH__ >= 6
+
+2: TUSER(strh) r2, [r0]
+
 #else
-2: TUSER(strb) ip, [r0]
-3: TUSER(strb) r2, [r0, #1]
-#endif
-#else  /* !CONFIG_THUMB2_KERNEL */
+
+       mov     ip, r2, lsr #8
 #ifndef __ARMEB__
 2: TUSER(strb) r2, [r0], #1
 3: TUSER(strb) ip, [r0]
@@ -58,7 +55,8 @@ ENTRY(__put_user_2)
 2: TUSER(strb) ip, [r0], #1
 3: TUSER(strb) r2, [r0]
 #endif
-#endif /* CONFIG_THUMB2_KERNEL */
+
+#endif /* __LINUX_ARM_ARCH__ >= 6 */
        mov     r0, #0
        ret     lr
 ENDPROC(__put_user_2)
@@ -91,7 +89,9 @@ ENDPROC(__put_user_bad)
 .pushsection __ex_table, "a"
        .long   1b, __put_user_bad
        .long   2b, __put_user_bad
+#if __LINUX_ARM_ARCH__ < 6
        .long   3b, __put_user_bad
+#endif
        .long   4b, __put_user_bad
        .long   5b, __put_user_bad
        .long   6b, __put_user_bad