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.3 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 EB411C433DB for ; Wed, 13 Jan 2021 11:24:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 75C5B23382 for ; Wed, 13 Jan 2021 11:24:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 75C5B23382 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 9207E8D004A; Wed, 13 Jan 2021 06:24:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D1378D0049; Wed, 13 Jan 2021 06:24:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BFFC8D004A; Wed, 13 Jan 2021 06:24:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id 640AE8D0049 for ; Wed, 13 Jan 2021 06:24:10 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 29B101EF1 for ; Wed, 13 Jan 2021 11:24:10 +0000 (UTC) X-FDA: 77700517860.13.level82_430af272751d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 0A51018140B60 for ; Wed, 13 Jan 2021 11:24:10 +0000 (UTC) X-HE-Tag: level82_430af272751d X-Filterd-Recvd-Size: 4542 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 11:24:09 +0000 (UTC) Received: by mail-lf1-f53.google.com with SMTP id o13so2231148lfr.3 for ; Wed, 13 Jan 2021 03:24:09 -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=jp7oVCO/s16g25YLCPyXULxbDEtiWxyNjeq/cNPPspM=; b=VDn/be97YAMsrOqxP8NWvn8/sfGec6JYdD3JXTc/FHdeoqVOWjb2U+XynWI/ioyoKo /+BFJ9t1dxplVTpU3kuzQnA5GDEnHDDNnfwiPrI8uRecJs9PQnzmMuEpKRRxgugYwRgp g+Udn9cBXt6m3OfGr5RCpzrq4RKs75KvbVEcqjxeYcvMj6wwhrmCcPL1PGT2npo0HVKy pCFcHosBG95HZYTj1txbrbnpY+aE6+rOOwxppYoUDc0z/Z95qEDjwUN59qbOgwHtipqk jUdAYLO1TLNhAbL+ctts8/oPnJYUWaSyIPli+RXDlETK89YCWM1IP5NcKOEzft5I/EnT MRRA== 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=jp7oVCO/s16g25YLCPyXULxbDEtiWxyNjeq/cNPPspM=; b=Rc2ab4mV4ozbHptM7afEn6+5b+ztM08Y4ztnbZcKRBaxTDoizzYu0TnD/FOKwQsk4O Eg9hrDpIiRKbMSoF/kUnW/BBMba1SECoYDsToJ5/yD7F405G5PtJXQjxGQOaFF4Q8k9t THnDJZI1PB4XMGFsAcK7HaHIMne5qcwHXQ+hPl1+bHDeAkRrW8UBHJ5ioqzA1/sledP8 4p3wTlpMnnNQ/djh6hjUeru1cYzcALNA7VHEcBY69r3LlJlHGvhcmcXrICXC0unE/y0D JdmZgrkx3uvVnmoePxQFK/Ut9BHZ1PVEc5hfcUhMD4DIjLddoOfc1J9D7KMB0aU5meu4 V2iQ== X-Gm-Message-State: AOAM533vvpoBH64PVzN+JTbCrQ4zzUhJbM7PTNmLsEqp7yO64pLf5+iq Z1OHcpNGT9bFTt1DxDHm0yE= X-Google-Smtp-Source: ABdhPJz9z9zAfqVegJwhvFz1yzEBK99SQdYj+K3YwCrQwiLG55NndrE9lWOP4cfZkSkk0DQHrHYyxA== X-Received: by 2002:a19:8983:: with SMTP id l125mr681304lfd.182.1610537047952; Wed, 13 Jan 2021 03:24:07 -0800 (PST) Received: from [192.168.1.33] (88-114-222-21.elisa-laajakaista.fi. [88.114.222.21]) by smtp.gmail.com with ESMTPSA id m7sm180344lfb.146.2021.01.13.03.24.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Jan 2021 03:24:07 -0800 (PST) Subject: Re: [PATCH v9] mm: Optional full ASLR for mmap(), mremap(), vdso, stack and heap To: linux-hardening@vger.kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Jann Horn , Kees Cook , Matthew Wilcox , Mike Rapoport , Linux API References: <20210104155316.16259-1-toiwoton@gmail.com> From: Topi Miettinen Message-ID: Date: Wed, 13 Jan 2021 13:24:04 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210104155316.16259-1-toiwoton@gmail.com> 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 4.1.2021 17.53, Topi Miettinen wrote: > Writing a new value of 3 to /proc/sys/kernel/randomize_va_space > enables full randomization of memory mappings. 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. > > Mappings created with mmap(NULL, ...) are randomized and mremap(..., > MREMAP_MAYMOVE) will move the mappings even if not necessary. The > locations of heap (memory allocated with brk()), stack and vdso are > also randomized. It seems that always moving the mappings in mremap() can expose bugs where the callers don't actually expect the mappings to move, even though MREMAP_MAYMOVE is specified (Debian libapt-pkg6.0): https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=980037 Perhaps this part should be a separate option to avoid tripping such bugs when compatibility is more important than improved ASLR and debugging. The option could be also used without randomize_va_space==3. How about something like sysctl.kernel.mremap_always_move, sysctl.vm.mremap_always_move or CONFIG_MREMAP_ALWAYS_MOVE? -Topi