From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796092721; b=fHJjJs6E+pTlBOldlzGOa4yUhMTZ89inTRv0sRw/lTNJqn4sOxEYGgX3rmBtVVw7nTAo nZ4WI9qvoQWvrsYNITkiSAG0gOFCEinWOZRfNhC+scCBr9X2O1HAMuKOFSFYN/X9C3g+0 O1D6Chalg5q6Q8INRCzzwxiuJZXceyd3qf/M56aLL1bKV09c4q9QoEXERsq+rbBMvrEbz IK72AEnhZ8OznPhQDpY1kCElWA6mjtTK9OcsZDviNESsqmG6vegwpf1XAm/6Bo95Hqrty K/2hQ4ZFn4yZ8hZLHJrg3t3YEDS0UgTzxMSLxy/wMJtWwMmXR1d8wydTN9fiTSRfzOA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796092721; h=Received:DKIM-Signature:Received:Received:X-ME-Sender: X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID:Received:X-Mailer: MIME-Version:X-ThreadId:Date:From:To:Cc:Message-Id:In-Reply-To: References:Subject:Content-Type:Content-Transfer-Encoding; bh=cuHZGN7KRSV5ePQMmmIBrIUK9HamD3Q/faO64j5QqyQ=; b=Fb9K95tX5DEYaRN0inmiJJJkh5S3Z9uugwKp813QoslLq3sifBNLE3w03MbxKiDZDxoE ucG9OgYG2PGRFFDlSwMbyrzfmgp793x+VDq5gUgZ4CU+WeAcdp+3C7GQn/9KD3MHyxZ1c hkgxSSWbMFoavO3FSCg5F2d7vv8QNjjNkGu9+WqTI6EqEhck80cSDP5y2fKITh3J27IZo pkLhbHgLhI3skiRsSWRmEOVrJwXipD6DDbAtHco4CDnwugnhwtk90SUc35J7P9yRavuGR Ebh48erxB6v5tm8qFs1pqBGzY7bvYvkQZpcI/z7Qg9OE7zfuwe7FG69qNq2eJPxte5w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TS5OGyRb; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D035F606A320 for ; Tue, 1 Dec 2026 02:38:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TS5OGyRb Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF55D1F0089A; Tue, 1 Dec 2026 02:38:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796092721; bh=cuHZGN7KRSV5ePQMmmIBrIUK9HamD3Q/faO64j5QqyQ=; h=Date:From:To:Cc:In-Reply-To:References:Subject; b=TS5OGyRbfGtj3TkyIZcq/VMTXNodKrtMxDhz5Hp6Pk9YH8u11LtacJKpfFwxe2WZp WXbYZknQCKO3WZ77voGNx+4IaRQM6S9gjKFltddATn/8pDIDuEymA+V7l8sYlZmdyh RXHmgyeGQixpXNFtWVdInownygEy/wG69ASDbMlaCiC/GYPdpCWizgQ0+kWUa49pe6 mdCf2n/H4cDD8bomAWCMrIzMdTtGb6WDyT/OsHc0i5M+i16JP5fxAmVexPK4OH/FlW SHYTHeNYoyLR8u8HIcQ7BdUgIjBgODdl730+4wWh2UsDmZWnboIGJiuoTqZXqEeBVC fZeolc0WKKouA== Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfauth.phl.internal (Postfix) with ESMTP id 12629F40067; Mon, 30 Nov 2026 21:38:40 -0500 (EST) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-01.internal (MEProxy); Mon, 30 Nov 2026 21:38:40 -0500 X-ME-Sender: X-ME-Proxy-Cause: dmFkZTE7YnmrppjgYk7cOl39QfRBg5eCl7/tvcpc8bvwTAA+EXAUxJ/Az85xVnixA0GOve lttICnlJbZUVCLmz57Xj3EFm94bputgQKLQbIav8ZtkZZSK3ZpqXCkQhETB/WuMFBT7dhz eVLvzOmaR72G6EbZeMxrQMcb3xoQig2GvRxaj6v5/9YI1zuWwxq9klaqFBIow4BrZSijRV Aq4Q7gubC5+qT9+QkCBaXcvszjr95aaEfBf6Uo7oCCfb7xd3MAwslGcU3vyoD++Y+73rqD Oy/oqKJVTbKWXPhyRFSJe3okiq0fICb1Cm5Vox7Jv2oE1Yq+yxYJex1yXn5F2do7vqgNdn HJ+ydjKCO/YkB5/fGtayiRU5cxulpkUDsSyNrjkyuDn1Qct9Ez8KX6ZSVHehg+R7qu3r13 +1j7R/SOIZxO9ElvoRbmhDzSyhWcPhjlE+rC4X1bNTcmNWoUbyRWeKM0pEBUTjhvWZFmw+ kKkJn9bR6CUuDUkeGnNx5Lqkg02t82NqzyfwGKb8MuM5VhVIusQ9Vjm6j1SAA7SyXuxnAr 5kNLZi44GF8aq9d8b4x9GXdI+8DyarqZXMg7uueV7Z7v6bCWG4uHvfBnpXNXJxtveIoXH1 jFVa+67kQIr5pbz2hNMJzczcl7LXgfFR+91cOraVnJ4D7lueo0gFFcdDzxEQ X-ME-Proxy: Feedback-ID: ieff94742:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id DF8DF700065; Mon, 30 Nov 2026 21:38:39 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-ThreadId: AisSLPdYCdlo Date: Mon, 30 Nov 2026 18:38:19 -0800 From: "Andy Lutomirski" To: "Kumar Kartikeya Dwivedi" Cc: "Alexei Starovoitov" , bpf@vger.kernel.org, "Puranjay Mohan" , "Andrii Nakryiko" , "Daniel Borkmann" , "Eduard Zingerman" , "Emil Tsalapatis" , "Ihor Solodrai" , "Dave Hansen" , "Peter Zijlstra (Intel)" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , kkd@meta.com, kernel-team@meta.com, "the arch/x86 maintainers" , "Linux Kernel Mailing List" Message-Id: In-Reply-To: References: <20261009024925.3169077-1-memxor@gmail.com> <20261009024925.3169077-2-memxor@gmail.com> <5f46d1c1-fdce-4f3b-9d56-675a822b2d65@app.fastmail.com> <03275761-8de2-41be-92fd-8e3012a87eeb@app.fastmail.com> <1ba7d551-32e1-4020-b898-502cd9ab8fb7@app.fastmail.com> Subject: Re: [PATCH bpf-next v1 1/3] x86/mm: Resolve BPF exception fixups for user address faults under SMAP Content-Type: text/plain Content-Transfer-Encoding: 7bit On Mon, Nov 30, 2026, at 6:06 PM, Kumar Kartikeya Dwivedi wrote: > On Tue, 1 Dec 2026 at 02:49, Andy Lutomirski wrote: >> >> >> >> If you believe that the BPF verifier can statically verify that a BPF program doing a PROBE_MEM access is referencing a valid (or maybe only mildly stale) kernel address, then I encourage you and Kumar to drop all of the x86 patches you keep sending, remove all the code that BPF emits to avoid tripping over SMAP, and be completely confident that the kernel will never OOPS or otherwise malfunction as a result. >> >> If you don't believe that, for example if you think a program might do x = a->b->c where the *a cannot be proven to still be alive and intact at the time that a->b is read, then I don't think that __iomem will save you, and maybe you should not believe anything in the previous paragraph, and maybe you should rethink this. > > Hi Andy, > > I think that part is clear to me, __iomem based rejections are useful > but not sufficient to prevent the problem you mentioned. I should have > been clearer in my earlier reply. > > That said, some of the options you outlined would be too expensive > (like walking a table at each access) and would just make tracing > programs prohibitively slow due to potential overhead. If you look at > the cover letter, some programs consist largely of probe reads, and > are often used in performance critical paths for observability and > statistics collection. > > Taking a step back, we agree that ioremap() pages are also a problem > for every user of copy_from_kernel_nofault(). My impression is that > exploring a region based approach, so we can isolate ioremap() regions > in a range and using a range check to cheaply work around those > addresses would be the best fit. I haven't spent time exploring this > option, but I'm happy to follow up separately. > As I understand the situation, there's a class of eBPF programs that contain memory accesses that cannot be statically verified to be correct, and eBPF is does not actually trust the programs enough to run them despite the lack of verification. And presumably the SMAP check (or the range check that avoids it) actually gets hit in practice, so eBPF can't get away with just ignoring the issue, because it will OOPS on occasion. I'll assume for the sake of this discussion that it is actually reasonable for eBPF to have a primitive that means, approximately, "read this address and produce either a garbage result or zero in case the pointer is bogus". (And that it's okay that a malicious attacker might control the result, etc.) Given this, eBPF needs an implementation of the primitive. Apparently the pointers really are wild enough that they hit user-half addresses with some frequency and they've even hit the vsyscall page. So I'll assume that they are genuinely completely wild. And you want good performance. And there is no plan that I'm aware of to improve the verifier and the tools available to eBPF programs to get actual static verification. So I think this is a catch-22. x86 could make an arch change (the ignore-bpf-smap-violations thing) that will make most, but not all, wild pointer reads "safe" in the sense that they will return zero instead of oopsing. But it will do nothing to help the smaller fraction that hit side-effect-ful memory out of bounds. And it will encourage everyone to forget about the issue even while it's known buggy. > At the same time, getting rid of the user space address check which is > feasible when SMAP is enabled, and closing the case where __iomem > tagged pointers are rejected from the verifier, both seem useful > additions to me. They do not fix everything we discussed but are > orthogonal improvements to the status quo, reducing overhead and > preventing potential mistakes. I think the __iomem change makes sense. Those programs are presumably just wrong. But I'm not seeing why the SMAP change is actually a good idea, since it just papers over the issue by suppressing most of the OOPSes. In any case, if eBPF needs a dynamic check for address safety, then it needs a dynamic check or address safety. x86 has PKS, which can do this (on some CPUs), coherently with the page tables. And it can be done as ordinary code. Using a temporary mm will be slow. I don't really see another option. > > Even if we have to keep instrumentation for the ioremap() range (since > we don't have potential ways to cheaply activate hardware protection > on such accesses), that will still be much cheaper (perhaps a single > branch) than emitting a longer sequence for each load instruction, as > we do today. > Can you explain what the sequence is? I'm not really seeing why SMAP is expensive but MMIO checks would be cheap.