]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.0.16/oprofile-fix-uninitialized-memory-access-when-writing-to-writing-to-oprofilefs.patch
Linux 4.9.178
[thirdparty/kernel/stable-queue.git] / releases / 3.0.16 / oprofile-fix-uninitialized-memory-access-when-writing-to-writing-to-oprofilefs.patch
1 From 913050b91eb94f194392dd797b1ff3779f606ac0 Mon Sep 17 00:00:00 2001
2 From: Robert Richter <robert.richter@amd.com>
3 Date: Mon, 19 Dec 2011 16:38:30 +0100
4 Subject: oprofile: Fix uninitialized memory access when writing to writing to oprofilefs
5
6 From: Robert Richter <robert.richter@amd.com>
7
8 commit 913050b91eb94f194392dd797b1ff3779f606ac0 upstream.
9
10 If oprofilefs_ulong_from_user() is called with count equals
11 zero, *val remains unchanged. Depending on the implementation it
12 might be uninitialized.
13
14 Change oprofilefs_ulong_from_user()'s interface to return count
15 on success. Thus, we are able to return early if count equals
16 zero which avoids using *val uninitialized. Fixing all users of
17 oprofilefs_ulong_ from_user().
18
19 This follows write syscall implementation when count is zero:
20 "If count is zero ... [and if] no errors are detected, 0 will be
21 returned without causing any other effect." (man 2 write)
22
23 Reported-By: Mike Waychison <mikew@google.com>
24 Signed-off-by: Robert Richter <robert.richter@amd.com>
25 Cc: Andrew Morton <akpm@linux-foundation.org>
26 Cc: oprofile-list <oprofile-list@lists.sourceforge.net>
27 Link: http://lkml.kernel.org/r/20111219153830.GH16765@erda.amd.com
28 Signed-off-by: Ingo Molnar <mingo@elte.hu>
29 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
30
31 ---
32 arch/s390/oprofile/init.c | 2 +-
33 drivers/oprofile/oprofile_files.c | 7 ++++---
34 drivers/oprofile/oprofilefs.c | 11 +++++++++--
35 3 files changed, 14 insertions(+), 6 deletions(-)
36
37 --- a/arch/s390/oprofile/init.c
38 +++ b/arch/s390/oprofile/init.c
39 @@ -90,7 +90,7 @@ static ssize_t hwsampler_write(struct fi
40 return -EINVAL;
41
42 retval = oprofilefs_ulong_from_user(&val, buf, count);
43 - if (retval)
44 + if (retval <= 0)
45 return retval;
46
47 if (oprofile_started)
48 --- a/drivers/oprofile/oprofile_files.c
49 +++ b/drivers/oprofile/oprofile_files.c
50 @@ -45,7 +45,7 @@ static ssize_t timeout_write(struct file
51 return -EINVAL;
52
53 retval = oprofilefs_ulong_from_user(&val, buf, count);
54 - if (retval)
55 + if (retval <= 0)
56 return retval;
57
58 retval = oprofile_set_timeout(val);
59 @@ -84,7 +84,7 @@ static ssize_t depth_write(struct file *
60 return -EINVAL;
61
62 retval = oprofilefs_ulong_from_user(&val, buf, count);
63 - if (retval)
64 + if (retval <= 0)
65 return retval;
66
67 retval = oprofile_set_ulong(&oprofile_backtrace_depth, val);
68 @@ -141,9 +141,10 @@ static ssize_t enable_write(struct file
69 return -EINVAL;
70
71 retval = oprofilefs_ulong_from_user(&val, buf, count);
72 - if (retval)
73 + if (retval <= 0)
74 return retval;
75
76 + retval = 0;
77 if (val)
78 retval = oprofile_start();
79 else
80 --- a/drivers/oprofile/oprofilefs.c
81 +++ b/drivers/oprofile/oprofilefs.c
82 @@ -60,6 +60,13 @@ ssize_t oprofilefs_ulong_to_user(unsigne
83 }
84
85
86 +/*
87 + * Note: If oprofilefs_ulong_from_user() returns 0, then *val remains
88 + * unchanged and might be uninitialized. This follows write syscall
89 + * implementation when count is zero: "If count is zero ... [and if]
90 + * no errors are detected, 0 will be returned without causing any
91 + * other effect." (man 2 write)
92 + */
93 int oprofilefs_ulong_from_user(unsigned long *val, char const __user *buf, size_t count)
94 {
95 char tmpbuf[TMPBUFSIZE];
96 @@ -79,7 +86,7 @@ int oprofilefs_ulong_from_user(unsigned
97 spin_lock_irqsave(&oprofilefs_lock, flags);
98 *val = simple_strtoul(tmpbuf, NULL, 0);
99 spin_unlock_irqrestore(&oprofilefs_lock, flags);
100 - return 0;
101 + return count;
102 }
103
104
105 @@ -99,7 +106,7 @@ static ssize_t ulong_write_file(struct f
106 return -EINVAL;
107
108 retval = oprofilefs_ulong_from_user(&value, buf, count);
109 - if (retval)
110 + if (retval <= 0)
111 return retval;
112
113 retval = oprofile_set_ulong(file->private_data, value);