Received: by 10.223.185.116 with SMTP id b49csp2638203wrg; Mon, 5 Mar 2018 06:25:12 -0800 (PST) X-Google-Smtp-Source: AG47ELssw5r0LJVZH1G1P/KdlMS1rbzLW4vtaguowWxROTQfAkAcTtWkmLkE975cJcQ145XoDjnn X-Received: by 10.98.238.2 with SMTP id e2mr15522676pfi.68.1520259912494; Mon, 05 Mar 2018 06:25:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520259912; cv=none; d=google.com; s=arc-20160816; b=tAhBwB65cvXwX3b9ip3LwkouInlHxN0iD2UQNr2yGd/bPY7ADrieRak+ti9iQHSRgV zPcLlC2fWpb01Iz18tG69yB6Wz80RYjq32p+yLgZIem3xPeIm/S8/JzwmrtXq9C8u5n4 Hmd7MRSdlPm/YKdwKLIptvz0VLBH7bSGGsR01jKnKvOuBSg9u3qrAkKMPxSGIzjYycPF ZJrE0/6UoTz7vQ/eU2YPXE9aVlwpvxIZ3GUXZfbkxBpLETc3A2p3zOjC6HevIMBHw6qn bvVNuz0x0uwtHUuJLA7pzVCPWduu2Uw5pMoDRygPGyGNU0TGDGi6n+Zit76u9uKNc6mz BMEg== 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:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=N/RT9fotQ90aaXMRcQhewQOkQJhY4VHOQhlnJbPJP+Q=; b=bn41Reqa9kmulrn3+JHABFUBBPtNkAa4RTI+fvNeAKzc43yvleO/ptaU3riyj1wWxv EeFOXX/moAQj5lDfKrpxdaLfZ0llaPSdW66ou6tKii0E4waHvm3MQbuWbuqUlC77R7oR WiOW0Z8ivagw8e0ZD5cS/mdJhPVQ+DdcN+JISbSQ44bl8F/pythXRHOz0zHgJIGrKRSy fWCObbzsTEkyGkf9/hrOcBM7Mn+50vEqmiyaIBFEQ0h6zRzzq6VPONT/QULZADQH0V2S MH2q5LV5zQL939phR0ocM2wNlSR57E+C/Qe3U5Cgp8eicKG9BshghemU97JZmfirRBjb R+Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MXr9imcX; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z6-v6si2874615pln.732.2018.03.05.06.24.57; Mon, 05 Mar 2018 06:25:12 -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=@gmail.com header.s=20161025 header.b=MXr9imcX; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751906AbeCEOYH (ORCPT + 99 others); Mon, 5 Mar 2018 09:24:07 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:43562 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751776AbeCEOYB (ORCPT ); Mon, 5 Mar 2018 09:24:01 -0500 Received: by mail-qt0-f195.google.com with SMTP id d26so20474159qtk.10 for ; Mon, 05 Mar 2018 06:24:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=N/RT9fotQ90aaXMRcQhewQOkQJhY4VHOQhlnJbPJP+Q=; b=MXr9imcXLtSbdvVDHS3Ix7q1RNyBlHn31qOwvPuhvBV6y89XfuYLmLUrN5hS2HKY64 Oewznz+DJ9fQZ8fr8taj0mccX0SUlrc3XVBz2b70d98Hje0+6wTAFCx2TRu0z4/PDt67 YUOFScVcusuYROVJ9iL5V+L3EQ3stIZaawouVOTYucsXPVoPtb6/TK/XdcbGpA5Ihy2+ vH/etHLKJ63u+I1HWKRrCMfKiYAmp4eqxj75PUTzLGNOrZNG3fIWooTn3EyoAg+qh/ZG JF8J6gdG5S9JoQvyHBq6jSYW3H/XeyP8G2ArL1OPu0hXBFfS2bNOSRiF1RYezugqY/vW to0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=N/RT9fotQ90aaXMRcQhewQOkQJhY4VHOQhlnJbPJP+Q=; b=uW3NCMd52453gkggrVAV9YpYHl5SStFsl+JpcirRB3GSKK3LBcDUduAKUwgl3aUYtY VOy0KsP+Gy8UhgNLa6t4VUHM2SXebK27SgO6IXwHvOCiakgqE5avIBJlNs5KbodxcsK0 fV+/aDEHDs9bYCr5ZJWQlFCS5jrsqqWDrvFFIkWNLyP3VHG0sjj+BZISnLfsKvApcptV +hYAm8lVGkfg6Z1p3pSSkN7w46I4/v76eQ/QgctsJHjlXHH0FpV8USvg5G8N7nWPg/kA uSXDtAbDwkhMZFQd+y/uCUKrkv2jDUpX5w0HRIkj/br9wnlEv6/MdNeHAA2BKCRHECWo bTjQ== X-Gm-Message-State: AElRT7FGBzU6OpDmUuH2UpjqHFV4BjXm9ktuu4LTuFidCHsTbnK7rpkE ETU70JW8ql3X2NELcj9ZEo2CInbQfy9M0lKzA0o= X-Received: by 10.200.36.78 with SMTP id d14mr22168791qtd.329.1520259839927; Mon, 05 Mar 2018 06:23:59 -0800 (PST) MIME-Version: 1.0 Received: by 10.200.33.232 with HTTP; Mon, 5 Mar 2018 06:23:59 -0800 (PST) In-Reply-To: <7FA6631B-951F-42F4-A7BF-8E5BB734D709@gmail.com> 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> From: Daniel Micay Date: Mon, 5 Mar 2018 09:23:59 -0500 Message-ID: Subject: Re: [RFC PATCH] Randomization of address chosen by mmap. To: Ilya Smith Cc: Matthew Wilcox , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5 March 2018 at 08:09, 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=E2=80=99m 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 > - now feature vma_merge shouldn=E2=80=99t work at all, until MAP_FIXED is= set or > PROT_GUARD(0) > - the entropy you provide is like 16 bit, that is really not so hard to b= rute > - in your patch you don=E2=80=99t use vm_guard at address searching, I se= e many roots > of bugs here > - if you unmap/remap one page inside region, field vma_guard will show he= ad > or tail pages for vma, not both; kernel don=E2=80=99t know how to handle = it > - user mode now choose entropy with PROT_GUARD macro, where did he gets i= t? > User mode shouldn=E2=80=99t be responsible for entropy at all I didn't suggest this as the way of implementing fine-grained randomization but rather a small starting point for hardening address space layout further. I don't think it should be tied to a mmap flag but rather something like a personality flag or a global sysctl. It doesn't need to be random at all to be valuable, and it's just a first step. It doesn't mean there can't be switches between random pivots like OpenBSD mmap, etc. I'm not so sure that randomly switching around is going to result in isolating things very well though. The VMA count issue is at least something very predictable with a performance cost only for kernel operations. > I can=E2=80=99t understand what direction this conversation is going to. = I was talking > about weak implementation in Linux kernel but got many comments about ASL= R > should be implemented in user mode what is really weird to me. That's not what I said. I was saying that splitting things into regions based on the type of allocation works really well and allows for high entropy bases, but that the kernel can't really do that right now. It could split up code that starts as PROT_EXEC into a region but that's generally not how libraries are mapped in so it won't know until mprotect which is obviously too late. Unless it had some kind of type key passed from userspace, it can't really do that. > I think it is possible to add GUARD pages into my implementations, but i= nitially > problem was about entropy of address choosing. I would like to resolve it= step by > step. Starting with fairly aggressive fragmentation of the address space is going to be a really hard sell. The costs of a very spread out address space in terms of TLB misses, etc. are unclear. Starting with enforced gaps (1 page) and randomization for those wouldn't rule out having finer-grained randomization, like randomly switching between different regions. This needs to be cheap enough that people want to enable it, and the goals need to be clearly spelled out. The goal needs to be clearer than "more randomization =3D=3D good" and then accepting a high performance cost for that. I'm not dictating how things should be done, I don't have any say about that. I'm just trying to discuss it.