Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932134Ab3EaVPu (ORCPT ); Fri, 31 May 2013 17:15:50 -0400 Received: from mail-bk0-f53.google.com ([209.85.214.53]:55737 "EHLO mail-bk0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756301Ab3EaVPn (ORCPT ); Fri, 31 May 2013 17:15:43 -0400 From: Mathias Krause To: Ananth N Mavinakayanahalli , Anil S Keshavamurthy , Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, Mathias Krause , "David S. Miller" , Andrew Morton Subject: [PATCH] kprobes: handle empty/invalid input to debugfs "enabled" file Date: Fri, 31 May 2013 23:15:10 +0200 Message-Id: <1370034910-16268-1-git-send-email-minipli@googlemail.com> X-Mailer: git-send-email 1.7.10.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1493 Lines: 46 When writing invalid input to 'debug/kprobes/enabled' it'll silently be ignored. Even worse, when writing an empty string to this file, the outcome is purely random as the switch statement will make its decision based on the value of an uninitialized stack variable. Fix this by handling invalid/empty input as error returning -EINVAL. Cc: Ananth N Mavinakayanahalli Cc: Anil S Keshavamurthy Cc: "David S. Miller" Cc: Masami Hiramatsu Cc: Andrew Morton Signed-off-by: Mathias Krause --- kernel/kprobes.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 3fed7f0..948b597 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -2322,6 +2322,7 @@ static ssize_t write_enabled_file_bool(struct file *file, if (copy_from_user(buf, user_buf, buf_size)) return -EFAULT; + buf[buf_size] = '\0'; switch (buf[0]) { case 'y': case 'Y': @@ -2333,6 +2334,8 @@ static ssize_t write_enabled_file_bool(struct file *file, case '0': disarm_all_kprobes(); break; + default: + return -EINVAL; } return count; -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/