Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2687867imj; Mon, 11 Feb 2019 07:03:14 -0800 (PST) X-Google-Smtp-Source: AHgI3IZz7oVGCIPtfwHzMaakaWmZ1gOkggvs07oIzYAXZThqvQmU/o3Ng+Npou3OYgOktmpqwt+o X-Received: by 2002:a62:1e87:: with SMTP id e129mr36773658pfe.221.1549897394269; Mon, 11 Feb 2019 07:03:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549897394; cv=none; d=google.com; s=arc-20160816; b=p4pYy3Uk5Vd6UdrGLz+EwC7WFtVp+1t4fsURTHSM6mRCWCLPUVFenzgmG+P9t4leck kguPBqQEtrAPAFe36T9VER/9SyLavmLHfsJMnW2+OvcU3Pgl9AWXbFhC8F91iWvnhpvc PLtLt0Vv/vPMdz2077lFua+/w6j8Pn1H2NqmaydjrWaRbIBVeig3u5yqD87rKot3/ced 2aBXVjSUIVQSokCFO+AY/OUwiW8mNnf0DLp9kN+It08wexlwi6Yup4ZHFq+DYo8pdO1h dSuFbvPkCZt5OoZY+JoKrsht0/7mm6ePsVZ7QA8NQ/40CF8s08ZjzAuCtKFgEIvjVj5A DAag== 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=sO+zRizhOI07Nz09jX9dGSYUa6mmEPtu3oH6lBQhjqo=; b=C38MI4nRInS0DvPQYsP5Q+VcFcaoTsZeCK2SXgH08bC22TEbdmnnXd1acMJKdkHbcZ L49cOXR7+Vi/bJ6csUwhXE+nXkGQAODX3+/j7W/U84ZI9HrPvOEdaUnWSNfqfsqOXdYD vpPO0AVxUFdayq6AAPVjgI7Ue/wSBKzc0uGWMJTPVCP5jFMUe2BxeFE3LJYXCW7Z8Hy+ IdvO3oGjhoXIg/eW08xi/x9oUOuLks+ffKP7UeoEiciGzYAfGJfU7NOpE7i1gb3prvdp FLgaYSjgNSuVEu56UsDbr5AH2E6QvoevKL/tyEK1hX759RMaIrx5Bu/GZtW0Pfr9iNFE dogg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RXIFIE3R; 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 w13si3924239pll.126.2019.02.11.07.02.54; Mon, 11 Feb 2019 07:03:14 -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=RXIFIE3R; 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 S2390284AbfBKPBw (ORCPT + 99 others); Mon, 11 Feb 2019 10:01:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:49966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390273AbfBKPBu (ORCPT ); Mon, 11 Feb 2019 10:01:50 -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 83A90222AF; Mon, 11 Feb 2019 15:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549897310; bh=JCkmsQSdtMeZTZC5r6wo6nn3rqAcGpv5CBUDe/rkjGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RXIFIE3RbObuFAToJ4UITVcA28CcQcZNXB8dyzJG6er1Y+t0OzLS4dC21JIvMA4jK 6DsuMy04AkCM3X+ORfTTJH9C0aU10Ox9aBCY96hHTChJzI+q0e/z1li1i5bsJknP2E Ib2TVrK6JF1YGmfwwOtP0lI6vVBHQtG3GGpPUXHI= 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.14 160/205] proc/sysctl: fix return error for proc_doulongvec_minmax() Date: Mon, 11 Feb 2019 15:19:18 +0100 Message-Id: <20190211141838.828541692@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141827.214852402@linuxfoundation.org> References: <20190211141827.214852402@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.14-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 d330b1ce3b94..3ad00bf90b3d 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2708,6 +2708,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