Re: [PATCH v2 20/40] metag: fix put_user sparse errors

From: James Hogan
Date: Wed Jan 07 2015 - 04:55:17 EST


On 06/01/15 15:44, Michael S. Tsirkin wrote:
> virtio wants to write bitwise types to userspace using put_user.
> At the moment this triggers sparse errors, since the value is passed
> through an integer.
>
> For example:
>
> __le32 __user *p;
> __le32 x;
> put_user(x, p);
>
> is safe, but currently triggers a sparse warning.
>
> Fix that up using __force.
>
> This also fixes warnings due to writing a pointer out to
> userland.
>
> Note: this does not suppress any useful sparse checks since callers
> do a cast (__typeof__(*(ptr))) (x) which in turn forces all the
> necessary type checks.
>
> Suggested-by: James Hogan <james.hogan@xxxxxxxxxx>
> Signed-off-by: Michael S. Tsirkin <mst@xxxxxxxxxx>
> ---
> arch/metag/include/asm/uaccess.h | 21 +++++++++++++--------
> 1 file changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/arch/metag/include/asm/uaccess.h b/arch/metag/include/asm/uaccess.h
> index c314b45..9627c19 100644
> --- a/arch/metag/include/asm/uaccess.h
> +++ b/arch/metag/include/asm/uaccess.h
> @@ -107,18 +107,23 @@ extern long __put_user_asm_w(unsigned int x, void __user *addr);
> extern long __put_user_asm_d(unsigned int x, void __user *addr);
> extern long __put_user_asm_l(unsigned long long x, void __user *addr);
>
> -#define __put_user_size(x, ptr, size, retval) \
> -do { \
> - retval = 0; \
> - switch (size) { \
> +#define __put_user_size(x, ptr, size, retval) \
> +do { \
> + retval = 0; \
> + switch (size) { \

On the last 3 lines here you've added a tab after spaces which
checkpatch complains about. With that fixed (or converted to tabs properly):

Acked-by: James Hogan <james.hogan@xxxxxxxxxx>

Cheers
James

> case 1: \
> - retval = __put_user_asm_b((unsigned int)x, ptr); break; \
> + retval = __put_user_asm_b((__force unsigned int)x, ptr);\
> + break; \
> case 2: \
> - retval = __put_user_asm_w((unsigned int)x, ptr); break; \
> + retval = __put_user_asm_w((__force unsigned int)x, ptr);\
> + break; \
> case 4: \
> - retval = __put_user_asm_d((unsigned int)x, ptr); break; \
> + retval = __put_user_asm_d((__force unsigned int)x, ptr);\
> + break; \
> case 8: \
> - retval = __put_user_asm_l((unsigned long long)x, ptr); break; \
> + retval = __put_user_asm_l((__force unsigned long long)x,\
> + ptr); \
> + break; \
> default: \
> __put_user_bad(); \
> } \
>

Attachment: signature.asc
Description: OpenPGP digital signature