Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3241576imu; Sat, 24 Nov 2018 00:53:32 -0800 (PST) X-Google-Smtp-Source: AFSGD/U522qd7es9scgjYe18YDOb5YRVHDBxxfZADwuJ++DD2TNjgwAlMvAYrFUVdUKBDB1PB7iQ X-Received: by 2002:a63:5765:: with SMTP id h37mr17259263pgm.423.1543049612552; Sat, 24 Nov 2018 00:53:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543049612; cv=none; d=google.com; s=arc-20160816; b=stmQjcrxYtizI8JIpYrIfmY8lfSY2x1Cvx0PWpRcO4ZQjTcAz4YoWlqht9p7zRYyqf CbPLyJ7Zk6xKuVsSFq9Mqj/qv/Py2Lw/PJB//Znu92mKckSfWAUaySr0OowMh06o+beV n0pwBd0EvxE3kaR2P4bc91Ehk/uQXZzX8mNUkpVG1QejcGj5+8fcJYr7bR63Hb3wBftj Qhjo9Q8e3etyVsvAqwCUvhtntVPepjHwZnKJYn6GkAdHvoCv9Rjb031q4Df3FIh/iANU vVX+uWxzEQbtqt4GzlIRzTO3xDoNpy358MPeGVngjgCiuJZ/22IkaKFRgvL8n9rQ/lHa XivQ== 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; bh=rh2XEhZp3OlSf80E3kYiM4wB0uV4CSuX3Z0CSj9+gLA=; b=ZhXQQXZfpzvIgNp3XUFFamZw7vILJrx2IRBnTdMym6Ikx5fLY1BEADtcY6vqFYqegf u7IOlZN+HWMrQwKaocF2/II5DCwRbdatuq+YcIHFHRSp4ILkxpmf6cAqGyf83jpehfLh vR5QkbjLAmHMMqD/AkSNGmahZEyChpxS0JSGg8rPrqH03uz0LS6WPhHW9y6gfTRfk/bV xfedC9WieaCOmcBZrMS/aBe3HgfsQxgPJ9rPh61gQL4sHLlebvB07ZjJhPhZfKrl8pso 82hAdNcAxxwzv1yL7XRjBhnSCSwzLYKzt9fSthdmufmhT0lEa8eUrfMPFeDVtScZVAr2 uxwg== 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 a1si56442282pgk.495.2018.11.24.00.53.18; Sat, 24 Nov 2018 00:53:32 -0800 (PST) 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 S1726614AbeKXHxK (ORCPT + 99 others); Sat, 24 Nov 2018 02:53:10 -0500 Received: from www62.your-server.de ([213.133.104.62]:35094 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726467AbeKXHxK (ORCPT ); Sat, 24 Nov 2018 02:53:10 -0500 Received: from [88.198.220.132] (helo=sslproxy03.your-server.de) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1gQIfR-0002Lt-12; Fri, 23 Nov 2018 22:07:13 +0100 Received: from [178.197.248.22] (helo=linux.home) by sslproxy03.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1gQIfQ-0003QC-NP; Fri, 23 Nov 2018 22:07:12 +0100 Subject: Re: [PATCH v3 1/2] bpf: add __weak hook for allocating executable memory To: Ard Biesheuvel , linux-kernel@vger.kernel.org Cc: Alexei Starovoitov , Rick Edgecombe , Eric Dumazet , Jann Horn , Kees Cook , Jessica Yu , Arnd Bergmann , Catalin Marinas , Will Deacon , Mark Rutland , "David S. Miller" , linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org References: <20181123094152.21368-1-ard.biesheuvel@linaro.org> <20181123094152.21368-2-ard.biesheuvel@linaro.org> From: Daniel Borkmann Message-ID: Date: Fri, 23 Nov 2018 22:07:11 +0100 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: <20181123094152.21368-2-ard.biesheuvel@linaro.org> 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.100.2/25146/Fri Nov 23 15:18:52 2018) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/23/2018 10:41 AM, Ard Biesheuvel wrote: > By default, BPF uses module_alloc() to allocate executable memory, > but this is not necessary on all arches and potentially undesirable > on some of them. > > So break out the module_alloc() and module_memfree() calls into __weak > functions to allow them to be overridden in arch code. > > Signed-off-by: Ard Biesheuvel > --- > kernel/bpf/core.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c > index 1a796e0799ec..572dd74c26e3 100644 > --- a/kernel/bpf/core.c > +++ b/kernel/bpf/core.c > @@ -609,6 +609,16 @@ static void bpf_jit_uncharge_modmem(u32 pages) > atomic_long_sub(pages, &bpf_jit_current); > } > > +void *__weak bpf_jit_alloc_exec(unsigned long size) > +{ > + return module_alloc(size); > +} > + > +void __weak bpf_jit_free_exec(const void *addr) > +{ > + module_memfree(addr); > +} > + > struct bpf_binary_header * > bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr, > unsigned int alignment, > @@ -626,7 +636,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr, > > if (bpf_jit_charge_modmem(pages)) > return NULL; > - hdr = module_alloc(size); > + hdr = bpf_jit_alloc_exec(size); > if (!hdr) { > bpf_jit_uncharge_modmem(pages); > return NULL; > @@ -650,7 +660,7 @@ void bpf_jit_binary_free(struct bpf_binary_header *hdr) > { > u32 pages = hdr->pages; > > - module_memfree(hdr); > + bpf_jit_free_exec(hdr); > bpf_jit_uncharge_modmem(pages); The const needs to be removed, this generates the following warning: # make -j8 kernel/bpf/ DESCEND objtool CALL scripts/checksyscalls.sh CC kernel/bpf/core.o CC kernel/bpf/syscall.o CC kernel/bpf/verifier.o CC kernel/bpf/hashtab.o CC kernel/bpf/helpers.o CC kernel/bpf/inode.o CC kernel/bpf/arraymap.o CC kernel/bpf/lpm_trie.o kernel/bpf/core.c: In function ‘bpf_jit_free_exec’: kernel/bpf/core.c:619:17: warning: passing argument 1 of ‘module_memfree’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] module_memfree(addr); ^~~~ In file included from kernel/bpf/core.c:28:0: ./include/linux/moduleloader.h:30:6: note: expected ‘void *’ but argument is of type ‘const void *’ void module_memfree(void *module_region); ^~~~~~~~~~~~~~ CC kernel/bpf/local_storage.o [...] Please respin with that fixed. Thanks, Daniel