Received: by 10.223.185.116 with SMTP id b49csp3007934wrg; Mon, 5 Mar 2018 12:21:46 -0800 (PST) X-Google-Smtp-Source: AG47ELusL+NbdkL8l7Hlr6E/mbmi6zGrJI5vi7F8XOsYpICFCPTst9w64q5DktvoAJJIxAqcFNg3 X-Received: by 10.101.90.203 with SMTP id d11mr12970543pgt.366.1520281306809; Mon, 05 Mar 2018 12:21:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520281306; cv=none; d=google.com; s=arc-20160816; b=ISvLWpQJkCEUtN5j0lJxuTRA7l8lSM3KuYigmPaitrZz1cVvp7ql9Vl/kfKYUhR5pz +4mn1x52xhNsDPvKB5EAgE9tk14yZBmJsBGqOFurOaVC1LUXh0P/MhHwsNDwf6ttO160 dhK0Q5ZDKH36zJJQX2XkqDZDeOSyb/WVtLoLP3Bv0en2ZTzM3B/n3VqOck+ntHzB5MVe o1a/VV8sIhhqMGwzrXENUBGD0N434QDIIiqkcIWadOx51bGmXWKpw0qsGdE3PLk4s9dA HE8qxT+z0iCNugKeYu/J8LpJ90jzjmWE6TXSDOYYSxS1IU581KOiHDywi0li4vYk9cgn 7Prg== 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=XA0XSQijkWkLCYpOKsnmfcEcJ2n9AzlDbgcSsM7eN10=; b=rkLLj8xXV/90qYOM1CmcsKMtXkfqyUP6poUNbnUIKBdVfl3s+VO3QAqERfa4kgw9zo z+PjT+GyXHBRF3m2k155v4iRzmLNDvTD2fcqHpO4cqZw3qsxeA5jmyFLpwQFaN2Jy+NF q+gzox7qXl7NNI7spaTjFAhv3kufCBAY0Wh5598/NIiFJgfTfRB/SUgyDtJSeJNQOEHz XMxVTH2wxR3Lg9lnXP+5PYncCZY35+KQfS/3E0PPVw8kZ2dp9cn4JxjWYX2hRQ9Ny3wy lzBSWGytmGeRJe3qHW69QqzpytPCFsdsKjZ5kDKzlEnDpq+hZO7ZabCzgwbpzaiD8olq bitQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qF6cFiQm; 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 j11si10529399pff.406.2018.03.05.12.21.32; Mon, 05 Mar 2018 12:21:46 -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=qF6cFiQm; 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 S1752508AbeCEUUg (ORCPT + 99 others); Mon, 5 Mar 2018 15:20:36 -0500 Received: from mail-lf0-f53.google.com ([209.85.215.53]:32771 "EHLO mail-lf0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751275AbeCEUUf (ORCPT ); Mon, 5 Mar 2018 15:20:35 -0500 Received: by mail-lf0-f53.google.com with SMTP id o145so25066764lff.0 for ; Mon, 05 Mar 2018 12:20:34 -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=XA0XSQijkWkLCYpOKsnmfcEcJ2n9AzlDbgcSsM7eN10=; b=qF6cFiQm1f6drlqzBNzHmApEQ6HKVUOOR+RE6/a/v0Hg97/PUjV6mOwlIntJHaxdVs mJATX7HIVL/ESeEAI040kuwHH26Rgg/C1RFFNKCZUm0108npbLAVsDu+NKE1DiAHLayZ GOwBDlrWJSyUyGlWabpra3lEL7EhxoV8rcX3t76Svm/xGJOYHoEel8ujxYM+fJMRf8d/ 9jHihYGTmBtQcXJYw2iHnGyiJwiStP6k+6uimRd7VMq8ArpoUeJRb7duE3MbLaspGe/G KLYbEp2nXGljjoSxDjXINlV1579CkOzTjeEULi3yZk5751ThPMIO9bsq44SmDg6BKhqk kF9A== 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=XA0XSQijkWkLCYpOKsnmfcEcJ2n9AzlDbgcSsM7eN10=; b=rG71QBLRlYLCvvL6FTGC7Hbv2AqJPSDmETQkUnFjpbN5RrbfHY7jnDZvYXEHH6PbuA xLsitI3GZa/UnWPyCfiNb1qjXSQqO/KjLAWDmLJMHA952RrfC7EXGZYBeB4DaWrwg/Zs tosnthVYEHnRarOgJ146G4GdCV3wMwxPFA1HlVl27VIKLr9y2D9GH/UmrIe7dsJAG7bb oR4Y99XvH3hAQPLd6j/ahHggvU9WvIsmcp0IjDVOVkmsvepIm4r0YzeYfDpsZKQ+t15Y MEKH6ryglO1b9/sqZghCskVj/Gz3Ga6bmp0wbZaqxBl38lJlkp2G7uxCpfC9pNl2AZSD ZMjw== X-Gm-Message-State: AElRT7HmaxsPENrm+Mv6rY5xk5MoR+u+H+STvNQUtKqgyMakxNEDmhhb v2wyhDsWCvAOyn1YOtTyTfs= X-Received: by 10.25.105.18 with SMTP id e18mr10587114lfc.52.1520281233889; Mon, 05 Mar 2018 12:20:33 -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 z21sm2845484ljz.83.2018.03.05.12.20.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Mar 2018 12:20:31 -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: <20180305194728.GB10418@bombadil.infradead.org> Date: Mon, 5 Mar 2018 23:20:31 +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: <4CB48994-60BF-4329-B6CE-0613EE1F7417@gmail.com> References: <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> <20180305194728.GB10418@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 22:47, Matthew Wilcox wrote: >>>> - 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. >>=20 >> Well yes, its ok, sorry. I just would like to have 32 bit entropy = maximum some day :) >=20 > We could put 32 bits of padding into the prot argument on 64-bit = systems > (and obviously you need a 64-bit address space to use that many bits). = The > thing is that you can't then put anything else into those pages = (without > using MAP_FIXED). >=20 This one sounds good to me. In my approach it is possible to map there, = but ok. >>>> - 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? >=20 > I thought I covered that in my earlier email. Using one letter per = page, > and a five-page mapping with two guard pages: MMMMMGG. Now unmap the > fourth page, and the VMA gets split into two. You get: MMMGMGG. >=20 I was just interesting, it=E2=80=99s not the issue to me. Now its clear, = thanks. >>> 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. >>=20 >> 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). >=20 > I think this functionality can just as well live inside libc as in > the kernel. >=20 Good news for them :) >> Well, let me summary: >> My approach chose random gap inside gap range with following strings: >>=20 >> + addr =3D get_random_long() % ((high - low) >> PAGE_SHIFT); >> + addr =3D low + (addr << PAGE_SHIFT); >>=20 >> 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. >>=20 >> 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 > umm ... 64k * 4k is a 256MB gap, not 1GB. And it consumes address = space, > not memory. >=20 hmm, yes=E2=80=A6 I found 8 bits somewhere.. 256MB should be enough for = everyone. >> 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? >=20 > I'm just putting it out there for discussion. If people think this is > the right approach, then I'm happy to finish it off. If the consensus > is that we should randomly pick addresses instead, I'm happy if your > approach gets merged. So now, its time to call for people? Sorry, I=E2=80=99m new here. Thanks, Ilya