Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10389743imu; Wed, 5 Dec 2018 23:35:23 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vz9kXqK/mE7UgFQAQMrPjmHCsf16X6d7UTryhG54bShQaXubmw0ZtdQetr6P4ghc2YLzM5 X-Received: by 2002:a63:c70d:: with SMTP id n13mr23729012pgg.108.1544081723510; Wed, 05 Dec 2018 23:35:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544081723; cv=none; d=google.com; s=arc-20160816; b=pULncjMAQKmz2MEXX5KJ3L3+InTduhLp7YBxa5+E0Eb8uR5DCWuXfdrjZ5mEZH2nv5 +eaL0hYvGhn3pLM1RwUElqSKc0z/OANy5QvmRukL3CC+ZVsq5z23IoBWahxElAFJY5JK aIj/z8K6EIaAnJUIGMgZOYsB1yE/qQERUsxB1G2bWXfYugHPyX7I+8nJRQQfqZ9VscVT CtUv5DlW4NcI/gBrajBIl+qISixF6T5D7MKw996qPWgnKmHi/h88yKfOhv4RlkkuWci4 FhGepZN8e5/RSjVGe8/mOvZ3TjFVLgMJX7GLDb+cvg71wy069+ZEx7ynGQ81BIoC62v4 AFww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=BoByAUKXbKKNYndkJMl1xvPS4aEuu2afMvZtoxdCsTI=; b=picPTtR/b8LUwTSn4BSP+S1W8g2MxO4h9lfW5jku7bfMKpkKh7AehqLD8K1j8MOGK8 hkO9+F2pUARBQwMSEULl4p9nu7GsC5QxMDBLR/OKRTj3vbwZtXUHfGmqLq0QylJL8/vj 1GMQjuB3kUYQiVWFGBPNY9pufHFKQ8XDF9u6uiQqPoK7GPDgG7ALnznRRy+YtBz1gS+V cNaMxdzYpBoY/KRffttHf9J4yAS2gWxbm0hTwvp+TNK3x098NQIn2DnOSQ3m+yjTSST4 bYpJmXxoWLIAuXRsntTAEZy4zvuKvx8zG8TkiX1ObHHW4N1emb5Af+2vei+y4t8rB0Ma 7bRg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v10si22060582plp.183.2018.12.05.23.35.07; Wed, 05 Dec 2018 23:35:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729321AbeLFHdb (ORCPT + 99 others); Thu, 6 Dec 2018 02:33:31 -0500 Received: from mxhk.zte.com.cn ([63.217.80.70]:54562 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729038AbeLFHd2 (ORCPT ); Thu, 6 Dec 2018 02:33:28 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id E2F7E7F0D8B42B9CAE03; Thu, 6 Dec 2018 15:33:25 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id wB67XMik013184; Thu, 6 Dec 2018 15:33:22 +0800 (GMT-8) (envelope-from cheng.lin130@zte.com.cn) Received: from fox-host8.localdomain ([10.74.120.8]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018120615334773-15085957 ; Thu, 6 Dec 2018 15:33:47 +0800 From: Cheng Lin To: mcgrof@kernel.org Cc: keescook@chromium.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, zhong.weidong@zte.com.cn, wang.yi59@zte.com.cn, Cheng Lin Subject: [PATCH] proc/sysctl: fix return error for proc_doulongvec_minmax Date: Thu, 6 Dec 2018 15:36:15 +0800 Message-Id: <1544081775-15720-1-git-send-email-cheng.lin130@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-12-06 15:33:47, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-12-06 15:33:11, Serialize complete at 2018-12-06 15:33:11 X-MAIL: mse01.zte.com.cn wB67XMik013184 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the number of input parameters is less than the total parameters, an EINVAL error will be returned. e.g. We use proc_doulongvec_minmax to pass up to two parameters with kern_table. { .procname = "monitor_signals", .data = &monitor_sigs, .maxlen = 2*sizeof(unsigned long), .mode = 0644, .proc_handler = proc_doulongvec_minmax, }, Reproduce: When passing two parameters, it's work normal. But passing only one parameter, an error "Invalid argument"(EINVAL) is returned. [root@cl150 ~]# echo 1 2 > /proc/sys/kernel/monitor_signals [root@cl150 ~]# cat /proc/sys/kernel/monitor_signals 1 2 [root@cl150 ~]# echo 3 > /proc/sys/kernel/monitor_signals -bash: echo: write error: Invalid argument [root@cl150 ~]# echo $? 1 [root@cl150 ~]# cat /proc/sys/kernel/monitor_signals 3 2 [root@cl150 ~]# The following is the result after apply this patch. No error is returned when the number of input parameters is less than the total parameters. [root@cl150 ~]# echo 1 2 > /proc/sys/kernel/monitor_signals [root@cl150 ~]# cat /proc/sys/kernel/monitor_signals 1 2 [root@cl150 ~]# echo 3 > /proc/sys/kernel/monitor_signals [root@cl150 ~]# echo $? 0 [root@cl150 ~]# cat /proc/sys/kernel/monitor_signals 3 2 [root@cl150 ~]# There are three processing functions dealing with digital parameters, __do_proc_dointvec/__do_proc_douintvec/__do_proc_doulongvec_minmax. This patch deals with __do_proc_doulongvec_minmax, just as __do_proc_dointvec does, adding a check for parameters 'left'. In __do_proc_douintvec, its code implementation explicitly does not support multiple inputs. static int __do_proc_douintvec(...){ ... /* * Arrays are not supported, keep this simple. *Do not* add * support for them. */ if (vleft != 1) { *lenp = 0; return -EINVAL; } ... } So, just __do_proc_doulongvec_minmax has the problem. And most use of proc_doulongvec_minmax/proc_doulongvec_ms_jiffies_minmax just have one parameter. Signed-off-by: Cheng Lin --- kernel/sysctl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 5fc724e..9ee261f 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2779,6 +2779,8 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int bool neg; left -= proc_skip_spaces(&p); + if (!left) + break; err = proc_get_long(&p, &left, &val, &neg, proc_wspace_sep, -- 1.8.3.1