Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5656010img; Wed, 27 Mar 2019 12:33:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+/+aklgLnoU3jSpM44E/Xul/UAqbGiRIYGT/xM6hjRNOiQgazMH4WSEr6/AUdYtUs1qaH X-Received: by 2002:a17:902:6aca:: with SMTP id i10mr38304333plt.43.1553715223510; Wed, 27 Mar 2019 12:33:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553715223; cv=none; d=google.com; s=arc-20160816; b=ZPuT+kHoP3b3f285AXISXqerjjsyCKxMt4arfw1NVGgJmLfaK3Sffd8260Al7zqcbp yY9fVDfTQ6lcfaJeIxjlH48J6wxuzd2kjjMt7G4kwOtV0mWt83YU1ez9TtV+EaLonRSr L7zipWG66ZKBnV2GLzDdF/LYTWim/Vtlh7PuX76eUb5oh6KYiZ/MdRXse8onsU7hvcg1 tOplnbk494kQImQfRY227UfNzI7X0T1DA2BEqO/98CNArvZZ/X+a5mgBL61DiOM8ZiVL NqBAY7h9NntxXfcnswYZrEhB8MW/zA1uWQlxns3YAc69ewzd1JOSt+LPRAaOuDvv9WDD ImzA== 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=JkY8kK9y+GxKYanZe47aNledN6D4pDdQiVyEFRogOr4=; b=Toh3I1b4THXAQzWNAdNsT6Y5Awh19xrcImm+tgqUR1FfvzSr45P3Z133z7pzImJhQN 9TpnHHSxNkdBzDuNiCKnEGWDh9tFTxyBkEFCBxzbUuqYsBeqDFQoMoxx2miwyKnqyl4f /fUfsbqoYhI26gTJyyahnaqjHhEhaV/7hP5RV8adZ1RR/aB+6uPJ62yLF6DKk6p5442b DhOaqvzICMEjv2E1BhY2SHY8sROj+0iTrbnteM9j39lS6gge6mXC8M2D9AncWKsgIXch aXoqZB9zSNgl8qHs88p/m8gSEvurwvTFE68EXIvNvv0sMkwVaFeihnOoOq54XnZ59ZNA ZuyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WQ2raMUh; 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 f9si9150297pgm.479.2019.03.27.12.33.28; Wed, 27 Mar 2019 12:33:43 -0700 (PDT) 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=WQ2raMUh; 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 S1731066AbfC0SCi (ORCPT + 99 others); Wed, 27 Mar 2019 14:02:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:42506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730933AbfC0SCg (ORCPT ); Wed, 27 Mar 2019 14:02:36 -0400 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 A22942184E; Wed, 27 Mar 2019 18:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709755; bh=oCw5CKJlnYznozQMTdln4IAd8Z7utoRspNASHMYI75o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WQ2raMUh89nH6FCKRFM2YPigIOyqRQzn2Rgq8i10eEywRR5wf64rW/7A46CyAZVSW W7NkVuTaeM1dBsUW8QBbcOCHx+iJ/2C4HV2ZdL60TAeChkNkeAUfSqNnah8ELBD4Mv Gb6yjDO+V9ir6TzS0rFRCa2h2cy+sCyXosa/QUxw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christian Brauner , Alexey Dobriyan , Al Viro , Dominik Brodowski , "Eric W. Biederman" , Joe Lawrence , Luis Chamberlain , Waiman Long , Andrew Morton , Linus Torvalds , Sasha Levin , linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 021/262] sysctl: handle overflow for file-max Date: Wed, 27 Mar 2019 13:57:56 -0400 Message-Id: <20190327180158.10245-21-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-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: Christian Brauner [ Upstream commit 32a5ad9c22852e6bd9e74bdec5934ef9d1480bc5 ] Currently, when writing echo 18446744073709551616 > /proc/sys/fs/file-max /proc/sys/fs/file-max will overflow and be set to 0. That quickly crashes the system. This commit sets the max and min value for file-max. The max value is set to long int. Any higher value cannot currently be used as the percpu counters are long ints and not unsigned integers. Note that the file-max value is ultimately parsed via __do_proc_doulongvec_minmax(). This function does not report error when min or max are exceeded. Which means if a value largen that long int is written userspace will not receive an error instead the old value will be kept. There is an argument to be made that this should be changed and __do_proc_doulongvec_minmax() should return an error when a dedicated min or max value are exceeded. However this has the potential to break userspace so let's defer this to an RFC patch. Link: http://lkml.kernel.org/r/20190107222700.15954-3-christian@brauner.io Signed-off-by: Christian Brauner Acked-by: Kees Cook Cc: Alexey Dobriyan Cc: Al Viro Cc: Dominik Brodowski Cc: "Eric W. Biederman" Cc: Joe Lawrence Cc: Luis Chamberlain Cc: Waiman Long [christian@brauner.io: v4] Link: http://lkml.kernel.org/r/20190210203943.8227-3-christian@brauner.io Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- kernel/sysctl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index d80bee8ff12e..28ec71d914c7 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -127,6 +127,7 @@ static int __maybe_unused one = 1; static int __maybe_unused two = 2; static int __maybe_unused four = 4; static unsigned long one_ul = 1; +static unsigned long long_max = LONG_MAX; static int one_hundred = 100; static int one_thousand = 1000; #ifdef CONFIG_PRINTK @@ -1722,6 +1723,8 @@ static struct ctl_table fs_table[] = { .maxlen = sizeof(files_stat.max_files), .mode = 0644, .proc_handler = proc_doulongvec_minmax, + .extra1 = &zero, + .extra2 = &long_max, }, { .procname = "nr_open", -- 2.19.1