Received: by 10.223.185.116 with SMTP id b49csp2749540wrg; Mon, 5 Mar 2018 08:07:45 -0800 (PST) X-Google-Smtp-Source: AG47ELtlKWriiW2q/I+AiueylmV9KS5iAe7XnlzGYbwDVSqyGzPYLSmMrvCb68AbF+jF6b42rxXc X-Received: by 2002:a17:902:ac1:: with SMTP id 59-v6mr13557851plp.228.1520266065109; Mon, 05 Mar 2018 08:07:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520266065; cv=none; d=google.com; s=arc-20160816; b=LJDdTJEGWGDt62e0Xewv5J4sWmIU6vHIBYQl1mvqPjVsmhm/neME1eC5xY6El+PXkH nJ+9kUDOfOA5Y97a00kcv7yp6ToWeLJBPRktATV681vNbP3Tybce8gftx06/WOH7DohR mqHr2lJQC8FbQpnv7hNToE0WgryI8LdXRrzLrxMSLxHIkRVmK3+HtvmB7o3hfNQX6s7G 1hgOF4bNuFL1M4qTeMxNb2kY+QWqW5CValoZQT+a1Czgi1mRkWXWddzAFxGTdwgYj+l6 D/34nib7VJmXdq9VCL0CEQhVGLv6XBev+D7yE88Efr/66eeUh2HJrGnaYQqKwl72ebJN WZQA== 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=Brhb63k5tXeR3zAWkCQfG+j0SRWIESRW7IQtgqH9sfw=; b=BUBCuXwpeMZ6tIBDQc0BCOl0um6yfqgHtTI4FErgQ9ZNzho5uFFfvX1fxltNwXcmYJ 9/Skl1CzqHh7oIuRShDSQvysu7WNVwELpjpv5YVKgNLvf/LSioqjBV6MBNL5Erh2X/ti tqxthLJhfSHuL+lkMaqkI5qy2CGC3wI5qVD7bEKBdQNe1pSULFne6udMJchhVQUBKlLZ kfH77td3CKhfnS28BwEliDeCEKb/izZUghPO97DavCY7eyQ/90JM2rqQNGg4GyEBLfDh ifIrPH1gDGEHMd75jI4xbQ96VtnKA52Fk4ofavD3VW6fYP5mOyIn88zJhVdRgeGhiQs2 SYLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WWGGJkOb; 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 e10si151014pgu.428.2018.03.05.08.07.29; Mon, 05 Mar 2018 08:07:45 -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=WWGGJkOb; 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 S1751932AbeCEQFO (ORCPT + 99 others); Mon, 5 Mar 2018 11:05:14 -0500 Received: from mail-lf0-f53.google.com ([209.85.215.53]:43936 "EHLO mail-lf0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751311AbeCEQFM (ORCPT ); Mon, 5 Mar 2018 11:05:12 -0500 Received: by mail-lf0-f53.google.com with SMTP id q69so23867284lfi.10 for ; Mon, 05 Mar 2018 08:05:12 -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=Brhb63k5tXeR3zAWkCQfG+j0SRWIESRW7IQtgqH9sfw=; b=WWGGJkOb/6ARtQ8tipgGzAvv7mRNuuswvJ5WjHVVrPNci/mE7BHpibkJcawtB1hKoI Y2u1pVuFIAmoV4BiKkq2fWxRGWTZNCiKGf5YNPwFwc+uZRRvfU1+lUrdsR2LJwsiKbsF ehvGH8/OQ8kBb7gmq8eKqpo4lUVmN8+BcIQLv0+BlucT9inDOefIxhmLYryHvfZReXs8 MsX3fkU5mUciJPbf6JAi4cHIffY3fxRKexGogrpCUPEwdawItME/XJZL7nUwyzpsXb9k A+EbPVcMLFkK3gKL26lNot8WB1WASmMvoJVi4/nblwdoK2eMzVICIafvMREkFE02g0bF 2t0Q== 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=Brhb63k5tXeR3zAWkCQfG+j0SRWIESRW7IQtgqH9sfw=; b=dZm7Zd5S1k8tIGFwtPiyctRr9hVmWwNgajYn8qSH05veLFvVJfdsVto6z+AYlxzls2 GiA4h3p/jedbGnD1Kw0mfy3JE7OXIs8PoGLLxhKKRksvCvc4HV6HvWFB199IjjAAuNx5 H4BR2N2JHeL8kMNVC/FeR7iofaorzCeItYjtWvr1H0OCgW5zlskMwuMvXCpFA5R8dy+4 Xsbzu+2w05rKMXZWxmjre19CwAhNz/DhNJTBulqG1MgTsenTE6l5IGBmQo1yMD682Kw6 s24KXqeMWQ7j1HeJV/jbEi6GlHs5r0DDQ0xpiHMr/lz0gbiwPuHNfbl22SMasuyRWDSc LSTA== X-Gm-Message-State: AElRT7HLJuoym1yqBm3X+/405pyjFd1LMSK93H0u5SdAp7IcYjP9j9fM mYp9uVQhds1jbBfqaNAkVtE= X-Received: by 10.25.145.72 with SMTP id y8mr9482261lfj.1.1520265911165; Mon, 05 Mar 2018 08:05:11 -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 a129sm287293lfa.13.2018.03.05.08.05.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Mar 2018 08:05:09 -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: Date: Mon, 5 Mar 2018 19:05:08 +0300 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-Transfer-Encoding: quoted-printable Message-Id: <896E6047-A49F-4E2E-A831-34CC2AD48550@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> To: Daniel Micay 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 17:23, Daniel Micay wrote: > 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. >=20 Here I like the idea of Kees Cook: > I think this will need a larger knob -- doing this by default is > likely to break stuff, I'd imagine? Bikeshedding: I'm not sure if this > should be setting "3" for /proc/sys/kernel/randomize_va_space, or a > separate one like /proc/sys/mm/randomize_mmap_allocation. I mean it should be a way to turn randomization off since some = applications are=20 really need huge memory. If you have suggestion here, would be really helpful to discuss. I think one switch might be done globally for system administrate like=20= /proc/sys/mm/randomize_mmap_allocation and another one would be good to = have=20 some ioctl to switch it of in case if application knows what to do. I would like to implement it in v2 of the patch. >> 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 = ASLR >> should be implemented in user mode what is really weird to me. >=20 > 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. Yes, thats really true. I wrote about earlier. This is the issue - = kernel can=E2=80=99t=20 provide such interface thats why I try to get maximum from current mmap = design.=20 May be later we could split mmap on different actions by different types = of=20 memory it handles. But it will be a very long road I think.=20 >> I think it is possible to add GUARD pages into my implementations, = but initially >> problem was about entropy of address choosing. I would like to = resolve it step by >> step. >=20 > 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. >=20 I want to clarify. As I know TLB caches doesn=E2=80=99t care about = distance between=20 pages, since it works with pages. So in theory TLB miss is not an issue = here. I=20 agree, I need to show the performance costs here. I will. Just give some = time=20 please. The enforced gaps, in my case: + addr =3D get_random_long() % ((high - low) >> PAGE_SHIFT); + addr =3D low + (addr << PAGE_SHIFT); but what you saying, entropy here should be decreased. How about something like this: + addr =3D get_random_long() % min(((high - low) >> PAGE_SHIFT),=20= MAX_SECURE_GAP ); + addr =3D high - (addr << PAGE_SHIFT); where MAX_SECURE_GAP is configurable. Probably with sysctl. How do you like it? > I'm not dictating how things should be done, I don't have any say > about that. I'm just trying to discuss it. Sorry, thanks for your involvement. I=E2=80=99m really appreciate it.=20 Thanks, Ilya