Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2077430imu; Wed, 21 Nov 2018 06:26:14 -0800 (PST) X-Google-Smtp-Source: AFSGD/VsuBDW+LteaClwxOa3jnaJbDy0eS2RzFiR6e7l5f3RaRCzkkE09OoALR2mFaSiG2mP7XLL X-Received: by 2002:a17:902:24d:: with SMTP id 71mr6800222plc.225.1542810373958; Wed, 21 Nov 2018 06:26:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542810373; cv=none; d=google.com; s=arc-20160816; b=p5qcd0fpaQEFriz8pL+dH5QX54BvwjuyRU1pvqJhTe8Yj3m6vb9SXP0dTP3mR+XnQR +PKwhVeCs8+WyO0IMXLhuEroMdm+Ku62AigXwhaOz1DqhRqSa7k//knhr5gPQumSzOu4 qrP51dSlys5zTmFVanuNO5C4BjF+ExPU3uXSzaYBVVzrbZJGqw236nFWd9OHfJSWSrwF yEeOgG8uYBM5q4YRTiQroTfwKDqB8qBlObdUnG1ny4ym1uQBv177WUTLF5Fp4MkJjcdP lb5FrNsJSdUUxCn8MBDrFGJOTgN/A2YqpYJszgm6jCEYgAnae8BQa1rDvLM2cOP0w/nQ m8wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=AeOSRD17eI7lqQdKuzheZHr/lUeJ/wz4KokMFARTc+Y=; b=lhbZaNlREO72mMXf8ORZKYJAmItfePA9xoexnSQc91OPRh8g3fQA7ewPKNCRjgVyWO 7tsC//BGK8Qp7VGE08n8KJdkC0eTdq15cg8mvhkeO23COx7qXGgkxwhlaVT7sZFF+TG9 CNGzx4uJg5S6v82qGI5jp9H5Vgo8U/npGbc/ZvJiQ1uKe/EGzdfmooEP5OKpnsgMMfeQ xT9vVEURmTS3zswIhlOQRXu6oXHstWHqX8pqxYh+EdtW0WBufKOKDQBlpuHWdjU3hirj 3QruQLljY8vSwAv0dUPNfNBjS4mTYiVBnLf154ULhpWES+X6QTZSZDZyMo+8waLXgEyl s5xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ygh+2Lj5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h70si43300640pge.221.2018.11.21.06.25.47; Wed, 21 Nov 2018 06:26:13 -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; dkim=pass header.i=@linaro.org header.s=google header.b=Ygh+2Lj5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730949AbeKUXwH (ORCPT + 99 others); Wed, 21 Nov 2018 18:52:07 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:38512 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729128AbeKUXwF (ORCPT ); Wed, 21 Nov 2018 18:52:05 -0500 Received: by mail-ed1-f66.google.com with SMTP id h50so4855046ede.5 for ; Wed, 21 Nov 2018 05:17:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AeOSRD17eI7lqQdKuzheZHr/lUeJ/wz4KokMFARTc+Y=; b=Ygh+2Lj5cEMg6oVN64CQcyFRQTdy0Md0J7EJggMJPoZO82mhFGh7Ps9P8enMqjisOH RBOrTlLg9N1r6t8KCP4czn0GWxphAenXXmY7T9ObCj5awEAdy7kIpypzhq21TotWc9mp NRCRN8pCMcOTDd0FPPr7ptyG7iFNuY2NX9MZc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AeOSRD17eI7lqQdKuzheZHr/lUeJ/wz4KokMFARTc+Y=; b=iw/1IacLxIPYT0YJWFdsQDBr92VHRzPS/ptah6kowbWJImS9ecm1xGLTGTNFSMraqR ccxl8by/zCMjmgDVDpxpQh7CZPgATW2LkqHcjjn41WRD3vHPxGr+Ma9w4vfKl1rFkg3p Bx9B+0WJOPxr0kbCFpJu4kLB/EclQyKzn5W35sGnvsbdRsy8vJ8EAsBbcVBNKE1t7JnZ rV5nbHLCYD4DrEck+PEYYuVWfW6Pq4HS2Tztm26B+BD6ZBCNf6B3Qi5KyVKXO7/2SSMI EzxpOqjtnLztVNz54YqgtuLEN9DIxTIV0kvvONqUm71MpzMqBs/UWqG7K9q7HRIZFe7o gduw== X-Gm-Message-State: AGRZ1gJmzn2/kHPwEMpcYz0RW6dfxJYFIw/PG4zQ3W0PGw7MJ1Bcnqqi bQJF4F46IX2xFMQ81kS9rg1h8A== X-Received: by 2002:a17:906:4684:: with SMTP id a4-v6mr5210489ejr.24.1542806263663; Wed, 21 Nov 2018 05:17:43 -0800 (PST) Received: from mba13.wifi.ns.nl (dhcp-077-251-017-237.chello.nl. [77.251.17.237]) by smtp.gmail.com with ESMTPSA id f4sm11501597edb.21.2018.11.21.05.17.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Nov 2018 05:17:42 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Daniel Borkmann , Alexei Starovoitov , Rick Edgecombe , Eric Dumazet , Jann Horn , Kees Cook , Jessica Yu , Arnd Bergmann , Catalin Marinas , Will Deacon , Mark Rutland , "David S. Miller" , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 1/2] bpf: add __weak hook for allocating executable memory Date: Wed, 21 Nov 2018 14:17:32 +0100 Message-Id: <20181121131733.14910-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181121131733.14910-1-ard.biesheuvel@linaro.org> References: <20181121131733.14910-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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..f28d8a5eb6b8 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) +{ + return module_memfree(size); +} + 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); } -- 2.17.1