Received: by 10.223.185.116 with SMTP id b49csp2958865wrg; Mon, 5 Mar 2018 11:28:44 -0800 (PST) X-Google-Smtp-Source: AG47ELuT3F3FB/mCraSDscLB/fvTGYDacwg+YONkW0pgwAztE+IYCJCj6Vgq6o0tNjZjmpiyvBN2 X-Received: by 10.98.17.86 with SMTP id z83mr16378627pfi.207.1520278124014; Mon, 05 Mar 2018 11:28:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520278123; cv=none; d=google.com; s=arc-20160816; b=T9F4qxAR4WAovTAt95FYc99w5no5+vhLSHZ6J9zRVQw7KqoDjnvpjSD2sC5zbBi8jY gTT3bsoZITM9j4Fvg4hp9PClP2B3Ip168horGJ1Iv9staeqxGeVzlQzdvEK5XPDMvfMk bxESEwAkjTt7jql8mMsU7erFoIKHZkVTwoJMM9GKWH2Lo5nRg7Tl1wXWldgA3j2uaZTs Pgqcd9LsbS09Y+rAQu8YUtK1jMM9wj0tHisU5YyQPqvOG2ce0A2YLSh/KO8R/3xg6pXq 4uLm8T1N1F92qjtVQtb+GYejrjv2M8diaVnFebNnXYt+4muDMFv214inACEXspyWEBjH iAbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature:arc-authentication-results; bh=/Bno5D2DcHGozFh1N4VqTmuIGKLck2seubG3XwPAX+A=; b=pN8jal9iPM+cVpu7ds+iRCvX2Ky0bDtwLlcqDc9H7+RSJMXvyXUZkS3aLUH9d+K4Ou mA0BlYASNWLAv6HLPQ6/L4OTDjc9aH18WaH12zSBkk4o/UEeqO5sf+JH0mXkir1RPV6s 2IL9RV1Ok8fkFzgoCuj1vwVKpMK/g0l9qunGIi+vVOpwwtC6DlMopcaMqgzysMLrTL55 uzhNpBd87qotAujo+rl/fdkO75oljqBZ+V1/Ja0FLfeQAPUkXwVBLfNt7NThWffgqT87 Z0cg8NKTer6EKy0tfDbJuZ6qptE2tRiAyums9eNRW1hRiOlp/LeDWDQBPCBmh2B/ZtFx qvxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ED5Wnkua; 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 w9si3021254pgq.815.2018.03.05.11.28.29; Mon, 05 Mar 2018 11:28:43 -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=ED5Wnkua; 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 S1752722AbeCET1i (ORCPT + 99 others); Mon, 5 Mar 2018 14:27:38 -0500 Received: from mail-lf0-f44.google.com ([209.85.215.44]:34170 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751779AbeCET1g (ORCPT ); Mon, 5 Mar 2018 14:27:36 -0500 Received: by mail-lf0-f44.google.com with SMTP id l191so24821829lfe.1 for ; Mon, 05 Mar 2018 11:27:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=/Bno5D2DcHGozFh1N4VqTmuIGKLck2seubG3XwPAX+A=; b=ED5WnkuaJp9tGiP9Ejow6+qS0vzrqouhZS/QBw3Foc69IVbxeGbtmDJOq2DmQf49QP wcrW/fRO85OWtnbkocAx2ZKHpLqTnHJ7RJRXXTKuuS4eKBAZHk9joilsd72Vof0pTF8B VxALnl+/d1PjLTs3ht6Bg93NLnTKS5wccikzz0wlZO/5rw5NbS6nV0Z/DGZiSl7noEu9 52Po2ctB0+Gwnax48Of/K8apvmttBGyshsUDGEHdU0f4FMh0ocXxq/5toAuM3vo9AbwS og60R4KpOvK3jvz0XTwSV2RLMkBbxPhpcPQ+uIYhc4FYEUR89YmlUYUqWo3RmM/3QmxW o7rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=/Bno5D2DcHGozFh1N4VqTmuIGKLck2seubG3XwPAX+A=; b=It2zSBigkAm9jWvH3Ijijlbx05tsBM6P+/k6i61UR0TDWSc9ExRlwli+AEotjRVEBF pgcdjy5qRVafKt1l8Rk6/kp6LfHUS2eqBCnJOgK2kggoL3PBxkGTlt2bFCt2dGp8m7pZ ECJ3TY/BjlFqyOtmquoCM6oLrK0LhgP9DwhfclUsPhOLDbw4+xnZaC3l3k3Q7jjoUBJl g87OTadDdK9RQ6svXeSNVlZUD7ACY/Mn4O+eBV3jReoTqJm/Molz6HYO6kHvV7bCIIoz s+pWyuuhJR+NO1/YjPPI23ichBLpXDRXis2TYVdU8dprEKAqdO+OiYGxeA1CeBJ0nCGq FETg== X-Gm-Message-State: AElRT7F6HAvGl/kYnyLcp/FkzVcT4NzI28CnzCKj9kg2jTInNGSiMgLf uydD4DG0QfHnxXg+OtmjiJ0= X-Received: by 10.25.35.19 with SMTP id j19mr10877206lfj.21.1520278055353; Mon, 05 Mar 2018 11:27:35 -0800 (PST) Received: from [192.168.1.3] (broadband-188-255-70-164.moscow.rt.ru. [188.255.70.164]) by smtp.gmail.com with ESMTPSA id m1sm2824894lje.66.2018.03.05.11.27.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Mar 2018 11:27:33 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Re: [RFC PATCH] Randomization of address chosen by mmap. From: Ilya Smith In-Reply-To: <20180305162343.GA8230@bombadil.infradead.org> Date: Mon, 5 Mar 2018 22:27:32 +0300 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 Content-Transfer-Encoding: quoted-printable Message-Id: 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> <20180305162343.GA8230@bombadil.infradead.org> To: Matthew Wilcox X-Mailer: Apple Mail (2.3445.5.20) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On 5 Mar 2018, at 19:23, Matthew Wilcox wrote: >=20 > On Mon, Mar 05, 2018 at 04:09:31PM +0300, Ilya Smith wrote: >>=20 >> 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=20 >> patch did >=20 > 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. >=20 The issue was in VMAs count as Daniel mentioned.=20 The more count, the harder walk tree. I think this is fine >> - the entropy you provide is like 16 bit, that is really not so hard = to brute >=20 > It's 16 bits per mapping. I think that'll make enough attacks harder > to be worthwhile. Well yes, its ok, sorry. I just would like to have 32 bit entropy = maximum some day :) >> - in your patch you don=E2=80=99t use vm_guard at address searching, = I see many roots=20 >> of bugs here >=20 > Don't need to. vm_end includes the guard pages. >=20 >> - if you unmap/remap one page inside region, field vma_guard will = show head=20 >> or tail pages for vma, not both; kernel don=E2=80=99t know how to = handle it >=20 > There are no head pages. The guard pages are only placed after the = real end. >=20 Ok, we have MG where G =3D vm_guard, right? so when you do vm_split,=20 you may come to situation - m1g1m2G, how to handle it? I mean when M is=20= split with only one page inside this region. How to handle it? >> - user mode now choose entropy with PROT_GUARD macro, where did he = gets it?=20 >> User mode shouldn=E2=80=99t be responsible for entropy at all >=20 > 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. I think the usual case to use randomization for any mmap or not use it = at all=20 for whole process. So here I think would be nice to have some variable=20= changeable with sysctl (root only) and ioctl (for greedy processes). Well, let me summary: My approach chose random gap inside gap range with following strings: + addr =3D get_random_long() % ((high - low) >> PAGE_SHIFT); + addr =3D low + (addr << PAGE_SHIFT); Could be improved limiting maximum possible entropy in this shift. To prevent situation when attacker may massage allocations and=20 predict chosen address, I randomly choose memory region. I=E2=80=99m = still like my idea, but not going to push it anymore, since you have yours = now. Your idea just provide random non-mappable and non-accessable offset from best-fit region. This consumes memory (1GB gap if random value=20 is 0xffff). But it works and should work faster and should resolve the = issue. =20 My point was that current implementation need to be changed and you have your own approach for that. :) Lets keep mine in the mind till better times (or worse?) ;) Will you finish your approach and upstream it? Best regards, Ilya