Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2890173imu; Mon, 19 Nov 2018 07:38:46 -0800 (PST) X-Google-Smtp-Source: AJdET5dhBxcS0Ohmh8z4UGYL4aeYoafWSJcAnb+NwUtKDJyOX+M6odUxhyh0x2VRljp5WvUMXnJ/ X-Received: by 2002:a62:9fcc:: with SMTP id v73-v6mr5047951pfk.191.1542641926024; Mon, 19 Nov 2018 07:38:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542641925; cv=none; d=google.com; s=arc-20160816; b=zheFi3CKzNo4HDDM7tZxH2N9zTXEweODT1kK9CIKDPn01EUiSpSyMo9MnmljwLrHBT zY8S0TKIlUJMROv6xtsZIGMoA1YCYuKBs8bD4M+AGz0+3CZyCyKuLWE9O+YWXUjIoiDE p8vWeYSBmyBnJfT6d9FoWMU1j279R8wxoQnpuni0hPl/qMVWNNbISEVG6eV+lkQhni6/ DkZBTYt4WGFGZQ/VrmBY0vQ8PSCymtSP135CX6zwS+ddvWLiMYNSOnGWAFDfvJ9GRJ5U vr2Lz+zFuc4FoxszQJE9FJBxhvOZ+5sHCtMYC2VcIclHYheK/9aEKrobhS2Ns3m4mBHi X+rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=HovDyLoW9JgP2dOMddyLtoMQVzEDX+zbCzhvdFpRmKg=; b=w2TSqeKzNfCIG8dtCKtCF44VGkAK/7gus5lMjW4v2EULPLKdMP8UCwNFFMweZtQ5rk cOvzp5CbiOdfgBODCG51tKMZE6jbspFHqX1oNDhY7RHBLgGMP2+MnlH2SjIJPIZikR4Q R/fwv8AddhVXg7eoBHes8SMQPDk2U1egJUoVZB34wOAzqQqcx6j0yJ5g6FEfd4r7Nbgs 3slyw0SM3y2fOUsV3oXwXS74H9B5YK5HDDi3Xdvo2e7iRqaHqU1XBXNYJs9pufO+2Vve O9gU/p7W3EY6/a02WTOxObnsTSnnnpfP8+ZQLo3q7NEU5duVWsEzIygKoDjEeYuGC5yN FHIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D7qcptHP; 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 w67si25866747pgw.84.2018.11.19.07.38.30; Mon, 19 Nov 2018 07:38:45 -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=D7qcptHP; 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 S1729803AbeKTCBt (ORCPT + 99 others); Mon, 19 Nov 2018 21:01:49 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:52384 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729745AbeKTCBs (ORCPT ); Mon, 19 Nov 2018 21:01:48 -0500 Received: by mail-it1-f196.google.com with SMTP id i7so2686060iti.2 for ; Mon, 19 Nov 2018 07:37:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HovDyLoW9JgP2dOMddyLtoMQVzEDX+zbCzhvdFpRmKg=; b=D7qcptHPzcuFLxZJDKf3/4DYoAkuBIC1/vhhevIzPorrX0vffSlkOwDgxtkWOJQ5at HawzLKIlQZPHhzcg/ht+WOn2/Bwzx35gGjNcBaHjt33qZAinytdLYzklmhvd92e87Qpx QdcvOzwwWfj2RygLc+IHYXpaaAK0ppUfMF4FA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HovDyLoW9JgP2dOMddyLtoMQVzEDX+zbCzhvdFpRmKg=; b=jTDx4wbYUqgsbOTTbuLMZZC5BazOly0eHjKEIksXrQg8kvzYiYHQvM0cUMHCmnLQ+y YN0xIGO4Cx1Wr/PettxblC+JEsaF2A4iHWKpEZUkTUDzQvgcQTHP3A8F18H+IQ+Hu1sY sl4Pgk/vbSx9sU7pU6Xyqx4LIa/ZuPh7P0unAjcU77lHqCxer2q0xuvBFpbL/X1U5qiY zHtXunUP83FTbkFyL2M1jBLc2mQgoCMec6p4CmvERCEOr0qnYMKRSlJGMIs/xlGoAlyh eKqif7s1XSFkUVndpVOCxs4ZI9XQCS0umCPAg1SykNoG3znpLi4g6/xlbZpSHYkcZNMk MSTw== X-Gm-Message-State: AA+aEWY37xH6IqVGtll8jk79eUrq2EiEZflJ4Wetkz7wXO1YMNe1o+is AXef8kZJdE0yPlrFL19e+09N5pujBVxQ2+U000RgCA== X-Received: by 2002:a24:710:: with SMTP id f16mr1015081itf.121.1542641871167; Mon, 19 Nov 2018 07:37:51 -0800 (PST) MIME-Version: 1.0 References: <20181117185715.25198-1-ard.biesheuvel@linaro.org> <20181117185715.25198-2-ard.biesheuvel@linaro.org> In-Reply-To: From: Ard Biesheuvel Date: Mon, 19 Nov 2018 07:37:39 -0800 Message-ID: Subject: Re: [PATCH 1/4] bpf: account for freed JIT allocations in arch code To: Daniel Borkmann Cc: Linux Kernel Mailing List , 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 , linux-mips , linuxppc-dev , sparclinux@vger.kernel.org, "" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 19 Nov 2018 at 02:37, Daniel Borkmann wrote: > > On 11/17/2018 07:57 PM, Ard Biesheuvel wrote: > > Commit ede95a63b5e84 ("bpf: add bpf_jit_limit knob to restrict unpriv > > allocations") added a call to bpf_jit_uncharge_modmem() to the routine > > bpf_jit_binary_free() which is called from the __weak bpf_jit_free(). > > This function is overridden by arches, some of which do not call > > bpf_jit_binary_free() to release the memory, and so the released > > memory is not accounted for, potentially leading to spurious allocation > > failures. > > > > So replace the direct calls to module_memfree() in the arch code with > > calls to bpf_jit_binary_free(). > > Sorry but this patch is completely buggy, and above description on the > accounting incorrect as well. Looks like this patch was not tested at all. > My apologies. I went off into the weeds a bit looking at different versions for 32-bit and 64-bit on different architectures. So indeed, this patch should be dropped. > The below cBPF JITs that use module_memfree() which you replace with > bpf_jit_binary_free() are using module_alloc() internally to get the JIT > image buffer ... > Indeed. So would you prefer for arm64 to override bpf_jit_free() in its entirety, and not call bpf_jit_binary_free() but simply call bpf_jit_uncharge_modmem() and vfree() directly? It's either that, or we'd have to untangle this a bit, to avoid having one __weak function on top of the other just so other arches can replace the module_memfree() call in bpf_jit_binary_free() with vfree() (which amount to the same thing on arm64 anyway)