Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3694725imu; Mon, 28 Jan 2019 09:10:51 -0800 (PST) X-Google-Smtp-Source: ALg8bN68gCa5uzEf+4ftlmsDcDWFgE90qbsrVrQXf1d/i56JpadY9UlSWgKLLO/ZaBzfUsz23Lb9 X-Received: by 2002:a63:104d:: with SMTP id 13mr20638191pgq.303.1548695451089; Mon, 28 Jan 2019 09:10:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548695451; cv=none; d=google.com; s=arc-20160816; b=WD3mZSnaXz38sY+8m6Od+t+YlRKMVzVSaePDufej3YjNrsLVcq0jgq+81oYGh2Kq0S at7EtSv0icK3jAmmC5hx2BrDL7EzyfUG4Z/eraKYagI/EdYIerCP3P8edMNHBAz+RcWz Ic4ZxwyWPVrVRi/pBp/FjBacJNsJM+j0zOpZjZD39mJ+i0TakP7zTLtY1TBjKzQa6VGa dQBEKU1zS0farg6yUFPnnyUOAe06rjHB0iEkaPurPyvRuPi5PjhguyKCirE1E/zTB+AC nnAuWz2U4j7ituS9ob3K74WXpmoZZAlw3hzOPDbu/MBnaFa4j21MV4p4iA3PdO7vWIdL Royg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Wawi0wacl2VDulBmKoWjqIfIpuNY4ahlztLyw1gceyg=; b=VYc8rLbVIDf5yU/Q1S5SlTcg4Js1cp1MFaW2UnzdUvjNAamAcda1FN+E+wq513Q78d y/dMJf6pc1Dqi8tZKKVh6Vo+CvBVSpbQ4Op4ZuJOwMszsaLyCd4SuYYKlTms8ldk8/k/ 5/VDaPE7rpQD4EVZNiiqfxDLgTdIM39XACYcv1qeFCn+BuOcTlnqNfY/T+sy8L6ef7tu dpk8xCAd32IoDnEtVG8eSfs3AnmBw/NgBn185oDci7NyWVRIelCzivQMJkVpW+fE6ObW kSd/IQQeiej2xDhWxoBN1221gjJTaBvZ0oiZsuuSt9UTVMYgK4W8M5G7lqz8dDpZ7Xr0 0DXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vSPaXK8+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 20si18619960pft.177.2019.01.28.09.10.35; Mon, 28 Jan 2019 09:10:51 -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; dkim=pass header.i=@kernel.org header.s=default header.b=vSPaXK8+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733013AbfA1QLq (ORCPT + 99 others); Mon, 28 Jan 2019 11:11:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:38996 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732600AbfA1QLn (ORCPT ); Mon, 28 Jan 2019 11:11:43 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9C31B2177E; Mon, 28 Jan 2019 16:11:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691902; bh=MIgTnXGdvwAhlNFEad+tgQmYeP2RKNUoasDWZ1D5/xY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vSPaXK8+jAypxU1RId/XngBneIYDM/Y2f2yiDrGjdl+IF5qyyI2ivw4fVaIIOzGGZ fiRQy1oJQnYIfb5BisbhcoDiUjhY+P/5I6A2WRAZjaexT98mgie/yNwn1ZTk7C3tD7 rvT5BSuCOPQU3SdQeCHBItkUmeBUyWE0VV0vYhc4= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Cheng Lin , Alexey Dobriyan , Andrew Morton , Linus Torvalds , Sasha Levin , linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 253/258] proc/sysctl: fix return error for proc_doulongvec_minmax() Date: Mon, 28 Jan 2019 10:59:19 -0500 Message-Id: <20190128155924.51521-253-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Cheng Lin [ Upstream commit 09be178400829dddc1189b50a7888495dd26aa84 ] If the number of input parameters is less than the total parameters, an EINVAL error will be returned. For example, 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. Link: http://lkml.kernel.org/r/1544081775-15720-1-git-send-email-cheng.lin130@zte.com.cn Signed-off-by: Cheng Lin Acked-by: Luis Chamberlain Reviewed-by: Kees Cook Cc: Alexey Dobriyan Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- kernel/sysctl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index cc02050fd0c4..32dea29d05a0 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2767,6 +2767,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, -- 2.19.1