* [PATCH] x86/sev-es: Fix SEV-ES #VC handler for string port IO
@ 2021-01-08 2:51 Hyunwook (Wooky) Baek
2021-01-08 17:20 ` Borislav Petkov
0 siblings, 1 reply; 3+ messages in thread
From: Hyunwook (Wooky) Baek @ 2021-01-08 2:51 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov
Cc: Joerg Roedel, Tom Lendacky, David Rientjes, Sean Christopherson,
linux-kernel, x86, Hyunwook (Wooky) Baek
Don't assume dest/source buffers are userspace addresses when manually
copying data for string I/O or MOVS MMIO, as {get,put}_user() will fail
if handed a kernel address and ultimately lead to a kernel panic.
Signed-off-by: Hyunwook (Wooky) Baek <baekhw@google.com>
Acked-by: David Rientjes <rientjes@google.com>
---
arch/x86/kernel/sev-es.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/arch/x86/kernel/sev-es.c b/arch/x86/kernel/sev-es.c
index 0bd1a0fc587e..812494d216ba 100644
--- a/arch/x86/kernel/sev-es.c
+++ b/arch/x86/kernel/sev-es.c
@@ -286,6 +286,12 @@ static enum es_result vc_write_mem(struct es_em_ctxt *ctxt,
u16 d2;
u8 d1;
+ /* If instruction ran in kernel mode and the I/O buffer is in kernel space */
+ if (!user_mode(ctxt->regs) && !access_ok(s, size)) {
+ memcpy(dst, buf, size);
+ return ES_OK;
+ }
+
switch (size) {
case 1:
memcpy(&d1, buf, 1);
@@ -335,6 +341,12 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,
u16 d2;
u8 d1;
+ /* If instruction ran in kernel mode and the I/O buffer is in kernel space */
+ if (!user_mode(ctxt->regs) && !access_ok(s, size)) {
+ memcpy(buf, src, size);
+ return ES_OK;
+ }
+
switch (size) {
case 1:
if (get_user(d1, s))
--
2.29.2.729.g45daf8777d-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/sev-es: Fix SEV-ES #VC handler for string port IO
2021-01-08 2:51 [PATCH] x86/sev-es: Fix SEV-ES #VC handler for string port IO Hyunwook (Wooky) Baek
@ 2021-01-08 17:20 ` Borislav Petkov
2021-01-08 19:32 ` Hyunwook (Wooky) Baek
0 siblings, 1 reply; 3+ messages in thread
From: Borislav Petkov @ 2021-01-08 17:20 UTC (permalink / raw)
To: Hyunwook (Wooky) Baek
Cc: Thomas Gleixner, Ingo Molnar, Joerg Roedel, Tom Lendacky,
David Rientjes, Sean Christopherson, linux-kernel, x86
On Thu, Jan 07, 2021 at 06:51:07PM -0800, Hyunwook (Wooky) Baek wrote:
> Don't assume dest/source buffers are userspace addresses when manually
> copying data for string I/O or MOVS MMIO, as {get,put}_user() will fail
> if handed a kernel address and ultimately lead to a kernel panic.
>
> Signed-off-by: Hyunwook (Wooky) Baek <baekhw@google.com>
> Acked-by: David Rientjes <rientjes@google.com>
> ---
> arch/x86/kernel/sev-es.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/arch/x86/kernel/sev-es.c b/arch/x86/kernel/sev-es.c
> index 0bd1a0fc587e..812494d216ba 100644
> --- a/arch/x86/kernel/sev-es.c
> +++ b/arch/x86/kernel/sev-es.c
> @@ -286,6 +286,12 @@ static enum es_result vc_write_mem(struct es_em_ctxt *ctxt,
> u16 d2;
> u8 d1;
>
> + /* If instruction ran in kernel mode and the I/O buffer is in kernel space */
> + if (!user_mode(ctxt->regs) && !access_ok(s, size)) {
^^^
Just by looking at this patch I know you haven't tested it before sending.
:-(
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/sev-es: Fix SEV-ES #VC handler for string port IO
2021-01-08 17:20 ` Borislav Petkov
@ 2021-01-08 19:32 ` Hyunwook (Wooky) Baek
0 siblings, 0 replies; 3+ messages in thread
From: Hyunwook (Wooky) Baek @ 2021-01-08 19:32 UTC (permalink / raw)
To: Borislav Petkov
Cc: Thomas Gleixner, Ingo Molnar, Joerg Roedel, Tom Lendacky,
David Rientjes, Sean Christopherson, linux-kernel, x86
Hi Borisslav,
My sincere apologies for it.
We actually tested the patch but I made a bad mistake while generating
the patch file to email.
I will send a PATCH V2 after testing the email version patch file from
the scratch.
Regards,
Wooky
On Fri, Jan 8, 2021 at 9:20 AM Borislav Petkov <bp@alien8.de> wrote:
>
> On Thu, Jan 07, 2021 at 06:51:07PM -0800, Hyunwook (Wooky) Baek wrote:
> > Don't assume dest/source buffers are userspace addresses when manually
> > copying data for string I/O or MOVS MMIO, as {get,put}_user() will fail
> > if handed a kernel address and ultimately lead to a kernel panic.
> >
> > Signed-off-by: Hyunwook (Wooky) Baek <baekhw@google.com>
> > Acked-by: David Rientjes <rientjes@google.com>
> > ---
> > arch/x86/kernel/sev-es.c | 12 ++++++++++++
> > 1 file changed, 12 insertions(+)
> >
> > diff --git a/arch/x86/kernel/sev-es.c b/arch/x86/kernel/sev-es.c
> > index 0bd1a0fc587e..812494d216ba 100644
> > --- a/arch/x86/kernel/sev-es.c
> > +++ b/arch/x86/kernel/sev-es.c
> > @@ -286,6 +286,12 @@ static enum es_result vc_write_mem(struct es_em_ctxt *ctxt,
> > u16 d2;
> > u8 d1;
> >
> > + /* If instruction ran in kernel mode and the I/O buffer is in kernel space */
> > + if (!user_mode(ctxt->regs) && !access_ok(s, size)) {
> ^^^
>
> Just by looking at this patch I know you haven't tested it before sending.
>
> :-(
>
> --
> Regards/Gruss,
> Boris.
>
> https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-08 19:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-08 2:51 [PATCH] x86/sev-es: Fix SEV-ES #VC handler for string port IO Hyunwook (Wooky) Baek
2021-01-08 17:20 ` Borislav Petkov
2021-01-08 19:32 ` Hyunwook (Wooky) Baek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).