Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2659876imj; Mon, 11 Feb 2019 06:37:02 -0800 (PST) X-Google-Smtp-Source: AHgI3IbUj8p8JOaP5I91Vm+OQUQcYup07GCy1P1e6N3TjnMaazVeCx/Sz3UCdNJTgblWf7bSCogE X-Received: by 2002:a62:fb07:: with SMTP id x7mr36737504pfm.71.1549895822660; Mon, 11 Feb 2019 06:37:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549895822; cv=none; d=google.com; s=arc-20160816; b=MjSAeLdLH4cAOKFaSodr7Yd+vFvZMNuxYPcytHgiyyRZ2YbbwMoI7EpsF2NvN4u2Je EJkke0QBaBx2Ej/MWbb+I04Y9nWHJcXyVrSp1Wc0oRoxVS5jn8htcr+1Ui4/bjP73/75 ObYmjsxGbxj+P/GFB4ybQizLMK9CkoEk53fXvlsN0fyc2I4Sv/yTgS3BMSdhNdQr21HD QD49m1O4xVK8DEq2jzAUkjEPc8HrMiE9TpzdpYe+bAXX+quBg9xLfpAKvv21cQG0zJQw xwisZQ29qZBoP3X88WNBZMEF6BVR76S3VG88G7ryMvXkKL3uapiC8i3K+11gz9Qg6IrM DPbQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=B8BJkYcjxwBnHAtOZq+057hYyqAxW3GLNbB0iKu4q8A=; b=xfyD7uBT6x3Vdl0CW+M90hUN28MHUxhJqq2CRFFxmiOBZE4x/r7x2bFeHY0wd6ukfw /M21TWwYgYZbP5tMvXjHjrTnNrVlTJRVlIu7B7GGuH5puYr1fQQxnTitz2iERg/+6FYc RnpAY8zAbpOWsLNueE8OCzf+E2lnf289WlJTrFN6mXx4aJj8vvi/VUrdwu2aXyOz3C45 KEadvVxPFCAyrl0MMyyo+BHbkCEnnvlfVKoPAKiBehBE1NcwQ8bxGRmnMsMLBtFn6FoO R9NFX8yA8lOyRpcdB637dJD5+KUwoqWFFUaILA4ujCFpK0UkNPS5w259rvOj9guId/vh hfLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=teE128lv; 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 g1si10015749plo.406.2019.02.11.06.36.46; Mon, 11 Feb 2019 06:37:02 -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=teE128lv; 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 S1731136AbfBKOfz (ORCPT + 99 others); Mon, 11 Feb 2019 09:35:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:44704 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730708AbfBKOfx (ORCPT ); Mon, 11 Feb 2019 09:35:53 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 421EB20844; Mon, 11 Feb 2019 14:35:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895752; bh=9AN8/t67k1Vo7bb8dYquVpBnISjiZbulXm7M2x+kdZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=teE128lv+knaeE7k2ezK4uaWyKdraNEPz9VO9CvgxyXpB28nwLr/i5Y3wZkfuPaL9 vc4lt4Nwt1F+cUeX1+K9fMQPpvo7CGviV+smWSB9uW5iIZwHh370WoGgPYuw1lV498 VW+7sQY60K0d/W9PUpLEu8IJsNKxxQeThTi5TXm8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Cheng Lin , Luis Chamberlain , Kees Cook , Alexey Dobriyan , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.20 284/352] proc/sysctl: fix return error for proc_doulongvec_minmax() Date: Mon, 11 Feb 2019 15:18:31 +0100 Message-Id: <20190211141904.998708566@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 5fc724e4e454..9ee261fce89e 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, -- 2.19.1