From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754883AbdA0NNE (ORCPT ); Fri, 27 Jan 2017 08:13:04 -0500 Received: from bastet.se.axis.com ([195.60.68.11]:43830 "EHLO bastet.se.axis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754832AbdA0NLw (ORCPT ); Fri, 27 Jan 2017 08:11:52 -0500 From: Rabin Vincent To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, bp@suse.de, Rabin Vincent Subject: [PATCH] printk: fix printk.devkmsg sysctl Date: Fri, 27 Jan 2017 14:11:46 +0100 Message-Id: <1485522706-18852-1-git-send-email-rabin.vincent@axis.com> X-Mailer: git-send-email 2.1.4 X-TM-AS-GCONF: 00 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rabin Vincent The comment says that it doesn't want to accept trailing crap but that's just what it allows: # echo -n offX > /proc/sys/kernel/printk_devkmsg # while at the same time it rejects legitimate uses: # echo -n off > /proc/sys/kernel/printk_devkmsg -sh: echo: write error: Invalid argument Fix it. Before this patch: # cat /proc/sys/kernel/printk_devkmsg ratelimit # echo off > /proc/sys/kernel/printk_devkmsg # sysctl -w kernel.printk_devkmsg=off sysctl: short write # echo -n off > /proc/sys/kernel/printk_devkmsg -sh: echo: write error: Invalid argument # echo -n offX > /proc/sys/kernel/printk_devkmsg # # printf "off\nX" >/proc/sys/kernel/printk_devkmsg -sh: printf: write error: Invalid argument After this patch: # cat /proc/sys/kernel/printk_devkmsg ratelimit # echo off > /proc/sys/kernel/printk_devkmsg # sysctl -w kernel.printk_devkmsg=off kernel.printk_devkmsg = off # echo -n off > /proc/sys/kernel/printk_devkmsg # echo -n offX > /proc/sys/kernel/printk_devkmsg -sh: echo: write error: Invalid argument # printf "off\nX" >/proc/sys/kernel/printk_devkmsg # As a side effect, the "off\nX" case is not rejected anymore, but that is how the other sysctl files behave: # cat /proc/sys/kernel/printk_ratelimit 0 # printf "5\nX" >/proc/sys/kernel/printk_ratelimit # cat /proc/sys/kernel/printk_ratelimit 5 Fixes: 750afe7babd117d ("printk: add kernel parameter to control writes to /dev/kmsg") Signed-off-by: Rabin Vincent --- kernel/printk/printk.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 8b26964..032b9e0 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -107,15 +107,15 @@ static int __control_devkmsg(char *str) if (!str) return -EINVAL; - if (!strncmp(str, "on", 2)) { + if (!strcmp(str, "on")) { devkmsg_log = DEVKMSG_LOG_MASK_ON; - return 2; - } else if (!strncmp(str, "off", 3)) { + return 0; + } else if (!strcmp(str, "off")) { devkmsg_log = DEVKMSG_LOG_MASK_OFF; - return 3; - } else if (!strncmp(str, "ratelimit", 9)) { + return 0; + } else if (!strcmp(str, "ratelimit")) { devkmsg_log = DEVKMSG_LOG_MASK_DEFAULT; - return 9; + return 0; } return -EINVAL; } @@ -177,7 +177,7 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, * Do not accept an unknown string OR a known string with * trailing crap... */ - if (err < 0 || (err + 1 != *lenp)) { + if (err < 0) { /* ... and restore old setting. */ devkmsg_log = old; -- 2.1.4