aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>2015-10-12 05:22:38 -0400
committerIngo Molnar <mingo@kernel.org>2015-10-12 10:15:47 -0400
commit85c9306d44f757d2fb3b0e3e399080a025315c7f (patch)
treef3739ff23a559c7370e6a578edbde3daad2e3c5a
parentcdbcd239e2e264dc3ef7bc7865bcb8ec0023876f (diff)
x86/ras/mce_amd_inj: Return early on invalid input
Invalid inputs such as these are currently reported in dmesg as failing: $> echo sweet > flags [ 122.079139] flags_write: Invalid flags value: et even though the 'flags' attribute has been updated correctly: $> cat flags sw This is because userspace keeps writing the remaining buffer until it encounters an error. However, the input as a whole is wrong and we should not be writing anything to the file. Therefore, correct flags_write() to return -EINVAL immediately on bad input strings. Signed-off-by: Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com> Signed-off-by: Borislav Petkov <bp@suse.de> Cc: Borislav Petkov <bp@alien8.de> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tony Luck <tony.luck@intel.com> Link: http://lkml.kernel.org/r/1443190851-2172-2-git-send-email-Aravind.Gopalakrishnan@amd.com Link: http://lkml.kernel.org/r/1444641762-9437-3-git-send-email-bp@alien8.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/ras/mce_amd_inj.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/arch/x86/ras/mce_amd_inj.c b/arch/x86/ras/mce_amd_inj.c
index 17e35b5bf779..4fd8bb9b90b9 100644
--- a/arch/x86/ras/mce_amd_inj.c
+++ b/arch/x86/ras/mce_amd_inj.c
@@ -129,12 +129,9 @@ static ssize_t flags_write(struct file *filp, const char __user *ubuf,
129{ 129{
130 char buf[MAX_FLAG_OPT_SIZE], *__buf; 130 char buf[MAX_FLAG_OPT_SIZE], *__buf;
131 int err; 131 int err;
132 size_t ret;
133 132
134 if (cnt > MAX_FLAG_OPT_SIZE) 133 if (cnt > MAX_FLAG_OPT_SIZE)
135 cnt = MAX_FLAG_OPT_SIZE; 134 return -EINVAL;
136
137 ret = cnt;
138 135
139 if (copy_from_user(&buf, ubuf, cnt)) 136 if (copy_from_user(&buf, ubuf, cnt))
140 return -EFAULT; 137 return -EFAULT;
@@ -150,9 +147,9 @@ static ssize_t flags_write(struct file *filp, const char __user *ubuf,
150 return err; 147 return err;
151 } 148 }
152 149
153 *ppos += ret; 150 *ppos += cnt;
154 151
155 return ret; 152 return cnt;
156} 153}
157 154
158static const struct file_operations flags_fops = { 155static const struct file_operations flags_fops = {