Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp85523imm; Thu, 21 Jun 2018 14:24:14 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIQ9SdlE7jX4d5RgaeqRyANcoxt9xvhUfKCjt7g/9H/4iaAEIGqpaJO7f5px2skBHFXuc6l X-Received: by 2002:a17:902:5acd:: with SMTP id g13-v6mr4562387plm.90.1529616254945; Thu, 21 Jun 2018 14:24:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529616254; cv=none; d=google.com; s=arc-20160816; b=AGx0/pWv1Mt6ljLS0sVG20JDsBg+NhXynJrpLzTjG1uSFwPIu1GZ/+0vSfoshLZ/6D rk4N4YNA6iPufIn9OSV6epNFFEgQdiVmgC3L0ITu2KLdOC1bFlZ1hkxZdPjUaaqw4Kqm 8zutDzVoVQH4A3+58lzNTH25GHHBiglBplbYtBcBPIJWIi167JsZz4IAk3xDShCF2mFi zx4xcne96iQxfpsAPNbicF98bBjYPmkOukdH90DDB0E1FB6st3KMpmJFiKLSrt2g1iPa ktwmf179gaEiI9DdzfrtzBDtk1TyuDinT5SK4KPL5G+hiSBGOqhqaEUDcbilfT1NedNP 0g8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=c3pg5EPfVVeJMFWOmTDKH0LeikXzAYkw+vp4L4F6AXE=; b=yVoOzUVX79w6WaXVl1DFiXyz/gDsIo/z/KClbQICp/GMb3+N+AnAN2xCmxY7uQoNmc veM8JM7KgOSOqXm5K5X/BQwV2NsR9iyJJgFfnRpUDRKES4eCamrsF+h8z770E+wzSMbn Bd+2kULaHcuE9avOeuhaqpUbkXVztOAkYfl6xW0x9rfz/wQXPOU3dEjmO8YLIyKB6qpu kKu6ibXyHuzkiQJgP0xTcMFgV7XWqls5sFGi9zkRcuc0Ql95qhWkAMU9HroJjTpvIpAG urp1MSr+Yxf4mEPpI9nXdgz9SkUAnZ0V/OcSW338PqHLdDZbWTAgJuvuTwHBS5KJjHf2 k3fg== ARC-Authentication-Results: i=1; mx.google.com; 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 d88-v6si5712542pfl.297.2018.06.21.14.24.00; Thu, 21 Jun 2018 14:24:14 -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; 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 S933304AbeFUVXV (ORCPT + 99 others); Thu, 21 Jun 2018 17:23:21 -0400 Received: from www62.your-server.de ([213.133.104.62]:36716 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933162AbeFUVXU (ORCPT ); Thu, 21 Jun 2018 17:23:20 -0400 Received: from [109.168.64.67] (helo=localhost.localdomain) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-SHA:256) (Exim 4.85_2) (envelope-from ) id 1fW72x-0003n3-W2; Thu, 21 Jun 2018 23:23:16 +0200 Subject: Re: [PATCH 0/3] KASLR feature to randomize each loadable module To: "Edgecombe, Rick P" , "jannh@google.com" , "keescook@chromium.org" Cc: "linux-kernel@vger.kernel.org" , "Van De Ven, Arjan" , "tglx@linutronix.de" , "linux-mm@kvack.org" , "x86@kernel.org" , "Accardi, Kristen C" , "hpa@zytor.com" , "mingo@redhat.com" , "kernel-hardening@lists.openwall.com" , "Hansen, Dave" References: <1529532570-21765-1-git-send-email-rick.p.edgecombe@intel.com> <1529607615.29548.202.camel@intel.com> From: Daniel Borkmann Message-ID: <4efbcefe-78fb-b7db-affd-ad86f9e9b0ee@iogearbox.net> Date: Thu, 21 Jun 2018 23:23:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1529607615.29548.202.camel@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.99.3/24683/Thu Jun 21 14:43:55 2018) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/21/2018 08:59 PM, Edgecombe, Rick P wrote: > On Thu, 2018-06-21 at 15:37 +0200, Jann Horn wrote: >> On Thu, Jun 21, 2018 at 12:34 AM Kees Cook >> wrote: >>> And most systems have <200 modules, really. I have 113 on a desktop >>> right now, 63 on a server. So this looks like a trivial win. >> But note that the eBPF JIT also uses module_alloc(). Every time a BPF >> program (this includes seccomp filters!) is JIT-compiled by the >> kernel, another module_alloc() allocation is made. For example, on my >> desktop machine, I have a bunch of seccomp-sandboxed processes thanks >> to Chrome. If I enable the net.core.bpf_jit_enable sysctl and open a >> few Chrome tabs, BPF JIT allocations start showing up between >> modules: >> >> # grep -C1 bpf_jit_binary_alloc /proc/vmallocinfo | cut -d' ' -f 2- >>   20480 load_module+0x1326/0x2ab0 pages=4 vmalloc N0=4 >>   12288 bpf_jit_binary_alloc+0x32/0x90 pages=2 vmalloc N0=2 >>   20480 load_module+0x1326/0x2ab0 pages=4 vmalloc N0=4 >> -- >>   20480 load_module+0x1326/0x2ab0 pages=4 vmalloc N0=4 >>   12288 bpf_jit_binary_alloc+0x32/0x90 pages=2 vmalloc N0=2 >>   36864 load_module+0x1326/0x2ab0 pages=8 vmalloc N0=8 >> -- >>   20480 load_module+0x1326/0x2ab0 pages=4 vmalloc N0=4 >>   12288 bpf_jit_binary_alloc+0x32/0x90 pages=2 vmalloc N0=2 >>   40960 load_module+0x1326/0x2ab0 pages=9 vmalloc N0=9 >> -- >>   20480 load_module+0x1326/0x2ab0 pages=4 vmalloc N0=4 >>   12288 bpf_jit_binary_alloc+0x32/0x90 pages=2 vmalloc N0=2 >>  253952 load_module+0x1326/0x2ab0 pages=61 vmalloc N0=61 >> >> If you use Chrome with Site Isolation, you have a few dozen open >> tabs, >> and the BPF JIT is enabled, reaching a few hundred allocations might >> not be that hard. >> >> Also: What's the impact on memory usage? Is this going to increase >> the >> number of pagetables that need to be allocated by the kernel per >> module_alloc() by 4K or 8K or so? > Thanks, it seems it might require some extra memory.  I'll look into it > to find out exactly how much. > > I didn't include eBFP modules in the randomization estimates, but it > looks like they are usually smaller than a page.  So with the slight > leap that the larger normal modules based estimate is the worst case, > you should still get ~800 modules at 18 bits. After that it will start > to go down to 10 bits and so in either case it at least won't regress > the randomness of the existing algorithm. Assume typically complex (real) programs at around 2.5k BPF insns today. In our case it's max a handful per net device, thus approx per netns (veth) which can be few hundreds. Worst case is 4k that BPF allows and then JITs. There's a BPF kselftest suite you could also run to check on worst case upper bounds.