Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3242426imu; Sat, 24 Nov 2018 00:54:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/UxUdQpz1eSZCHZFiLFv4EdDYojk5ucXYp8vG6DTdsyqR7tPQ6oneGFKUHEe0BSgkFsWB6M X-Received: by 2002:a63:cd4c:: with SMTP id a12mr17548663pgj.252.1543049680203; Sat, 24 Nov 2018 00:54:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543049680; cv=none; d=google.com; s=arc-20160816; b=jDmKFg2zDLG1AzhI3m14lqierR11UIx6jqU+1fZzAHTL5RYuOAoaH/kmczeznj2wSr l7exgdPSt8OVsOSO/0M5gpf+pj4ZbdiqUIVAQ9dOH5MB0QDlK8+Rs5M0tgvOFz7evLWA E4FdmIH/D/qqytFVuzbBJ8j0Y7XPkfMRzv/hdLqAv6BHfsaRMWa0doP2Mew0nVB75eQu ytu6oznSmvfVf8SiH/+qz/DvvfHKygpBJUHMMypur6Tp9nr6DwzJOv8ufCGjM+6SGvdQ IRe6DKqwJj782NLB9PI46i01Le/vCsNCRxPYwvxf9EcAkF3ihV3wROWxcnjta+MSaxFX L/rw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=fYPVSXXSxRlZtaS4pECe7oPYKLBl6FSIygjQnihZy4Q=; b=Ankn/BCV8Nfwxr6uFmrJRIsetKwjPEgLAWyraYHvUZSHeLU8JamMoaHvNY39Yfvw56 QCN46VCMB4oh9+9ifxDnIyCJDo1rRXJWPqHgpb7sX/uTFl7MG4qxDvPHW7oPnawocdjv SKjOT6VUrLD8aVt1OmzMyVXOxuBaU0TIIwzDTXfo1sGidnA62WgjMDkbbuEOLNzR5CxP CmYwfrgSBrvqtdAi50R9m3n8A4uyu9j+u1/0LfOrXe+NYNnNJUpzd877ExneEz/TKw8b 9Wb/c+PEyesV6UzOiToVi0PdnywyUdu2s9OPPpehEcVSUKvyrLxKIqDQ5obLkT0nqxAA 7x+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bKsKXBXS; 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 t11si28243573plo.293.2018.11.24.00.54.26; Sat, 24 Nov 2018 00:54:40 -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=bKsKXBXS; 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 S1727327AbeKXJE3 (ORCPT + 99 others); Sat, 24 Nov 2018 04:04:29 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55214 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727261AbeKXJE2 (ORCPT ); Sat, 24 Nov 2018 04:04:28 -0500 Received: by mail-wm1-f67.google.com with SMTP id r63-v6so13110328wma.4 for ; Fri, 23 Nov 2018 14:18:23 -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:mime-version :content-transfer-encoding; bh=fYPVSXXSxRlZtaS4pECe7oPYKLBl6FSIygjQnihZy4Q=; b=bKsKXBXSoVcz1eSzGI2lS7TvEUTCxlKboZJ1AbNuvllKsJTTVp6Ezjjjgy8YWAOwvM Zm8xRm7+iNYaq/iwRNeCyf1CNr0M08cbE+rKk4qXrB7XuVuvrMo0Q+tHWsJcVb9YOG6f wVAwcSWW+MmCGyiA/w3DStkFqWPIgcu9IcRHk= 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:mime-version :content-transfer-encoding; bh=fYPVSXXSxRlZtaS4pECe7oPYKLBl6FSIygjQnihZy4Q=; b=bJOp7CWguo4jl6Fv6LiCegZjQMAJjCWfzZr9Gmzkk/8fEE4NcjmkkbcF43TB4MVI/p FbRj1zrvKJqoy9/B2qA12hnjv3cXFwC8CfChXZ82by4JWVlC/oykXERjpkbaeEq8tg6H 0QRWFw1dO+HWPLjT5TPERCmkTZ5Va7K+Uk08u2NIWXTprbG2HOc8rBRSMyJrr5MrrI6a +iRwleJnqTECifEE0EvJ7TR4O5uC9YwGlfbsNPufpsMNZP74UW14twmoiFBaFFIMt3DK Hn2COGKNy5ETXes1dw6KTZZdmic+vSKhVjh4DJZRkABBUMbdLG16QjKkZ4RT1xXBVimY Bp3g== X-Gm-Message-State: AGRZ1gKJxlfiMZBKYiv32my7r4q9H3VpRnXhqVCfaXdjTwYZwlfPRT6I phehFuK1R+deT+cJjdRqGz3cG0NhllE= X-Received: by 2002:a7b:c003:: with SMTP id c3-v6mr14097308wmb.133.1543011502879; Fri, 23 Nov 2018 14:18:22 -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.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Nov 2018 14:18:21 -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 0/2] bpf: permit JIT allocations to be served outside the module region Date: Fri, 23 Nov 2018 23:18:02 +0100 Message-Id: <20181123221804.440-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.1 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 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 breaks out the module_alloc() and module_memfree() calls into __weak functions so they can be overridden. Patch #2 implements the new alloc/free overrides for arm64 Changes since v3: - drop 'const' modifier for free() hook void* argument - move the dedicated BPF region to before the module region, putting it within 4GB of the module and kernel regions on non-KASLR kernels Changes since v2: - properly build time and runtime tested this time (log after the diffstat) - create a dedicated 128 MB region at the top of the vmalloc space for BPF programs, ensuring that the programs will be in branching range of each other (which we currently rely upon) but at an arbitrary distance from the kernel and modules (which we don't care about) Changes since v1: - Drop misguided attempt to 'fix' and refactor the free path. Instead, just add another __weak wrapper for the invocation of module_memfree() 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: "David S. Miller" Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org Ard Biesheuvel (2): bpf: add __weak hook for allocating executable memory arm64/bpf: don't allocate BPF JIT programs in module memory arch/arm64/include/asm/memory.h | 5 ++++- arch/arm64/net/bpf_jit_comp.c | 13 +++++++++++++ kernel/bpf/core.c | 14 ++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) -- 2.19.1