Received: by 10.213.65.68 with SMTP id h4csp635406imn; Fri, 23 Mar 2018 12:09:23 -0700 (PDT) X-Google-Smtp-Source: AG47ELtHRV+5fE0uCf5XDVlQN73F01CIKgBYrjFzz573AKCrxWkdLnOz69fo96UAysjRa5yw2+a1 X-Received: by 2002:a17:902:5957:: with SMTP id e23-v6mr29945716plj.323.1521832163829; Fri, 23 Mar 2018 12:09:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521832163; cv=none; d=google.com; s=arc-20160816; b=xhIWwHq6K1sP3npefSqtJXe4abGZZtikWCg16jU1/890+wtmQOFLtz72Ul+Kl3KOVW lC/bBgPzyHEg9fynf2DkPJ8DveI0TapgtZFFy/Ql+XC//lroVHXny1Sf4nh6QxV+D9gi tcx2cEnzOna9/l91TNOrTXYxzmMXiY7GXUPIoQVWffmI55rVB6gm7Cgw+z9LH5VXcmQD C1cUfnsZhcV92kA6eloBSjJGgo6N0pZKFcbyWRf1P21PH13IC0oOPGSlRwOMEjtQ/uJe IR4W4OCB0EkGXlSjcDsu8CKfuVD8AsVfHrRdOM+jIAXrE/DqpYeTn896kf4cORdaSc4x lY0w== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=AFxcHieAc63yNfeQtW686kN7BToGXJsCLV/8x6Z1168=; b=QbhlFkOgP+D3hORedP4pQQFw2glTuFWQ8huaflk8H8etgChMwQu599nHw+pJ2jHbKH 8PEClHQ1UhxDY5ktGqooN8jzl3xwpcRAmPQXgZ3Mm/O7R4OHyA6dT6njN2puycVVfAKT K3oUTLn8nzpSVuWE4/yMHkuMtQiOry+S3fWJ/j1mNm181acoKNiy7bzqPFy9ZSQVD1dF 3AzCulpZqCx6OWVqJPsTC/SfzyQofH4knC21TAls8n3pB43K6iL7xlde2BKr9rLwIUyN LhjFk60KtAuXH0e1MTbwQRVAuRJOovlSqUXGFE1vBmPj1JxB7lT/u98XqIAa7lkcGsRr +CFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=RhzzrjMI; 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 e74si7193716pfd.97.2018.03.23.12.08.58; Fri, 23 Mar 2018 12:09:23 -0700 (PDT) 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=RhzzrjMI; 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 S1752131AbeCWTHe (ORCPT + 99 others); Fri, 23 Mar 2018 15:07:34 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:51790 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751595AbeCWTHb (ORCPT ); Fri, 23 Mar 2018 15:07:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding: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=AFxcHieAc63yNfeQtW686kN7BToGXJsCLV/8x6Z1168=; b=RhzzrjMIjZqJjapYC5y62lfX+ kSMZVeG0wGcptMTL82smxMmkhJMH/FDeckgOFL1tSXiB/1LQIlxP8o2EFQ2Osy5Y5U7rlg3uo45Md DLhc1QFE4+GMid8DeMHErgFHWqCYdvOq3CEvPbC0dGCxQpBNZZuiue7cNNiK4B/l11lkfV6G/EjhB UZvf5QZ2ZmbXMd4FLFG8p+mYawep254u0dSDO5EInBzy/lLSwwyPtTdh5Rz++B5Wovs6POgKXagM2 +ctVAfob4MI3bfOBkqsHw2oZqr/mKjnU5ksje0SGXQBcjiItmjzkajU2wfxiavzAIL1qVEXbY2Rd6 Fm4v3BZew==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1ezS14-0006Kg-Rr; Fri, 23 Mar 2018 19:06:18 +0000 Date: Fri, 23 Mar 2018 12:06:18 -0700 From: Matthew Wilcox To: Rich Felker Cc: Ilya Smith , rth@twiddle.net, ink@jurassic.park.msu.ru, mattst88@gmail.com, vgupta@synopsys.com, linux@armlinux.org.uk, tony.luck@intel.com, fenghua.yu@intel.com, jhogan@kernel.org, ralf@linux-mips.org, jejb@parisc-linux.org, deller@gmx.de, benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, ysato@users.sourceforge.jp, davem@davemloft.net, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, nyc@holomorphy.com, viro@zeniv.linux.org.uk, arnd@arndb.de, gregkh@linuxfoundation.org, deepa.kernel@gmail.com, mhocko@suse.com, hughd@google.com, kstewart@linuxfoundation.org, pombredanne@nexb.com, akpm@linux-foundation.org, steve.capper@arm.com, punit.agrawal@arm.com, paul.burton@mips.com, aneesh.kumar@linux.vnet.ibm.com, npiggin@gmail.com, keescook@chromium.org, bhsharma@redhat.com, riel@redhat.com, nitin.m.gupta@oracle.com, kirill.shutemov@linux.intel.com, dan.j.williams@intel.com, jack@suse.cz, ross.zwisler@linux.intel.com, jglisse@redhat.com, aarcange@redhat.com, oleg@redhat.com, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-metag@vger.kernel.org, linux-mips@linux-mips.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org Subject: Re: [RFC PATCH v2 0/2] Randomization of address chosen by mmap. Message-ID: <20180323190618.GA23763@bombadil.infradead.org> References: <1521736598-12812-1-git-send-email-blackzert@gmail.com> <20180323124806.GA5624@bombadil.infradead.org> <20180323180024.GB1436@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180323180024.GB1436@brightrain.aerifal.cx> 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 Fri, Mar 23, 2018 at 02:00:24PM -0400, Rich Felker wrote: > On Fri, Mar 23, 2018 at 05:48:06AM -0700, Matthew Wilcox wrote: > > On Thu, Mar 22, 2018 at 07:36:36PM +0300, Ilya Smith wrote: > > > Current implementation doesn't randomize address returned by mmap. > > > All the entropy ends with choosing mmap_base_addr at the process > > > creation. After that mmap build very predictable layout of address > > > space. It allows to bypass ASLR in many cases. This patch make > > > randomization of address on any mmap call. > > > > Why should this be done in the kernel rather than libc? libc is perfectly > > capable of specifying random numbers in the first argument of mmap. > > Generally libc does not have a view of the current vm maps, and thus > in passing "random numbers", they would have to be uniform across the > whole vm space and thus non-uniform once the kernel rounds up to avoid > existing mappings. I'm aware that you're the musl author, but glibc somehow manages to provide etext, edata and end, demonstrating that it does know where at least some of the memory map lies. Virtually everything after that is brought into the address space via mmap, which at least glibc intercepts, so it's entirely possible for a security-conscious libc to know where other things are in the memory map. Not to mention that what we're primarily talking about here are libraries which are dynamically linked and are loaded by ld.so before calling main(); not dlopen() or even regular user mmaps. > Also this would impose requirements that libc be > aware of the kernel's use of the virtual address space and what's > available to userspace -- for example, on 32-bit archs whether 2GB, > 3GB, or full 4GB (for 32-bit-user-on-64-bit-kernel) is available, and > on 64-bit archs where fewer than the full 64 bits are actually valid > in addresses, what the actual usable pointer size is. There is > currently no clean way of conveying this information to userspace. Huh, I thought libc was aware of this. Also, I'd expect a libc-based implementation to restrict itself to, eg, only loading libraries in the bottom 1GB to avoid applications who want to map huge things from running out of unfragmented address space.