Re: [PATCHv3 12/17] arm64: uaccess: split user/kernel routines

Mark Rutland
2020-11-02T10:49:12Z

On Mon, Oct 26, 2020 at 01:31:51PM +0000, Mark Rutland wrote:
> -#define __raw_get_mem(x, ptr, err) \
> +#define __raw_get_mem(ldr, x, ptr, err) \
> do { \
> unsigned long __gu_val; \
> __chk_user_ptr(ptr); \
> switch (sizeof(*(ptr))) { \
> case 1: \
> - __get_mem_asm("ldrb", "ldtrb", "%w", __gu_val, (ptr), \
> - (err), ARM64_HAS_UAO); \
> + __get_mem_asm(ldr "b", "%w", __gu_val, (ptr), (err)); \
> break; \
> case 2: \
> - __get_mem_asm("ldrh", "ldtrh", "%w", __gu_val, (ptr), \
> - (err), ARM64_HAS_UAO); \
> + __get_mem_asm(ldr "h", "%w", __gu_val, (ptr), (err)); \
> break; \
> case 4: \
> - __get_mem_asm("ldr", "ldtr", "%w", __gu_val, (ptr), \
> - (err), ARM64_HAS_UAO); \
> + __get_mem_asm(ldr, "%w", __gu_val, (ptr), (err)); \
> break; \
> case 8: \
> - __get_mem_asm("ldr", "ldtr", "%x", __gu_val, (ptr), \
> - (err), ARM64_HAS_UAO); \
> + __get_mem_asm(ldr, "%x", __gu_val, (ptr), (err)); \
> break; \
> default: \
> BUILD_BUG(); \
> @@ -298,7 +295,7 @@ do { \
> #define __raw_get_user(x, ptr, err) \
> do { \
> uaccess_enable_not_uao(); \
> - __raw_get_mem(x, ptr, err); \
> + __raw_get_mem("ldtr", x, ptr, err); \
> uaccess_disable_not_uao(); \
> } while (0)
>
> @@ -323,10 +320,19 @@ do { \
>
> #define get_user __get_user
>
> -#define __put_mem_asm(instr, alt_instr, reg, x, addr, err, feature) \
> +#define __get_kernel_nofault(dst, src, type, err_label) \
> +do { \
> + int __gkn_err; \
> + \
> + __raw_get_mem("ldr", *((type *)(dst)), \
> + (__force type __user *)(src), __gkn_err); \
> + if (unlikely(__gkn_err)) \
> + goto err_label; \
> +} while(0)

The `__gkn_err` variables needs to be initialized to zero to avoid
spurious errors being returned.

> @@ -366,7 +368,7 @@ do { \
> #define __raw_put_user(x, ptr, err) \
> do { \
> uaccess_enable_not_uao(); \
> - __raw_put_mem(x, ptr, err); \
> + __raw_put_mem("sttr", x, ptr, err); \
> uaccess_disable_not_uao(); \
> } while (0)
>
> @@ -391,6 +393,16 @@ do { \
>
> #define put_user __put_user
>
> +#define __put_kernel_nofault(dst, src, type, err_label) \
> +do { \
> + int __pkn_err; \
> + \
> + __raw_put_mem("str", *((type *)(src)), \
> + (__force type __user *)(dst), __pkn_err); \
> + if (unlikely(__pkn_err)) \
> + goto err_label; \
> +} while(0)

... and likewise here.

I've fixed both in my tree.

Mark.