From patchwork Sat Nov 17 18:57:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 151414 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp808684ljp; Sat, 17 Nov 2018 10:57:30 -0800 (PST) X-Google-Smtp-Source: AJdET5cqnGL7LCC6/Silc+s2oO96BHUJaZy3cTl9Lg3a/6pQNoyfZKoalVAQsTWN5RC2S+C9QG8c X-Received: by 2002:a17:902:24c:: with SMTP id 70-v6mr15488866plc.120.1542481049957; Sat, 17 Nov 2018 10:57:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542481049; cv=none; d=google.com; s=arc-20160816; b=uEB+FVSjQph5AAUL5C/s7q8DdjXXBgswFgutRGVi5yZ5IBVRUWQb4mJ9OS8Q3ONyRQ yMKENQ3nHvYSY94PZz5PprAyXrqVFPQUXn7RRoQm8QEnu7VVx8VmalwFB5CE60V2InOq ofHwP2FjWz6ZmXJSvASixet/8SZZ94s/Y9CpgYGnIdBggG/OW354e4dT8hyEcU8EGJGi ulpV2rYZjn0nJKHmE5F3cNMGe1v1UjAVZtbvhpMHRaDQnNzdBjW4cssVR+d9Ru8JX948 mFib11LPR06Ak54NY4r97lI++iPkDtbX7QGP/Syxl2GIezwQD0pu04c9HK3DCyLkF0Uc KaoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=KK24Xtf0yZxdzxm9LC+famSI28x00YC11YF96N0BM3E=; b=TlDEgAN5am3itsJHY7+Iikj4ThQDvAMOGaEM2qHai6An9r/G6ZwHYyKSNPR9O+vnPh wjCKFZF65uG/XQrhJd/n1d0NmeQTRDktgtqCsNfOYiQGvd5zpSGdY4YbAx2C0UC3Hxuc NMQp0EBuRXm4esjOdr/A1BwO0+67mw53KGwIxNDd3FTas0Zq7j9YyUn2MRFbtVd2E2DH JwxmPidG7WIfUHPcotXZF/sDi+HZ90eNB6BPU2REevtx1wWV0bFzemLLNpzAeS6XuUwQ FepRC1r5WsLt7y23O+1AFuSZfCVabtGZmvV3b26QHuzJ8odHc3CILLF2HhB3ZOrKS39n ktxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UORXOUKY; 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 o68si346275pfo.140.2018.11.17.10.57.29; Sat, 17 Nov 2018 10:57:29 -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=UORXOUKY; 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 S1726366AbeKRFOz (ORCPT + 32 others); Sun, 18 Nov 2018 00:14:55 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:38696 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725734AbeKRFOz (ORCPT ); Sun, 18 Nov 2018 00:14:55 -0500 Received: by mail-pg1-f195.google.com with SMTP id g189so317567pgc.5 for ; Sat, 17 Nov 2018 10:57:20 -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; bh=KK24Xtf0yZxdzxm9LC+famSI28x00YC11YF96N0BM3E=; b=UORXOUKYewxZBY9q60veahrHkEtPpR9GSai6HV7K7LIRYSUmveL4hgphwWKykjezr5 5aJslRjRd5lwcVzGm/diuVIZt/WHst6O5IT8qVuNmMEHGGC3uCNjKCW4U/6UPunf//Ri Yog90RJJIsfBEnEswOgbukRNoDii/RYXBxk8s= 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; bh=KK24Xtf0yZxdzxm9LC+famSI28x00YC11YF96N0BM3E=; b=A4gBl1fSAuWFJxIvSARauhMYlOKiKCZW5WEPHTYSw+0qA+H4xZo+rCaSjEKTF9vOpl 1r9t8dvJaQod2BR53Ek+hknPKyHM98OEr5ZBN6iAqOu0So7EkDo5kOZOKB6wbLGBukiO lGgv2DFHaqC+27s++j1AdccmZr3p1pLJaO/nPO0x17r1Yth9S0LE+bvKHFBeeqOHkIAu +k1XMcq22NM3sCv6FoC51yKGuWam8AUZaTWhk2YG3Vjq3erA6uQP8KU+eQFrZB2Dxvu3 oQg02zYAZKwipUVYpLJca/CaNFTV89Tce3SnZKHQKFJQcdyFSbOkL5Tu5FLWZ+WqVqrA BdJg== X-Gm-Message-State: AGRZ1gIbz2Q5/nFKpI01Top23IUTZiHTlITUenXj+lv/dJr3ofjJ3Pno i8fB6EJA+PhF6Jvsnd6xka6MLvhgHN9Usg== X-Received: by 2002:a63:3c44:: with SMTP id i4mr14292473pgn.286.1542481039552; Sat, 17 Nov 2018 10:57:19 -0800 (PST) Received: from mba13.psav.com ([64.114.255.114]) by smtp.gmail.com with ESMTPSA id u76-v6sm49550745pfa.176.2018.11.17.10.57.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Nov 2018 10:57:18 -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 , Ralf Baechle , Paul Burton , James Hogan , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "David S. Miller" , linux-arm-kernel@lists.infradead.org, linux-mips@linux-mips.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 0/4] bpf: permit JIT allocations to be served outside the module region Date: Sat, 17 Nov 2018 10:57:11 -0800 Message-Id: <20181117185715.25198-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On arm64, modules are allocated from a 128 MB window which is close to the core kernel, so that relative direct branches are guaranteed to be in range (except in some KASLR configurations). Also, module_alloc() is in charge of allocating KASAN shadow memory when running with KASAN enabled. This means that the way BPF reuses module_alloc()/module_memfree() is undesirable on arm64 (and potentially other architectures as well), and so this series refactors BPF's use of those functions to permit architectures to change this behavior. Patch #1 fixes a bug introduced during the merge window, where the new alloc/free tracking does not account for memory that is freed by some arch code. Patch #2 refactors the freeing path so that architectures can switch to something other than module_memfree(). Patch #3 does the same for module_alloc(). Patch #4 implements the new alloc/free overrides for arm64 Cc: Daniel Borkmann Cc: Alexei Starovoitov Cc: Rick Edgecombe Cc: Eric Dumazet Cc: Jann Horn Cc: Kees Cook Cc: Jessica Yu Cc: Arnd Bergmann Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: Ralf Baechle Cc: Paul Burton Cc: James Hogan Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: "David S. Miller" Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Cc: linux-mips@linux-mips.org Cc: linuxppc-dev@lists.ozlabs.org Cc: sparclinux@vger.kernel.org Cc: netdev@vger.kernel.org Ard Biesheuvel (4): bpf: account for freed JIT allocations in arch code net/bpf: refactor freeing of executable allocations bpf: add __weak hook for allocating executable memory arm64/bpf: don't allocate BPF JIT programs in module memory arch/arm64/net/bpf_jit_comp.c | 11 ++++++++++ arch/mips/net/bpf_jit.c | 7 ++----- arch/powerpc/net/bpf_jit_comp.c | 7 ++----- arch/powerpc/net/bpf_jit_comp64.c | 12 +++-------- arch/sparc/net/bpf_jit_comp_32.c | 7 ++----- kernel/bpf/core.c | 22 ++++++++++---------- 6 files changed, 31 insertions(+), 35 deletions(-) -- 2.17.1 Acked-by: Yonghong Song