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=-2.0 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,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 D21C5C4361B for ; Thu, 10 Dec 2020 19:58:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5E0DA22571 for ; Thu, 10 Dec 2020 19:58:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E0DA22571 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 8A4946B005D; Thu, 10 Dec 2020 14:58:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F5946B0068; Thu, 10 Dec 2020 14:58:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E4FE6B006C; Thu, 10 Dec 2020 14:58:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 519A96B005D for ; Thu, 10 Dec 2020 14:58:39 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 021FE362D for ; Thu, 10 Dec 2020 19:58:39 +0000 (UTC) X-FDA: 77578435158.27.pear23_230d798273fb Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id CAEFD3D669 for ; Thu, 10 Dec 2020 19:58:38 +0000 (UTC) X-HE-Tag: pear23_230d798273fb X-Filterd-Recvd-Size: 5339 Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Thu, 10 Dec 2020 19:58:38 +0000 (UTC) Received: by mail-lf1-f66.google.com with SMTP id h19so9964282lfc.12 for ; Thu, 10 Dec 2020 11:58:38 -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=GC/XblOlRvC+qjSKhqvPWSHVmyf1S0klyHzoOlN2iQc=; b=B5RF+oI/aEJk5oFliIENmOnUpk914JFiTNv0xNVgQe+zFhST94+JU5cbGP7hvBpD9v grxe8oo1mX5tiYCWySi3nscdMci1ElaO8JweSiONVZk+k+nFZ+Kil9YPERX7lJIBwAp8 iy82acrzkeA+z40q3fstbj9Na9DxCUJBIJO4V8acsMMpNsuHaaCjX/6RpStSTLkStSlp +wdaFCm1yjv/7n6d1uFK+yR9yzHEX3YPRZ3gE15T5vJKAoG0OHqFg4VUTXpMMDBpPYFN litjpTzzUYBMug4zvP+YywyKEC/jnyuvyath1r6HNbRBTF3VG3syPj8iBwdgEZbiHgk+ rlpQ== 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=GC/XblOlRvC+qjSKhqvPWSHVmyf1S0klyHzoOlN2iQc=; b=YIJE4d+h4+8vzFZCTRhh38zZ3oHL+gnygtRw/4kffbI9wKClXE6bq81hWRrcIVD5pQ WUpdfW2EAW+o4bqwAD26qCcyBhQ8f4BBWiYK3/oq6+Ew7pDhPHLmfiAOkroEfasGv75r VUgmZcD3UsvmNyFdcsEiR4T1Ns91mb6CSgQOJ3wB6AycOOiKlU3oBgrysZuWRfcz7bKh IrtqaqPui+ZaAAprmhfuKyjCj6m19vKU4M0BuDTT0QoCHsv93GzfYJiT49Hi3e8lhg8U 77WA7Ut0z98txeN46HFcSsJ4VoHVI1aDtxphkGn9Fp/qgdBPVF+aOfHPDmgsW020ht7H HRjw== X-Gm-Message-State: AOAM531B/SfheW1A/Glv41aZX6YCYWUX2W0yW0aAyHL3FkQ8GpWZ2ytR 6kAkdt2esolp48iqj99cF60= X-Google-Smtp-Source: ABdhPJxhUF+Yv2avD1Pj5n+dOKXAWNePLfrPOFYOF7WHhPIbi9+WEBCX4vmjJXJECzcEC8KHTOt0Jw== X-Received: by 2002:a19:8b55:: with SMTP id n82mr3398587lfd.485.1607630316854; Thu, 10 Dec 2020 11:58:36 -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 r16sm712488ljj.52.2020.12.10.11.58.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Dec 2020 11:58:36 -0800 (PST) Subject: Re: [PATCH] mm/vmalloc: randomize vmalloc() allocations To: Mike Rapoport Cc: linux-hardening@vger.kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andy Lutomirski , Jann Horn , Kees Cook , Linux API , Matthew Wilcox References: <20201201214547.9721-1-toiwoton@gmail.com> <9d34fb0a-7aba-1e84-6426-006ea7c3d9f5@gmail.com> <20201203065801.GH751215@kernel.org> From: Topi Miettinen Message-ID: <37787c16-e188-89ae-a5fb-583fd97e6661@gmail.com> Date: Thu, 10 Dec 2020 21:58:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: <20201203065801.GH751215@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable 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 3.12.2020 8.58, Mike Rapoport wrote: > On Wed, Dec 02, 2020 at 08:49:06PM +0200, Topi Miettinen wrote: >> On 1.12.2020 23.45, Topi Miettinen wrote: >>> Memory mappings inside kernel allocated with vmalloc() are in >>> predictable order and packed tightly toward the low addresses. With >>> new kernel boot parameter 'randomize_vmalloc=3D1', the entire area is >>> used randomly to make the allocations less predictable and harder to >>> guess for attackers. >>> >> >> This also seems to randomize module addresses. I was going to check th= at >> next, so nice surprise! >=20 > Heh, that's because module_alloc() uses vmalloc() in that way or anothe= r :) I got a bit further with really using vmalloc with=20 [VMALLOC_START..VMALLOC_END] for modules, but then inserting a module=20 fails because of the relocations: [ 9.202856] module: overflow in relocation type 11 val ffffe1950e27f08= 0 Type 11 is R_X86_64_32S expecting a 32 bits signed offset, so the loader=20 obviously can't fit the relocation from the highest 2GB to somewhere 32=20 TB lower. The problem seems to be that the modules aren't really built as=20 position-independent shared objects with -fPIE/-fPIC, but instead=20 there's explicit -fno-PIE. I guess the modules also shouldn't use=20 -mcmodel=3Dkernel. Though tweaking the flags shows that some combinations= =20 aren't well supported (like =E2=80=99-mindirect-branch=3Dthunk-extern=E2=80= =99 and=20 =E2=80=98-mcmodel=3Dlarge=E2=80=99 are not compatible) and the handwritte= n assembly code=20 also assumes 32 bit offsets. A different approach could be to make the entire kernel relocatable to=20 lower addresses and then the modules could stay close nearby. I guess=20 the asm files aren't written with position independence in mind either. But it seems that I'm finding and breaking lots of assumptions built in=20 to the system. What's the experts' opinion, is full module/kernel=20 randomization ever going to fly? -Topi