Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3241591imu; Sat, 24 Nov 2018 00:53:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/XMmQ5W7Nz0uDmFasIydJt6NpIE294d63PNx6zi/T2nF2cT3MtOhK6tyuNKt9O+Qe7IYEWB X-Received: by 2002:a63:5407:: with SMTP id i7mr17155372pgb.413.1543049613704; Sat, 24 Nov 2018 00:53:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543049613; cv=none; d=google.com; s=arc-20160816; b=lZP3ZJUSB1o79hUOnEbIsuGzCnKRg8B4eK4YzFx9T2TxcCD6ITUbniamcnjme2kGIU yKChFNKMi5Ilpx9cLDb3zwDa9HnTwDEK1u0oPVBcpKLIKLtyHMtIzc6U1VAhocR55Fwx yapaT7ZIiFanhOQBd3jxJzrkGFMbIggTpjYuSfOUUgLxIMaPwfGaX7FlXnaENyPzcCh/ Y5qPLZ3Xhn7dUs8BMVaDuBFiCb+TYRt/XrPkRxy5KiXK7dbkmCUzslNiouwm81Laheqa zpzH0oq9WlDDa2nDM2JKfjPzj2LWsNDh1i4OzIb2MF3KwlkG/+EJzj5kXrl3/Ed8uAtU bAkQ== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2t2DKZwLo4uiuBiBMlCY8fawnGcKKtVedWhh8SZ5pW8=; b=kEAMFumPSG9EpqLqAci0YuMNKUDY+jPWcQP+vNHBggllaxgWfcivtXXtALo/9Frjdc qPtF/E+ZKEqNr74kjIDmhzZHMlIJPVVPbhZEO58odfDcEuBKQxm144SOcmXASkfzW7kT PYTFeWtCBSpGc+Yo6rsXdwlm4POPvNyo+1W7TY85PRgQnhJwdZFrPz3rVs1kl+fdooIb HsBUBsNWs812/xFZdK1r2ysNxEH7uOELjUOL57DUlf3/95ktdqFD6IB5WdMCTxA7j1Ht Jfkd2eZfdoli4bGNvd2CjHfzMQDnPoJpF7Fc4u7kCRjtZCjKG2PXnwTkVH4xXaIPzS2o aRQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="fEXGYNj/"; 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 h3-v6si56659993pld.424.2018.11.24.00.53.19; Sat, 24 Nov 2018 00:53:33 -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="fEXGYNj/"; 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 S1727384AbeKXJEa (ORCPT + 99 others); Sat, 24 Nov 2018 04:04:30 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:42210 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727302AbeKXJE3 (ORCPT ); Sat, 24 Nov 2018 04:04:29 -0500 Received: by mail-wr1-f66.google.com with SMTP id q18so13558311wrx.9 for ; Fri, 23 Nov 2018 14:18:25 -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 :mime-version:content-transfer-encoding; bh=2t2DKZwLo4uiuBiBMlCY8fawnGcKKtVedWhh8SZ5pW8=; b=fEXGYNj/zjrne2auIEZkw4UbItpB9cnQsXYQXrVwYhXuatn1twG7bEQKehvRb5hzEk 4PhZp3v8/zDBoWML41sVaMoIFQ8v9OJnM91SQ/zPdClh1RwbG4tD5YtqYIFIww1mxqbo ks7GhN+jEpgtuDsOAY/q5P/1DWS5iDHK5ja/Q= 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:mime-version:content-transfer-encoding; bh=2t2DKZwLo4uiuBiBMlCY8fawnGcKKtVedWhh8SZ5pW8=; b=g6jmNSIEkJfviULK4ieBSE7tzjq28hKeYOpv6wZ5bXMRF5CxQNrad/2/2g98Jf8+EG xm7EPtmhyBRdSmfMU16zmdMgTMShHtOhMxreVOHsz0g3zqpi1vqjvBhEk+xKC2SVViop ohhnj1BcgXNozS2CWk/QtQKQfXCyDAHT+xBRx4V9cZO85SpguUQ/lreSSBbriGxzo6sL Gcijbk1/azjHVTHojEcJUpp96f9nAegrBTYePRi+C1h92X6Q6R1STVK+itZwZT8DMojr 1qGS5/fv2Fqsir4Q+Op9mgdNhSf1e6GWIiu2pFFuhQk09TVmhQzuzuUSQypBp73ZLYTx yNBw== X-Gm-Message-State: AA+aEWYkt8XuyJNctcKuY6qFDaiEvYjY7ecovb3XfxCKXaIEW+Iiycoa MoleTDBGThbH8cbu5W5fach5IDNc32w= X-Received: by 2002:adf:a452:: with SMTP id e18mr3846291wra.190.1543011504211; Fri, 23 Nov 2018 14:18:24 -0800 (PST) Received: from harold.home ([2a01:cb1d:112:6f00:6913:f64b:5e59:5ba5]) by smtp.gmail.com with ESMTPSA id y13sm12578267wrw.85.2018.11.23.14.18.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Nov 2018 14:18:23 -0800 (PST) From: Ard Biesheuvel To: linux-kernel@vger.kernel.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-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Subject: [PATCH v4 1/2] bpf: add __weak hook for allocating executable memory Date: Fri, 23 Nov 2018 23:18:03 +0100 Message-Id: <20181123221804.440-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181123221804.440-1-ard.biesheuvel@linaro.org> References: <20181123221804.440-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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..78e9b76201b3 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(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); } -- 2.19.1