Received: by 10.223.176.5 with SMTP id f5csp1437094wra; Wed, 7 Feb 2018 20:05:52 -0800 (PST) X-Google-Smtp-Source: AH8x227xSIQ2t6aEDAs/vPRUpl0bFXnuZ0ppc3hTOpL+la3oqBo4cFB7FMvVSVZ+8wDsiTWVz9Q6 X-Received: by 10.99.127.90 with SMTP id p26mr6813323pgn.252.1518062752701; Wed, 07 Feb 2018 20:05:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518062752; cv=none; d=google.com; s=arc-20160816; b=baP8nGmy0yBg4lVg92cjqCYMoTR9v3emT4eWmyAhe1Rkkoued/h9aMkOmKDkXwwEWM CuiTTnXCo43P3iuR+4DkArzkzzq3ns7f61GFWIP8mVHdRL1Air7O9CGeY3W2Q37gYa7r TjyR4eWCuiZtadlbPNW3RyHskB/OtOoz79Mm+wSsMhtHOVH9SfmZ8eNdzz/SX6+eAWed gDYqNrxeT6riKPtPN1aC/j5B6JsqADAozf2KSqXM0sMxHpWpnNGo0tx8Ng4boBAWCtoD 1BYODLkyzytDJUllB/9mq2CgerkZu8fPaUtVlgWZP76AmCoMptlOXv/4/r52+qvkgLR7 z29w== 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:arc-authentication-results; bh=EY0nM7visqBv8f40UKRzqz/yUY0BC6legCi+dMJ2SYs=; b=ldiPk/x00R4HSPgwJltdeELkFinAt5/d8Gdn5fcTy7c02DbipyZ/T6Fz/peNKUUEvP rvi1eAk+Kv8Jr38PWD23EVm7g4M/P3uFXc2JwYwxd+gdycqKYUtBaTBLX4Jwi46HGLN0 z/Snavlc9pO0Q+1WEyJtrH5nUs3kGATshlE8o7HxTIJMa3c2CD2sWp9VBcodPVACD8NG aIyd8sitcSAFOgrB7UUl/Ub96AZyMfkbu8xZ/RmXek/nlWKo9XQm3jpbornxWq5C09MO YBnV9U5yx2zXWx1MaIMjiEyaakfLIR/cfcSQxmPhbiC8LRRxHVVNs22oN0sI+P7ewZsi OZ6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=QCyaNoCh; 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 n11si1851526pgq.230.2018.02.07.20.05.37; Wed, 07 Feb 2018 20:05:52 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=QCyaNoCh; 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 S1751190AbeBHEE7 (ORCPT + 99 others); Wed, 7 Feb 2018 23:04:59 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:41093 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750806AbeBHEE6 (ORCPT ); Wed, 7 Feb 2018 23:04:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=EY0nM7visqBv8f40UKRzqz/yUY0BC6legCi+dMJ2SYs=; b=QCyaNoCh8Q3CBGnS/N8eindul rpzDJk6hwsLhczGcLVvIe8HtQ7iaT9yX+r0vayJ8aTNRwBcmyes2w7pdwrAPydRnpUEb9ccOwlsez OHrPX9LOowaQadPaDoDV1gdZu7gO2eDD85R1elA5QLV5s7eKgVYbbETPafcPRWthvp/598Ztff3wa hJmYiuO2tcTbbJ3XxIAsuA7AESOYNL428MjYYJAu/6uMk0L7WIgi/bpaTvE3xE+zJvrJlf+p9tDp7 yrFQGJQ3wkSLRKLog7RKcdtxL8g/IhaqNTRH1IortzbbB6uQyGxL7UwCMeVNG1n+o880bBO5hURgA knj5/0iZg==; Received: from willy by bombadil.infradead.org with local (Exim 4.89 #1 (Red Hat Linux)) id 1ejdSB-0002wX-Ji; Thu, 08 Feb 2018 04:04:55 +0000 Date: Wed, 7 Feb 2018 20:04:55 -0800 From: Matthew Wilcox To: Jann Horn Cc: linux-mm@kvack.org, Kernel Hardening , kernel list , "Kirill A. Shutemov" Subject: Re: [RFC] Warn the user when they could overflow mapcount Message-ID: <20180208040455.GC14918@bombadil.infradead.org> References: <20180208021112.GB14918@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 08, 2018 at 03:56:26AM +0100, Jann Horn wrote: > How much memory would you need to trigger this? You need one > vm_area_struct per increment, and those are 200 bytes? So at least > 800GiB of memory for the vm_area_structs, and maybe more for other > data structures? That's a good point that I hadn't considered. Systems with that quantity of memory are becoming available though. > On systems with RAM on the order of terabytes, it's probably a good > idea to turn on refcount hardening to make issues like that > non-exploitable for now. _mapcount is a bad candidate to be turned into a refcount_t. It's completely legitimate to go to 0 and then back to 1. Also, we care about being able to efficiently notice when it goes from 2 to 1 and then from 1 to 0 (and we currently do that by biasing the count by -1). I suppose it wouldn't be too hard to notice when we go from 0x7fff'ffff to 0x8000'0000 and saturate the counter there. > > 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. > > I have negative feelings about this patch, mostly because AFAICS: > > - It documents an issue instead of fixing it. I prefer to think of it as warning the sysadmin they're doing something dangerous, rather than preventing them from doing it ... > - It likely only addresses a small part of the actual problem. By this, you mean that there's a more general class of problem, and I make no attempt to address it? > > + if ((INT_MAX / max_map_count) > pid_max) > > + pr_warn("pid_max is dangerously large\n"); > > This in reordered is "if (pid_max * max_map_count < INT_MAX) > pr_warn(...);", no? That doesn't make sense to me. Same thing again > further down. I should get more sleep before writing patches. > > - if (unlikely(mm->map_count >= sysctl_max_map_count)) { > > + if (unlikely(mm->map_count >= max_map_count)) { > > Why the renaming? Because you can't have a function and an integer with the same name, and the usual pattern we follow is that sysctl_foo_bar() is the function to handle the variable foo_bar.