Received: by 10.223.176.5 with SMTP id f5csp1407589wra; Wed, 7 Feb 2018 19:19:00 -0800 (PST) X-Google-Smtp-Source: AH8x227QJx25ufJ4TOim/CDrvQEKZ6earfQCocjGN+aqLcJ5t1bR8n2g3g68Wt3dloM1emlY7zrq X-Received: by 10.98.67.138 with SMTP id l10mr7999894pfi.72.1518059940805; Wed, 07 Feb 2018 19:19:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518059940; cv=none; d=google.com; s=arc-20160816; b=NP6iUYhmLeQg1rcEGAppOkev+GswlHBIpJW5koK+BohxT2ty1rcu2nRrWGA7ONN85/ Ayhsjd+RLefSyLmRGDyaAMWAYzTTbZ3NglFDi3pdiPG0/xmctUGMP85DM5aPs9L/+TLB wljTkOS+NLBhGqm4ZiQLm+HtJWgaFBRjcoVHNiwfTEWX4Q8ThYdYKMjq1tBQ8E2Dc7py 5SBdO1ks81Z50SDplA5vMdeJADGOGyaNp+GwW96Lzvowe4SQhiBIeGaolmLqz+EiwLQV H9P9e2GlOWaZatcn7JQtHH4Q198JaVXACth1xBQOaOYyjbk91hQRJcBBrOyOfYC2ivO4 P92g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature :arc-authentication-results; bh=oo4j8PQRS2FUqH91CRt43JycK5uE8XFygGpYiPKIhDI=; b=nBvtcvUTM4dOad88z+j3+wl1XM79MufXbWp5ZNX5gea3m5h4Qu6pjZ+ai4LSb9pJz8 sIpZwGZMUopVesa9jR6y20635FKNQBFVJdoq3GTw+9mh8hkljTjVk2mzheCcmAn4qJKb lVnoU2MAhPARaebWUTBleZTnM1vTlhlJ6fim4CmLy0xrrrAuHRrwjfGohGbPVfu+3tat QDCxhfbfToBbrA61pa6bDWb0Ge74qeqsrHBzBcDoaDUd2q6vsHPgEq3zjk0qVfiTXxpv cJuNXzVMAYve52HKS9H1GB8DDpmrsT85opeXOmPNPLKFp7KqUVs+zZiD3UwGuEln+cQr jD6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tobin.cc header.s=fm2 header.b=j8nNWOEh; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ISmYfg0o; 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 o14-v6si2114313pli.460.2018.02.07.19.18.47; Wed, 07 Feb 2018 19:19:00 -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=@tobin.cc header.s=fm2 header.b=j8nNWOEh; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ISmYfg0o; 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 S1751175AbeBHDSJ (ORCPT + 99 others); Wed, 7 Feb 2018 22:18:09 -0500 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:40225 "EHLO out2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750767AbeBHDSI (ORCPT ); Wed, 7 Feb 2018 22:18:08 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 9CD3320BC4; Wed, 7 Feb 2018 22:18:07 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Wed, 07 Feb 2018 22:18:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tobin.cc; h=cc :content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=oo4j8PQRS2FUqH91CRt43JycK5uE8XFygGpYiPKIhDI=; b=j8nNWOEh iWHXJ1/oE7MDRHFcCQvUCizEH5m51RUsGipzkbcA8MayMIlS1MT1UZ9QBfzKiCaP 5hWoAHEJDMolwReCpYJPkGLNfNvaPfIx9Zq5b7DZMaBXNokXCWW7onnICJs6FlfF p9xuwREMnZXKHBoIXKYSSPJnm8cnUTHQzDfAHWyah0t1JbyY3NiZOSzc4ziQoXRH VqG29C+eMOm4t1HFY50ADP/hO/sIvJ39hHd/Sphn1DMEM4hVophpK5d0OPwTNYxj eZFKTUsTr2wHH7ygqklCDzc1aR2LfIubFE/eazTrGTapqTO+/AGm2Ma9G8S1bQI4 P/w+gKRCQWdktg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=oo4j8PQRS2FUqH91CRt43JycK5uE8 XFygGpYiPKIhDI=; b=ISmYfg0oD41SElJ2qQPo6IcEO59SO4IGaMVQJmSUj8x7l cI0+6d7Mcrm9blAHPZ10vTzzi6Vx/Z1Ff9e+sQq2oFObOXWhPYTVvvu/X8+352wf fxo/j4WMIJVW3zG5k7ljx4plQ3MLm88IqAXRJ6k2Y9zvn2Jfcb45XsEfMaT0R1Ya RyiDWSD/9RK6NNnhbzIdDNHLov/TDoa+ptn4wEYOLCJEcqhUtfC2lB9zplakUlQh pfJSZYF7u2RIfIfNKUjAw169gTj0od1KueRTD8DJJZD+Wqhym2fO17HVCudNYzLa 5iPQaA0PObUrkZZHq6lDs4XwMMyN3LJr02LmqBhDw== X-ME-Sender: Received: from localhost (202-159-155-205.dyn.iinet.net.au [202.159.155.205]) by mail.messagingengine.com (Postfix) with ESMTPA id DCC6224640; Wed, 7 Feb 2018 22:18:06 -0500 (EST) Date: Thu, 8 Feb 2018 14:18:04 +1100 From: "Tobin C. Harding" To: Matthew Wilcox Cc: linux-mm@kvack.org, kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: Re: [RFC] Warn the user when they could overflow mapcount Message-ID: <20180208031804.GD3304@eros> References: <20180208021112.GB14918@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180208021112.GB14918@bombadil.infradead.org> X-Mailer: Mutt 1.5.24 (2015-08-30) User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 07, 2018 at 06:11:12PM -0800, Matthew Wilcox wrote: > > Kirill and I were talking about trying to overflow page->_mapcount > the other day and realised that the default settings of pid_max and > max_map_count prevent it [1]. But there isn't even documentation to > warn a sysadmin that they've just opened themselves up to the possibility > that they've opened their system up to a sufficiently-determined attacker. > > I'm not sufficiently wise in the ways of the MM to understand exactly > what goes wrong if we do wrap mapcount. Kirill says: > > rmap depends on mapcount to decide when the page is not longer mapped. > If it sees page_mapcount() == 0 due to 32-bit wrap we are screwed; > data corruption, etc. > > That seems pretty bad. So here's a patch which adds documentation to the > two sysctls that a sysadmin could use to shoot themselves in the foot, > and adds a warning if they change either of them to a dangerous value. > It's possible to get into a dangerous situation without triggering this > warning (already have the file mapped a lot of times, then lower pid_max, > then raise max_map_count, then map the file a lot more times), but it's > unlikely to happen. > > Comments? > > [1] map_count counts the number of times that a page is mapped to > userspace; max_map_count restricts the number of times a process can > map a page and pid_max restricts the number of processes that can exist. > So map_count can never be larger than pid_max * max_map_count. > > diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt > index 412314eebda6..ec90cd633e99 100644 > --- a/Documentation/sysctl/kernel.txt > +++ b/Documentation/sysctl/kernel.txt > @@ -718,6 +718,8 @@ pid_max: > PID allocation wrap value. When the kernel's next PID value > reaches this value, it wraps back to a minimum PID value. > PIDs of value pid_max or larger are not allocated. > +Increasing this value without decreasing vm.max_map_count may > +allow a hostile user to corrupt kernel memory > > ============================================================== > > diff --git a/Documentation/sysctl/vm.txt b/Documentation/sysctl/vm.txt > index ff234d229cbb..0ab306ea8f80 100644 > --- a/Documentation/sysctl/vm.txt > +++ b/Documentation/sysctl/vm.txt > @@ -379,7 +379,8 @@ While most applications need less than a thousand maps, certain > programs, particularly malloc debuggers, may consume lots of them, > e.g., up to one or two maps per allocation. > > -The default value is 65536. > +The default value is 65530. Increasing this value without decreasing > +pid_max may allow a hostile user to corrupt kernel memory. Just checking - did you mean the final '0' on this value? Tobin