From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 447A7C63697 for ; Tue, 17 Nov 2020 20:21:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9ACE4221F1 for ; Tue, 17 Nov 2020 20:21:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vJ5gRw4O" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9ACE4221F1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CAD4C6B0036; Tue, 17 Nov 2020 15:21:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C840E6B005C; Tue, 17 Nov 2020 15:21:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4B8B6B0068; Tue, 17 Nov 2020 15:21:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id 8912A6B0036 for ; Tue, 17 Nov 2020 15:21:45 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 340B2180AD81A for ; Tue, 17 Nov 2020 20:21:45 +0000 (UTC) X-FDA: 77495030970.19.hot23_630166427334 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 0509D1AD1B7 for ; Tue, 17 Nov 2020 20:21:44 +0000 (UTC) X-HE-Tag: hot23_630166427334 X-Filterd-Recvd-Size: 5692 Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Tue, 17 Nov 2020 20:21:44 +0000 (UTC) Received: by mail-lf1-f65.google.com with SMTP id u18so31893485lfd.9 for ; 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=NioDCx1wGcaveD0PDcwIVP3sh8KDFeAny7DRWZa+xuAHWpyZyZW0pQN3hmuk4QHGhk n41LLYsZNDRWWH6Zs9unTv3/uq6r+/iVlJ80o493ge1XS7FQ26ZqsXatEVS/QGNIXmGP y2yvbsihXafqfkqDve0Yl+GOW+ax5+wKbNmYnjmuZh1a9yb5/wqymV7cWC003/pfvMXq Y7x/gqGILW+naXnLOahZFnsEaob13GtqVGBGpVnirQfCYfbz53UXDpJt5IG4Npck6N7H u7Lg3v06SEaGXoeBRV/kzUBeUNi6JuZnC2BC6gWKnLto8P6Q5D6Zj2sBFezyQDJij3lv H/zw== X-Gm-Message-State: AOAM532GLx78PCkVIwwMPo81ccK10RAFeti91jM1wV0p0/kEaQk7bJmP F5eZvLjsGKleh3YXHdOLbAMVSeLIkpganA== X-Google-Smtp-Source: ABdhPJyIcj5fOJ77BPNWh48VfX9Ra3j2O98tJu12S72MAkpa2AM43C37crl33CQj9R7+XQX+xeqSZQ== 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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