]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.0.49/kernel-sys.c-fix-stack-memory-content-leak-via-uname26.patch
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 3.0.49 / kernel-sys.c-fix-stack-memory-content-leak-via-uname26.patch
1 From 2702b1526c7278c4d65d78de209a465d4de2885e Mon Sep 17 00:00:00 2001
2 From: Kees Cook <keescook@chromium.org>
3 Date: Fri, 19 Oct 2012 13:56:51 -0700
4 Subject: kernel/sys.c: fix stack memory content leak via UNAME26
5
6 From: Kees Cook <keescook@chromium.org>
7
8 commit 2702b1526c7278c4d65d78de209a465d4de2885e upstream.
9
10 Calling uname() with the UNAME26 personality set allows a leak of kernel
11 stack contents. This fixes it by defensively calculating the length of
12 copy_to_user() call, making the len argument unsigned, and initializing
13 the stack buffer to zero (now technically unneeded, but hey, overkill).
14
15 CVE-2012-0957
16
17 Reported-by: PaX Team <pageexec@freemail.hu>
18 Signed-off-by: Kees Cook <keescook@chromium.org>
19 Cc: Andi Kleen <ak@linux.intel.com>
20 Cc: PaX Team <pageexec@freemail.hu>
21 Cc: Brad Spengler <spender@grsecurity.net>
22 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
23 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
24 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
25
26 ---
27 kernel/sys.c | 12 +++++++-----
28 1 file changed, 7 insertions(+), 5 deletions(-)
29
30 --- a/kernel/sys.c
31 +++ b/kernel/sys.c
32 @@ -1133,15 +1133,16 @@ DECLARE_RWSEM(uts_sem);
33 * Work around broken programs that cannot handle "Linux 3.0".
34 * Instead we map 3.x to 2.6.40+x, so e.g. 3.0 would be 2.6.40
35 */
36 -static int override_release(char __user *release, int len)
37 +static int override_release(char __user *release, size_t len)
38 {
39 int ret = 0;
40 - char buf[65];
41
42 if (current->personality & UNAME26) {
43 - char *rest = UTS_RELEASE;
44 + const char *rest = UTS_RELEASE;
45 + char buf[65] = { 0 };
46 int ndots = 0;
47 unsigned v;
48 + size_t copy;
49
50 while (*rest) {
51 if (*rest == '.' && ++ndots >= 3)
52 @@ -1151,8 +1152,9 @@ static int override_release(char __user
53 rest++;
54 }
55 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
56 - snprintf(buf, len, "2.6.%u%s", v, rest);
57 - ret = copy_to_user(release, buf, len);
58 + copy = min(sizeof(buf), max_t(size_t, 1, len));
59 + copy = scnprintf(buf, copy, "2.6.%u%s", v, rest);
60 + ret = copy_to_user(release, buf, copy + 1);
61 }
62 return ret;
63 }