Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp994227yba; Thu, 4 Apr 2019 02:00:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIwBUKUvR2UQedbHC6LU7kH/2B9cBKDZIVmKjRZdqnZExXnyZCu1c88REgAkiCCSZSDgnG X-Received: by 2002:a17:902:d24:: with SMTP id 33mr5274122plu.246.1554368421629; Thu, 04 Apr 2019 02:00:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554368421; cv=none; d=google.com; s=arc-20160816; b=eNd2d7ng3NocoQjDUy3uOEXBNlLqoMxU3uWcj2HQbbThZOofx/riN6WKKy3khZ/kiI 3Li4zicv6x21BuEbWJQZneN3hUFzPAlZbxWFmTJOjCQsVIw2Iqj3QyOJ6XUyqsUwYL+t 0DUpA1HGrbO96KLBmxvLsDDSurMeJCOlSXlRZ8CsJR9mAvs8rqLvh+EqwkO1iwhn53a4 nZ/ZgwzLseyBM4rbcrtFHvqB9Tg1oRzk/h2VGPk/7cPZhS7F5Rg4/uYUKS7UxtbvoP/v T/6r1Boh6L0VF9c/eGZSFfOjZ+/QKXDlcBDkI5XS2UXKMMbxWBi76oiA38XRKB7qoP7U 2M9g== 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=5bhBMzbRZ/P5wiHZyZSLrmsCqKxBEO9mDpjwqhHqK+M=; b=uxOW/YLhWM07zlNRT6A5atuPkAeRqsh3CU24g3K+H9GqKdZBXJLVKU0b16XXiOMyvQ NtDTz9aAGCz0N0vFXvCXwkRb3gNXKkPSvuyq8rYUSqnIe7SYB4QvTzqW9+7DkVNGZLrg yHib2ZE0Ejt5gtuil46sZcfpwYtuAo/D8XHAHUx0ykGNGlfY/DW0VwgITlmgRRcWtUCa 7s9njc4sS79g7DvuBsfgyFDjdloF/qivuCfyKFgyYgWnPdu+1wzaLwAYrcn2tX+J/mb9 vEV3VgjiJQxWC3tXIA9zUH6S0gQlo5Cz+cB16CSCzuMwk8jUBR9e/1NzUdsNoXeV05ae +lPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=so89tzcp; 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 g14si7276495plo.287.2019.04.04.02.00.06; Thu, 04 Apr 2019 02:00:21 -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=so89tzcp; 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 S1731091AbfDDI7a (ORCPT + 99 others); Thu, 4 Apr 2019 04:59:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:35794 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731088AbfDDI73 (ORCPT ); Thu, 4 Apr 2019 04:59:29 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 A401D2177E; Thu, 4 Apr 2019 08:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368368; bh=Z/t/rhvzHX5TMF7k7ezoCSU2TWPHwFy3tqTuGlAWYeE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=so89tzcpNnOPDISlALEkaaJpWTnGtan8dd2sEGgx+9/mNhWrYdeXv4fHMuMb39NAc N3sTKz40C+jf/u7eSGv7zW3McQbgvZNp3nsH6d++Jlep+mmDmPNCgk9o0pMsWomABi P2Y8dhI2mCPDT5eM4iwaPmBKoU8XxRmCjhzpBDHg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christian Brauner , Kees Cook , Alexey Dobriyan , Al Viro , Dominik Brodowski , "Eric W. Biederman" , Joe Lawrence , Luis Chamberlain , Waiman Long , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 014/187] sysctl: handle overflow for file-max Date: Thu, 4 Apr 2019 10:45:51 +0200 Message-Id: <20190404084603.765313114@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@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.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 3b86acd5de4e..9e22660153ff 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -126,6 +126,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 @@ -1695,6 +1696,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