linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Anton Blanchard <anton@samba.org>
To: Michael Neuling <mikey@neuling.org>
Cc: Paul Mackerras <paulus@samba.org>,
	linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
	amodra@gmail.com
Subject: Re: [PATCH] powerpc: Never handle VSX alignment exceptions from kernel
Date: Tue, 20 Aug 2013 20:30:07 +1000	[thread overview]
Message-ID: <20130820203007.4e0803f6@kryten> (raw)
In-Reply-To: <CAEjGV6x6fMPMunzfcm7O0RYHdxEyhnUoH1FcZno2AQRHtqkMVw@mail.gmail.com>


Hi,

> Can you say what will happen when you apply this patch.  ie It
> produces one oops rather than megabytes of crap making it easier
> to debug.

Good point, updated.

> Also, can you give a clue as to how you can hit this since it should
> never happen in the first place.  I assume it's some LE corner case...

While it was found on LE, after reading the POWER7 docs I think we can
hit it pretty easily on BE. All it takes is a 4 byte aligned VSX load
or store. Misaligning the FPR array in the thread struct would be
enough to do it and we'd end up scribbling over memory until we self
destruct.

Anton
--

The VSX alignment handler needs to write out the existing VSX
state to memory before operating on it (flush_vsx_to_thread()).
If we take a VSX alignment exception in the kernel bad things
will happen. It looks like we could write the kernel state out
to the user process, or we could handle the kernel exception
using data from the user process (depending if MSR_VSX is set
or not).

Worse still, if the code to read or write the VSX state causes an
alignment exception, we will recurse forever. I ended up with
hundreds of megabytes of kernel stack to look through as a result.

Floating point and SPE code have similar issues but already include
a user check. Add the same check to emulate_vsx().

With this patch any unaligned VSX loads and stores in the kernel
will show up as a clear oops rather than silent corruption of
kernel or userspace VSX state, or worse, corruption of a potentially
unlimited amount of kernel memory.

Signed-off-by: Anton Blanchard <anton@samba.org>
---

Index: b/arch/powerpc/kernel/align.c
===================================================================
--- a/arch/powerpc/kernel/align.c
+++ b/arch/powerpc/kernel/align.c
@@ -651,6 +651,10 @@ static int emulate_vsx(unsigned char __u
 	int sw = 0;
 	int i, j;
 
+	/* userland only */
+	if (unlikely(!user_mode(regs)))
+		return 0;
+
 	flush_vsx_to_thread(current);
 
 	if (reg < 32)

      reply	other threads:[~2013-08-20 10:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-20  6:05 [PATCH] powerpc: Never handle VSX alignment exceptions from kernel Anton Blanchard
2013-08-20 10:04 ` Michael Neuling
2013-08-20 10:30   ` Anton Blanchard [this message]

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=20130820203007.4e0803f6@kryten \
    --to=anton@samba.org \
    --cc=amodra@gmail.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mikey@neuling.org \
    --cc=paulus@samba.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;
as well as URLs for NNTP newsgroup(s).