From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08199C4360F for ; Thu, 4 Apr 2019 09:32:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C6A2D218C3 for ; Thu, 4 Apr 2019 09:32:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554370354; bh=/Bm20F7vuP6wZZ0DYuwO9ZH6kint0espPdNPzSvvYIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=AFllonM2JzcWZmhnwuOCPteKBHfoy308MNqN5T5xpUPM31+YwWgBPk05dhsjcF5qO PaqRWQNldD517U569gk2OU9K7nS9OtvtnlVcsfhGJDjDumU05KJ6m4NAbisd8l6NM/ MrA7XGx/RWcp/0Kbxkimju7Wa7jjgK3/5AyOJPsI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729731AbfDDJcd (ORCPT ); Thu, 4 Apr 2019 05:32:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:47936 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732712AbfDDJIt (ORCPT ); Thu, 4 Apr 2019 05:08:49 -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 EF6132183E; Thu, 4 Apr 2019 09:08:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368928; bh=/Bm20F7vuP6wZZ0DYuwO9ZH6kint0espPdNPzSvvYIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OLPTEKLDa0pqOzIf45GcS2g3rX9KhI4WUmt2mL4hnCJ2PjUdId5BiUOhTKmV42IC/ 6OG+4YUdMrgIe+EdPJY5BVy60nQuAXbMgcn1SdFK4SFVUECFN0xamjYY7XZtHszA+f MfE/OVElPrtKoqDCtHiZl0d7sb30+gwO+q/gID8M= 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 5.0 017/246] sysctl: handle overflow for file-max Date: Thu, 4 Apr 2019 10:45:17 +0200 Message-Id: <20190404084619.774490082@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084619.236418459@linuxfoundation.org> References: <20190404084619.236418459@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 5.0-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 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