Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3217302imu; Sat, 24 Nov 2018 00:20:16 -0800 (PST) X-Google-Smtp-Source: AJdET5e6WpFHHB/9z3+PBBNKzD3w4kJ2tw6S8wjop92Tpyqf4Ha1RKbGfcuv4LIJQP99BJY7n+KU X-Received: by 2002:aa7:87ce:: with SMTP id i14mr19214878pfo.20.1543047616596; Sat, 24 Nov 2018 00:20:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543047616; cv=none; d=google.com; s=arc-20160816; b=h3nSAK01+x9lnT9xUgFPJT2i4IgiQO0cPeSp/J6B6OISjKZxxrOfOm1rP0/7f7LUIp XJQ+xwVEnSD1WfmZdQZsHvyGtADEBCd5TbnVgH4H+NXCEUBwaq9lXlaTV5fC9dp8QlG0 nF//sr9eX9rO3xmQ9kA5ETGZLJBCHLXAl3GV0KinOHrFUvs6qpm87tZsQYZKBEQ0cjII mOG9Apxe2Y5aXNDwguHB7Sx9GfuvHLQRSFCANEqz3EifqK50EkMglhI1TbiWnPygWjUk ofQt5FmtBYY0BaDsP/2ccmByiTdg71RjLYrq/5s9T8kPrtKj820zQPpYgSnYexkiQpXe U66w== 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=v8u1be1RwPj+OIivYZiNyoEvuwKWhLSeAuAn+o4TaVM=; b=dLG1mNxchU6Bj4abhv+/AV4+HeTid+CZ64BFasWfm9+7kp/AeUgoCRPEvAFQQJU9Ap ikpSpQ0qQh15g28hnbTga/oDiuE6oca1SlifJJz8I/O39u53Rf3E4g73GXzP+Nb+nCEY /0TdiYsD/miBkLf8po7daVGJ7I1k/WBW4xBs09YZ8qZJG1QT+No9o4IGNa8rfbZuPz/G Idbk7zvV5NsnUMrmJq0DThozLDi7md3qY5ThXRiAQNzGdZBK+w4h1v1ABvgAAx05cich 0uPDDdNq0vkAktSBlYREM+oqk6aqi///UrqOXRuNdADsa8QmJv526RO6TCGhF54pIsI1 EvuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Thb6DIKW; 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 c136si14212701pfc.141.2018.11.24.00.20.02; Sat, 24 Nov 2018 00:20:16 -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=Thb6DIKW; 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 S2502929AbeKWUZm (ORCPT + 99 others); Fri, 23 Nov 2018 15:25:42 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55913 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405436AbeKWUZl (ORCPT ); Fri, 23 Nov 2018 15:25:41 -0500 Received: by mail-wm1-f67.google.com with SMTP id y139so11207558wmc.5 for ; Fri, 23 Nov 2018 01:42:10 -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=v8u1be1RwPj+OIivYZiNyoEvuwKWhLSeAuAn+o4TaVM=; b=Thb6DIKWloK3VAeOMhRGVz7JUMNthBIe3jpvdlMgfpDF2WM7Yv2reFjk5VNxYFDevF NRAouSWeMHTKNfl8RW9mdnY2lDYEC64JhMi24oVca5KQTsrDG0pS82iG2Py6+5QvTSrh l8iLl3PyXCClu0kqpLSRn2/DU+KBkPmqZEpaQ= 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=v8u1be1RwPj+OIivYZiNyoEvuwKWhLSeAuAn+o4TaVM=; b=O2pdhojtcXZZm4Wik2G61dvusepyTkrQE/ISuopwz/q8cXpOs8Oy8GlzxmTHmv/vim nLWd3uqq6TynzuJ1RahjBtdJ+jsp+vWySf1nNjQkTYyctY8VntXkF6d0iqkHl2Mh1pxs mDcDR5pR8DOjCigzTXl7Z/O5Q8ksSQja08KDDmZnxjgs14I/DenEPGHgNfuwQuCjsr4d yPQ8XFuMneVNkOZ80MF2meN6o9PRBe6Bnw//Xf5pGDknYDFsreVNypNS7UP/TgmXFWFb kWPy3L/0GyYsXJNNrNOgdlQ/m6Ng1Fqi3fToabO7latyhM5/3voVGu59L4q1afjfeXZL A4nA== X-Gm-Message-State: AGRZ1gIvSegRh7mwxlZkmIWnbsK7JETDR/aHK96fUzPeTGbV8FFK1yCH G/IaujlnXcqkpPEAb8TYn3p4xWs9bZESUw== X-Received: by 2002:a1c:5f83:: with SMTP id t125-v6mr13176800wmb.53.1542966129100; Fri, 23 Nov 2018 01:42:09 -0800 (PST) Received: from mba13.wifi.ns.nl (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id k7sm35489897wrl.51.2018.11.23.01.42.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Nov 2018 01:42:08 -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 v3 1/2] bpf: add __weak hook for allocating executable memory Date: Fri, 23 Nov 2018 10:41:51 +0100 Message-Id: <20181123094152.21368-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181123094152.21368-1-ard.biesheuvel@linaro.org> References: <20181123094152.21368-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..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); } -- 2.17.1