Received: by 10.223.185.116 with SMTP id b49csp2771436wrg; Mon, 5 Mar 2018 08:26:10 -0800 (PST) X-Google-Smtp-Source: AG47ELsa5WCV1M2O/M9MmGDV3dGMJAbnuxqvOcZaQgv2YhlUb32vVB2eEbdzqliWXONQ7U2lWwzU X-Received: by 2002:a17:902:822:: with SMTP id 31-v6mr13784969plk.362.1520267169993; Mon, 05 Mar 2018 08:26:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520267169; cv=none; d=google.com; s=arc-20160816; b=xrkLpyYkIWiMK2ggoefQmZw4CwAU8myAVOxTqN+3hzIoJruXzg5BZJU21TFRuW8j+q ciU8JjlOV+YM6ik/qoOgMBhaeSMX9i1p/jATlk+8WsRB5jpLyf+MMgx+cwkWmuDsIu1r EpU15iHueWKdBhkEslzIyunx8ekRzWuWAdjf8PLY2tLnwT8xqHoFLrJ8aoCo6Fp0Ajyw 6ozvE+fvsb0ZVhPQJ4sq7ApvvfshM2ebOfvM1jDA4i862DAR9DsRJ7EfsXDPCCSITgj4 D/OBLe2D7y/olYC+WRjvXlRQd6LPpcuNWmkpcw2IxxkGWYQ1MGg+M11thOWx5tGWn3Q9 Jzww== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=apZaAkEhz5c1aXOSvECczVllYwmhd3LNsi00W8NR9Dg=; b=GKRmPwx+tycG3xAHtubV99OrPtqOVokcCBfrPrEB8Rwlg54OOmyIAeRemJgo4eVF7t tqk/E82yiryVTeAaH/xIdYp84cw4lsSjAwZVCGAu2DKTZqdMjp3pmKQo7PpzsULa0WJd +xn6uDhYemO2AH14xJ2yvYMgzojbhvPcWx9kuosWhKvUHToNS9Xnb0ZmgbU8Y/lj3Kde xvNwLDZbWuhti5I9z8VStj2Fem+RsV8CaGOdq2UGThMvACl+pKEnOG+AxSDpLlz1ULWK AP0cVsqNE5vDgaVoEuD2JrMnI2bPPd/VJsFkBue9NS8W3qB/Wm2Z8RzpGZUKKDGzMqWm sUDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=RXiK4kQb; 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 h10si8511254pgq.440.2018.03.05.08.25.55; Mon, 05 Mar 2018 08:26:09 -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=RXiK4kQb; 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 S1752586AbeCEQXv (ORCPT + 99 others); Mon, 5 Mar 2018 11:23:51 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:54846 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752401AbeCEQXt (ORCPT ); Mon, 5 Mar 2018 11:23:49 -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-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To: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=apZaAkEhz5c1aXOSvECczVllYwmhd3LNsi00W8NR9Dg=; b=RXiK4kQbyhKrNr8IFOrXGXint2 rBEKjfjmzz1KfFWigNnjcX9ovpvbVx7gkSrZeRF2T9AHTIVMvgi1ORsmiM9G35pHstSqqM7fy2Iba 9IGlJ2UTe4ud4t6my8Xni4QjTu3e61MEvpmOTO2qAQUSar3l7KFZhCn0AkEYPnwXetMcshVpgGH6p mURlZwOvqV264ENfvtaDztASeKk/axMRZ0WMs8c1j7qtpYloMd8oUD5hoE3mCytUc3UXkaMBaSLoF +8s5sxEDSuRu3T1EXh3Z71//cMc6jbo/5vudTQTgGRBzFw0qDebtAescIGQ7Cp9tP0XlP6D7/af8R jwUQaiZA==; Received: from willy by bombadil.infradead.org with local (Exim 4.89 #1 (Red Hat Linux)) id 1esstr-0005LF-UO; Mon, 05 Mar 2018 16:23:43 +0000 Date: Mon, 5 Mar 2018 08:23:43 -0800 From: Matthew Wilcox To: Ilya Smith Cc: Daniel Micay , Kees Cook , Andrew Morton , Dan Williams , Michal Hocko , "Kirill A. Shutemov" , Jan Kara , Jerome Glisse , Hugh Dickins , Helge Deller , Andrea Arcangeli , Oleg Nesterov , Linux-MM , LKML , Kernel Hardening Subject: Re: [RFC PATCH] Randomization of address chosen by mmap. Message-ID: <20180305162343.GA8230@bombadil.infradead.org> References: <20180227131338.3699-1-blackzert@gmail.com> <55C92196-5398-4C19-B7A7-6C122CD78F32@gmail.com> <20180228183349.GA16336@bombadil.infradead.org> <2CF957C6-53F2-4B00-920F-245BEF3CA1F6@gmail.com> <20180304034704.GB20725@bombadil.infradead.org> <20180304205614.GC23816@bombadil.infradead.org> <7FA6631B-951F-42F4-A7BF-8E5BB734D709@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7FA6631B-951F-42F4-A7BF-8E5BB734D709@gmail.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 05, 2018 at 04:09:31PM +0300, Ilya Smith wrote: > > On 4 Mar 2018, at 23:56, Matthew Wilcox wrote: > > Thinking about this more ... > > > > - When you call munmap, if you pass in the same (addr, length) that were > > used for mmap, then it should unmap the guard pages as well (that > > wasn't part of the patch, so it would have to be added) > > - If 'addr' is higher than the mapped address, and length at least > > reaches the end of the mapping, then I would expect the guard pages to > > "move down" and be after the end of the newly-shortened mapping. > > - If 'addr' is higher than the mapped address, and the length doesn't > > reach the end of the old mapping, we split the old mapping into two. > > I would expect the guard pages to apply to both mappings, insofar as > > they'll fit. For an example, suppose we have a five-page mapping with > > two guard pages (MMMMMGG), and then we unmap the fourth page. Now we > > have a three-page mapping with one guard page followed immediately > > by a one-page mapping with two guard pages (MMMGMGG). > > I’m analysing that approach and see much more problems: > - each time you call mmap like this, you still increase count of vmas as my > patch did Umm ... yes, each time you call mmap, you get a VMA. I'm not sure why that's a problem with my patch. I was trying to solve the problem Daniel pointed out, that mapping a guard region after each mmap cost twice as many VMAs, and it solves that problem. > - now feature vma_merge shouldn’t work at all, until MAP_FIXED is set or > PROT_GUARD(0) That's true. > - the entropy you provide is like 16 bit, that is really not so hard to brute It's 16 bits per mapping. I think that'll make enough attacks harder to be worthwhile. > - in your patch you don’t use vm_guard at address searching, I see many roots > of bugs here Don't need to. vm_end includes the guard pages. > - if you unmap/remap one page inside region, field vma_guard will show head > or tail pages for vma, not both; kernel don’t know how to handle it There are no head pages. The guard pages are only placed after the real end. > - user mode now choose entropy with PROT_GUARD macro, where did he gets it? > User mode shouldn’t be responsible for entropy at all I can't agree with that. The user has plenty of opportunities to get randomness; from /dev/random is the easiest, but you could also do timing attacks on your own cachelines, for example.