From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752821AbbJLOfa (ORCPT ); Mon, 12 Oct 2015 10:35:30 -0400 Received: from terminus.zytor.com ([198.137.202.10]:48068 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752742AbbJLOcR (ORCPT ); Mon, 12 Oct 2015 10:32:17 -0400 Date: Mon, 12 Oct 2015 07:31:03 -0700 From: tip-bot for Aravind Gopalakrishnan Message-ID: Cc: torvalds@linux-foundation.org, bp@suse.de, tglx@linutronix.de, mingo@kernel.org, bp@alien8.de, peterz@infradead.org, hpa@zytor.com, Aravind.Gopalakrishnan@amd.com, linux-kernel@vger.kernel.org, tony.luck@intel.com Reply-To: Aravind.Gopalakrishnan@amd.com, hpa@zytor.com, linux-kernel@vger.kernel.org, tony.luck@intel.com, bp@alien8.de, mingo@kernel.org, bp@suse.de, tglx@linutronix.de, torvalds@linux-foundation.org, peterz@infradead.org In-Reply-To: <1444641762-9437-3-git-send-email-bp@alien8.de> References: <1443190851-2172-2-git-send-email-Aravind.Gopalakrishnan@amd.com> <1444641762-9437-3-git-send-email-bp@alien8.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:ras/core] x86/ras/mce_amd_inj: Return early on invalid input Git-Commit-ID: 85c9306d44f757d2fb3b0e3e399080a025315c7f X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 85c9306d44f757d2fb3b0e3e399080a025315c7f Gitweb: http://git.kernel.org/tip/85c9306d44f757d2fb3b0e3e399080a025315c7f Author: Aravind Gopalakrishnan AuthorDate: Mon, 12 Oct 2015 11:22:38 +0200 Committer: Ingo Molnar CommitDate: Mon, 12 Oct 2015 16:15:47 +0200 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 Signed-off-by: Borislav Petkov Cc: Borislav Petkov Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Tony Luck 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 --- arch/x86/ras/mce_amd_inj.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/x86/ras/mce_amd_inj.c b/arch/x86/ras/mce_amd_inj.c index 17e35b5..4fd8bb9 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, { char buf[MAX_FLAG_OPT_SIZE], *__buf; int err; - size_t ret; if (cnt > MAX_FLAG_OPT_SIZE) - cnt = MAX_FLAG_OPT_SIZE; - - ret = cnt; + return -EINVAL; if (copy_from_user(&buf, ubuf, cnt)) return -EFAULT; @@ -150,9 +147,9 @@ static ssize_t flags_write(struct file *filp, const char __user *ubuf, return err; } - *ppos += ret; + *ppos += cnt; - return ret; + return cnt; } static const struct file_operations flags_fops = {