mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Jann Horn' <jannh@google.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	"H. Peter Anvin" <hpa@zytor.com>
Cc: "x86@kernel.org" <x86@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Signed-off-by : Qiaowei Ren" <qiaowei.ren@intel.com>
Subject: RE: [PATCH 2/2] x86: fix __user annotations
Date: Mon, 1 Apr 2019 14:37:23 +0000	[thread overview]
Message-ID: <ca2d792df2e9420090383f1a65a6d99f@AcuMS.aculab.com> (raw)
In-Reply-To: <20190328212321.92463-2-jannh@google.com>

From: Jann Horn
> Sent: 28 March 2019 21:23
> Fix __user annotations in various places across the x86 tree:
> 
...
>  - generic_load_microcode() deals with a pointer that can be either a
>    kernel pointer or a user pointer; change the code to pass it around as
>    a __user pointer, and add explicit casts to convert between __user and
>    __kernel
...
> -static int get_ucode_fw(void *to, const void *from, size_t n)
> +static int get_ucode_fw(void *to, const void __user *from, size_t n)
>  {
> -	memcpy(to, from, n);
> +	/* cast paired with request_microcode_fw() */
> +	memcpy(to, (const void __force *)from, n);
>  	return 0;
>  }
> 
> @@ -993,7 +996,8 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
>  		return UCODE_NFOUND;
>  	}
> 
> -	ret = generic_load_microcode(cpu, (void *)firmware->data,
> +	/* cast paired with get_ucode_fw() */
> +	ret = generic_load_microcode(cpu, (void __force __user *)firmware->data,
>  				     firmware->size, &get_ucode_fw);
> 
>  	release_firmware(firmware);
> @@ -1001,7 +1005,7 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
>  	return ret;
>  }
> 
> -static int get_ucode_user(void *to, const void *from, size_t n)
> +static int get_ucode_user(void *to, const void __user *from, size_t n)
>  {
>  	return copy_from_user(to, from, n);
>  }
> @@ -1012,7 +1016,7 @@ request_microcode_user(int cpu, const void __user *buf, size_t size)
>  	if (is_blacklisted(cpu))
>  		return UCODE_NFOUND;
> 
> -	return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
> +	return generic_load_microcode(cpu, buf, size, &get_ucode_user);

That is all an 'accident waiting to happen' ...

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  parent reply	other threads:[~2019-04-01 14:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-28 21:23 [PATCH 1/2] kernel.h: use parentheses around argument in u64_to_user_ptr() Jann Horn
2019-03-28 21:23 ` [PATCH 2/2] x86: fix __user annotations Jann Horn
2019-03-29 13:39   ` Borislav Petkov
2019-03-29 15:24     ` Ben Dooks
2019-03-29 16:02     ` Jann Horn
2019-04-01 14:37   ` David Laight [this message]
2019-04-01 15:04     ` Jann Horn
2019-03-29  5:59 ` [PATCH 1/2] kernel.h: use parentheses around argument in u64_to_user_ptr() Mukesh Ojha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ca2d792df2e9420090383f1a65a6d99f@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=qiaowei.ren@intel.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®