From patchwork Sat Jan 22 06:13:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12720523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D08AC433F5 for ; Sat, 22 Jan 2022 06:13:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33A4B6B00B2; Sat, 22 Jan 2022 01:13:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 310326B00C7; Sat, 22 Jan 2022 01:13:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F3B96B00CC; Sat, 22 Jan 2022 01:13:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0112.hostedemail.com [216.40.44.112]) by kanga.kvack.org (Postfix) with ESMTP id 0EDEF6B00B2 for ; Sat, 22 Jan 2022 01:13:52 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id CE0B196375 for ; Sat, 22 Jan 2022 06:13:51 +0000 (UTC) X-FDA: 79056907062.07.C2BA496 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf15.hostedemail.com (Postfix) with ESMTP id 66ED3A0003 for ; Sat, 22 Jan 2022 06:13:51 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 639AAB82100; Sat, 22 Jan 2022 06:13:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBDFAC004E1; Sat, 22 Jan 2022 06:13:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1642832029; bh=1x4JN5S0n9RZ0qlKxGN3jfVL3NgvlQumpjqKP1bFW9Q=; h=Date:From:To:Subject:In-Reply-To:From; b=j20TdlmqPVf3y8HCrTBkYyWWuwSQUQAhBQpF+/5KB/ywT1v7HhEQgrtRYiiPGU/KV nINPPSxZezq8nZri2zdnLTc7r27n82XhsXaiQaS5ZxS7DM3ip3QyttanYQ6QKqhUOt PzvdueyQTnaiVDaWH4+TuIUNx35Ryr40q9RfYjQU= Date: Fri, 21 Jan 2022 22:13:48 -0800 From: Andrew Morton To: akpm@linux-foundation.org, hulkci@huawei.com, libaokun1@huawei.com, linux-mm@kvack.org, mcgrof@kernel.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 43/69] sysctl: returns -EINVAL when a negative value is passed to proc_doulongvec_minmax Message-ID: <20220122061348.oKWIG8D09%akpm@linux-foundation.org> In-Reply-To: <20220121221021.60533b009c357d660791476e@linux-foundation.org> User-Agent: s-nail v14.8.16 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=j20Tdlmq; dmarc=none; spf=pass (imf15.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 66ED3A0003 X-Stat-Signature: 6a5txcn35odqt85urmmyyeqwe3eeuy6e X-HE-Tag: 1642832031-41213 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Baokun Li Subject: sysctl: returns -EINVAL when a negative value is passed to proc_doulongvec_minmax When we pass a negative value to the proc_doulongvec_minmax() function, the function returns 0, but the corresponding interface value does not change. we can easily reproduce this problem with the following commands: cd /proc/sys/fs/epoll echo -1 > max_user_watches; echo $?; cat max_user_watches This function requires a non-negative number to be passed in, so when a negative number is passed in, -EINVAL is returned. Link: https://lkml.kernel.org/r/20211220092627.3744624-1-libaokun1@huawei.com Signed-off-by: Baokun Li Reported-by: Hulk Robot Acked-by: Luis Chamberlain Signed-off-by: Andrew Morton --- kernel/sysctl.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/kernel/sysctl.c~sysctl-returns-einval-when-a-negative-value-is-passed-to-proc_doulongvec_minmax +++ a/kernel/sysctl.c @@ -1145,10 +1145,11 @@ static int __do_proc_doulongvec_minmax(v err = proc_get_long(&p, &left, &val, &neg, proc_wspace_sep, sizeof(proc_wspace_sep), NULL); - if (err) + if (err || neg) { + err = -EINVAL; break; - if (neg) - continue; + } + val = convmul * val / convdiv; if ((min && val < *min) || (max && val > *max)) { err = -EINVAL;