Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1567079

[PATCH 1/2] x86/fpu: move copyout_from_xsaves bounds check before the copy

From riel@redhat.com
Newsgroups linux.kernel
Subject [PATCH 1/2] x86/fpu: move copyout_from_xsaves bounds check before the copy
Date 2017-01-26 03:10 +0100
Message-ID <t3HFD-1sp-7@gated-at.bofh.it> (permalink)
References <t3HFD-1sp-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Rik van Riel <riel@redhat.com>

Userspace may have programs, especially debuggers, that do not know
how large the full XSAVE area space is. They pass in a size argument,
and expect to not get more data than that.

Unfortunately, the current copyout_from_xsaves does the bounds check
after the copy out to userspace.  This could theoretically result
in the kernel scribbling over userspace memory outside of the buffer,
before bailing out of the copy.

In practice, this is not likely to be an issue, since debuggers are
likely to specify the size they know about, and that size is likely
to exactly match the XSAVE fields they know about.

However, we could be a little more careful and do the bounds check
before committing ourselves with a copy to userspace.

Signed-off-by: Rik van Riel <riel@redhat.com>
---
 arch/x86/kernel/fpu/xstate.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index c24ac1efb12d..c1508d56ecfb 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -992,13 +992,13 @@ int copyout_from_xsaves(unsigned int pos, unsigned int count, void *kbuf,
 			offset = xstate_offsets[i];
 			size = xstate_sizes[i];
 
+			if (offset + size > count)
+				break;
+
 			ret = xstate_copyout(offset, size, kbuf, ubuf, src, 0, count);
 
 			if (ret)
 				return ret;
-
-			if (offset + size >= count)
-				break;
 		}
 
 	}
-- 
2.9.3

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH 1/2] x86/fpu: move copyout_from_xsaves bounds check before the copy riel@redhat.com - 2017-01-26 03:10 +0100
  Re: [PATCH 1/2] x86/fpu: move copyout_from_xsaves bounds check  before the copy Ingo Molnar <mingo@kernel.org> - 2017-01-26 10:50 +0100
    Re: [PATCH 1/2] x86/fpu: move copyout_from_xsaves bounds check  before the copy Ingo Molnar <mingo@kernel.org> - 2017-01-26 10:50 +0100

csiph-web