Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4141888pxb; Tue, 17 Nov 2020 12:24:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwcRHz0U5OzpeuHYcGlTUNoOSk/ZSuiBAeLNvZxMUARUk8U7//32AB7uQ75GSWEEvZx4D9k X-Received: by 2002:aa7:cac2:: with SMTP id l2mr22900523edt.141.1605644673353; Tue, 17 Nov 2020 12:24:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605644673; cv=none; d=google.com; s=arc-20160816; b=bTuVeyKPNWAJzY+44jE2pdLkUNFvaasg+b9lOgxBhcFZRAI3A5HVB9AhjOsIFsvw9n 2Lz+hx+pzSxsVKqHuL7ORgD8WDthDtBlK1TYMv9cCcVBfmsNiMo64t3ZlKpgACbYD87+ qD6n3k0pDA1pnncyQ7LN8hHs92SpKS8WsrqyG1C6e2mQ/fTzUoC7zWY8Zgl6OuU4EZaJ l7snC9m8BIXmzwX5BgNnZv1Tt7q/UDanjFakr0L5prYvKmWP68ePDoMHs/j0pj7YmX3E 1mnsGjK2gel93ErTcCweo2sdZkOm1fprJ7asTKFOHBftgGe31GRdGUt5jY02cY3YpQs0 oXFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=usYoX1OUo+I43l78t6yKp9KT+NTtewGJzWDSoIma1po=; b=Qpbr5GlepVMayAT6cq2GjFoqC3hPqVqoEDhHIWy0IHs4iIWBSdKP/dk9R6GCUeq0C9 55iuF8vwZDqgOEUr5LmjTAxrkNonNG7vC0DME/ebFswifEeTUdaHD4eJGAP4i1gyl0y9 C/brLsdO3EeVQBXt5D9Nxqu6wEY6Aag9H4jAqdrRy0IkuHDFRu4412TeAB1runoVN710 /fIpBsQF5kJ1uAbU+USlL94m2FEYpQO1t9CsktcLoxOpb6fybCG9cmnDANvErQdkjUCW MINiW7sHAxLTycUz6t/dttE98HQS1Yp+CURBOVezZeeQvPEQUjQr8I2nD4oa+1OgddsH qAAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vJ5gRw4O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id v2si19252eda.347.2020.11.17.12.24.10; Tue, 17 Nov 2020 12:24:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vJ5gRw4O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726541AbgKQUVp (ORCPT + 99 others); Tue, 17 Nov 2020 15:21:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725779AbgKQUVp (ORCPT ); Tue, 17 Nov 2020 15:21:45 -0500 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FB31C0613CF; Tue, 17 Nov 2020 12:21:44 -0800 (PST) Received: by mail-lf1-x141.google.com with SMTP id a9so30925762lfh.2; Tue, 17 Nov 2020 12:21:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=usYoX1OUo+I43l78t6yKp9KT+NTtewGJzWDSoIma1po=; b=vJ5gRw4OgRcSRzP93FGLPxWoOQvh4WwrYZTYKtDXw6DTvxGoZtlgswFl33TrAqlOOS BnUzlkx1X6FRwPL6I4TrNcLQRzwHa0JM0loB42eAvhDkMglTsmGFk1aJOzytK/Tgl9le /rS5H1dFDiC7wzWz6favYGUd9en8jNofwuk+Aw++oHFM6QmWLoXdx2MKKe+iTS5guEfF vdu1H2xPW7QLhlmoS0vi0vfF58fSV1aKJcm8vy58wwil2C8XONlPmtfpRlcNdBp6uxyd R6BCk/G/LhUUF3vQYgd/RcsagkvZK9CADRKHeaJGCkftT+obe4Qu9ricwkCW9wcnCxBU JAlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=usYoX1OUo+I43l78t6yKp9KT+NTtewGJzWDSoIma1po=; b=XqO1enaQ9FX1B88QjR7IAe9Wl6Z9aUZNcnivnwK3HMpm5MkBtqlb2oW/4lws8PiyGM +z7DNJ9U2UB/1QBSWj+0gKnpvZNpuhtrh/GnUqiYGTVTbshRe2018POR+SWgvlJryCsk qkr3SzEbzqGEID3F92IuYtgEmgBOdcssi2wy/K8w595LGsCQ2sSKFzmZi6Z4+HJ6FH6o YEWwJoYhyx2PmAHL7FrpG3wwC63Cm0Cq9/vigc01PEjkz0HR9kXAJgeKaXm01rlB8AiK e5uE5j9oBnQAYaIeUeqfFoWLJLqOY/EaeDMGL4655zAX8AWVII+hCGN6LQ1xV4WPlEUx 4ySg== X-Gm-Message-State: AOAM531acSjaYNAqI/WdbX7UPXUIP1lJkLeiScVkjFUCBHFLy7MUBeLa zeSvFk4GRseGTHZNY31lwMA= X-Received: by 2002:a19:8396:: with SMTP id f144mr2226096lfd.444.1605644503034; Tue, 17 Nov 2020 12:21:43 -0800 (PST) Received: from [192.168.1.112] (88-114-211-119.elisa-laajakaista.fi. [88.114.211.119]) by smtp.gmail.com with ESMTPSA id z19sm1287729ljn.15.2020.11.17.12.21.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Nov 2020 12:21:42 -0800 (PST) Subject: Re: [PATCH v4] mm: Optional full ASLR for mmap() and mremap() To: Matthew Wilcox Cc: linux-hardening@vger.kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jann Horn , Kees Cook , Mike Rapoport References: <20201026160518.9212-1-toiwoton@gmail.com> <20201117165455.GN29991@casper.infradead.org> From: Topi Miettinen Message-ID: <19373af5-2272-7615-27a7-6734c584f8bd@gmail.com> Date: Tue, 17 Nov 2020 22:21:30 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <20201117165455.GN29991@casper.infradead.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17.11.2020 18.54, Matthew Wilcox wrote: > On Mon, Oct 26, 2020 at 06:05:18PM +0200, Topi Miettinen wrote: >> Writing a new value of 3 to /proc/sys/kernel/randomize_va_space >> enables full randomization of memory mappings created with mmap(NULL, >> ...). With 2, the base of the VMA used for such mappings is random, >> but the mappings are created in predictable places within the VMA and >> in sequential order. With 3, new VMAs are created to fully randomize >> the mappings. Also mremap(..., MREMAP_MAYMOVE) will move the mappings >> even if not necessary. > > Is this worth it? > > https://www.ndss-symposium.org/ndss2017/ndss-2017-programme/aslrcache-practical-cache-attacks-mmu/ Thanks, very interesting. The paper presents an attack (AnC) which can break ASLR even from JavaScript in browsers. In the process it compares the memory allocators of Firefox and Chrome. Firefox relies on Linux mmap() to randomize the memory location, but Chrome internally chooses the randomized address. The paper doesn't present exact numbers to break ASLR for Chrome case, but it seems to require more effort. Chrome also aggressively randomizes the memory on each allocation, which seems to enable further possibilities for AnC to probe the MMU tables. Disregarding the difference in aggressiveness of memory allocators, I think with sysctl.kernel.randomize_va_space=3, the effort for breaking ASLR with Firefox should be increased closer to Chrome case since mmap() will use the address space more randomly. I have used this setting now for a month without any visible performance issues, so I think the extra bits (for some additional effort to attackers) are definitely worth the low cost. Furthermore, the paper does not describe in detail how the attack would continue after breaking ASLR. Perhaps there are assumptions which are not valid when the different memory areas are no longer sequential. For example, if ASLR is initially broken wrt. the JIT buffer but continuing the attack would require other locations to be determined (like stack, data segment for main exe or libc etc), further efforts may be needed to resolve these locations. With randomize_va_space=2, resolving any address (JIT buffer) can reveal the addresses of many other memory areas but this is not the case with 3. -Topi