aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/oprofile/oprofile_files.c
diff options
context:
space:
mode:
authorRobert Richter <robert.richter@amd.com>2011-12-19 10:38:30 -0500
committerIngo Molnar <mingo@elte.hu>2011-12-19 11:18:43 -0500
commit913050b91eb94f194392dd797b1ff3779f606ac0 (patch)
treebcb861e17dc40875ef0f694641392b7177f04852 /drivers/oprofile/oprofile_files.c
parent497f16f21a04060098c0da6ed522fbcafb90c0db (diff)
oprofile: Fix uninitialized memory access when writing to writing to oprofilefs
If oprofilefs_ulong_from_user() is called with count equals zero, *val remains unchanged. Depending on the implementation it might be uninitialized. Change oprofilefs_ulong_from_user()'s interface to return count on success. Thus, we are able to return early if count equals zero which avoids using *val uninitialized. Fixing all users of oprofilefs_ulong_ from_user(). This follows write syscall implementation when count is zero: "If count is zero ... [and if] no errors are detected, 0 will be returned without causing any other effect." (man 2 write) Reported-By: Mike Waychison <mikew@google.com> Signed-off-by: Robert Richter <robert.richter@amd.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: <stable@vger.kernel.org> Cc: oprofile-list <oprofile-list@lists.sourceforge.net> Link: http://lkml.kernel.org/r/20111219153830.GH16765@erda.amd.com Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'drivers/oprofile/oprofile_files.c')
-rw-r--r--drivers/oprofile/oprofile_files.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
index 89f63456646f..84a208dbed93 100644
--- a/drivers/oprofile/oprofile_files.c
+++ b/drivers/oprofile/oprofile_files.c
@@ -45,7 +45,7 @@ static ssize_t timeout_write(struct file *file, char const __user *buf,
45 return -EINVAL; 45 return -EINVAL;
46 46
47 retval = oprofilefs_ulong_from_user(&val, buf, count); 47 retval = oprofilefs_ulong_from_user(&val, buf, count);
48 if (retval) 48 if (retval <= 0)
49 return retval; 49 return retval;
50 50
51 retval = oprofile_set_timeout(val); 51 retval = oprofile_set_timeout(val);
@@ -84,7 +84,7 @@ static ssize_t depth_write(struct file *file, char const __user *buf, size_t cou
84 return -EINVAL; 84 return -EINVAL;
85 85
86 retval = oprofilefs_ulong_from_user(&val, buf, count); 86 retval = oprofilefs_ulong_from_user(&val, buf, count);
87 if (retval) 87 if (retval <= 0)
88 return retval; 88 return retval;
89 89
90 retval = oprofile_set_ulong(&oprofile_backtrace_depth, val); 90 retval = oprofile_set_ulong(&oprofile_backtrace_depth, val);
@@ -141,9 +141,10 @@ static ssize_t enable_write(struct file *file, char const __user *buf, size_t co
141 return -EINVAL; 141 return -EINVAL;
142 142
143 retval = oprofilefs_ulong_from_user(&val, buf, count); 143 retval = oprofilefs_ulong_from_user(&val, buf, count);
144 if (retval) 144 if (retval <= 0)
145 return retval; 145 return retval;
146 146
147 retval = 0;
147 if (val) 148 if (val)
148 retval = oprofile_start(); 149 retval = oprofile_start();
149 else 150 else