From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51AEE2DA75C; Fri, 13 Jun 2025 08:32:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749803562; cv=none; b=KonmucDLdQrKZp2U89uFrzfKJNacrP8rAQB9oC4HAGc9/XvQog86IsmbDxkw6ZWmMl3H/PigBLBXeFmcujTdizWKOUxMmSPMACvdvS4cegO4OR7jh61WffL46BXUpTtAOxMhW6CCAORNnvx/dKdXGxx7Hq4TQFJW2BONmWhw9bk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749803562; c=relaxed/simple; bh=lH/7F/aDPraj67MYN2H8m0zzpepfCQa9N8ZMrQCE/h4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dKMlGnOi/WzMqGQtUz77oQ9CIJM+rSewIMUqze8XN8G6nTFTmcxOtQdXMpTHUg45OSFwV/UtIePw1Pu5db4KTR6OOGzCPJz0R0hUGBgQlbHZxcX8GdxRk6TMv7HqDWRLLAV+kTSu68saS2kSpIJbcELd8/YAyMYVWhIZhr7geio= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=ZRWi8pCI; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ZRWi8pCI" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=ceyQVU1s/TeC1A0uuWSXGNuCFCVzbMABPNZsJKr21a4=; b=ZRWi8pCIRln6gDBwDpL5TpDfHk niUGHnvaDU0AKjQp3zTX54Kw4vhPB112ARtEB3A3tsfHGDPm6te2aBSu7kQtFjcx3+kRZgROg+c7W kS7pt8ASyk3TCFFxhiEm6kPTIZMPPiU8dnfjrPAPRbBVgSDRNGvQTO0GcSsXKkLM7uvdZc9X4Otcr A50grAGUwhRNlVjkB6SSJaMvazcQwGoFc0/VziikYdX2zpo1f5E8Gom7g2W12Se9sFjjSftOPGhfM tDyo0kZ13bbnUwgZboISoP0egP9ZHd1TSEPBzLl/kwGBrm/dWyTWo/out4wopH6YyoR9cHDgoastf /btuiUCQ==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1uPzpy-00000002viF-2jCO; Fri, 13 Jun 2025 08:32:34 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 94D9E300969; Fri, 13 Jun 2025 10:32:32 +0200 (CEST) Date: Fri, 13 Jun 2025 10:32:32 +0200 From: Peter Zijlstra To: Alexis =?iso-8859-1?Q?Lothor=E9?= Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "David S. Miller" , David Ahern , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Menglong Dong , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Pu Lehui , Puranjay Mohan , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Ilya Leoshkevich , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Hari Bathini , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Mykola Lysenko , Shuah Khan , Maxime Coquelin , Alexandre Torgue , ebpf@linuxfoundation.org, Thomas Petazzoni , Bastien Curutchet , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kselftest@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH bpf 2/7] bpf/x86: prevent trampoline attachment when args location on stack is uncertain Message-ID: <20250613083232.GL2273038@noisy.programming.kicks-ass.net> References: <20250613-deny_trampoline_structs_on_stack-v1-0-5be9211768c3@bootlin.com> <20250613-deny_trampoline_structs_on_stack-v1-2-5be9211768c3@bootlin.com> <20250613081150.GJ2273038@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Fri, Jun 13, 2025 at 10:26:37AM +0200, Alexis Lothoré wrote: > Hi Peter, > > On Fri Jun 13, 2025 at 10:11 AM CEST, Peter Zijlstra wrote: > > On Fri, Jun 13, 2025 at 09:37:11AM +0200, Alexis Lothoré (eBPF Foundation) wrote: > >> When the target function receives more arguments than available > >> registers, the additional arguments are passed on stack, and so the > >> generated trampoline needs to read those to prepare the bpf context, > >> but also to prepare the target function stack when it is in charge of > >> calling it. This works well for scalar types, but if the value is a > >> struct, we can not know for sure the exact struct location, as it may > >> have been packed or manually aligned to a greater value. > > > > https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf > > > > Has fairly clear rules on how arguments are encoded. Broadly speaking > > for the kernel, if the structure exceeds 2 registers in size, it is > > passed as a reference, otherwise it is passed as two registers. > > Maybe my commit wording is not precise enough, but indeed, there's not > doubt about whether the struct value is passed on the stack or through a > register/a pair of registers. The doubt is rather about the struct location > when it is passed _by value_ and _on the stack_: the ABI indeed clearly > states that "Structures and unions assume the alignment of their most > strictly aligned component" (p.13), but this rule is "silently broken" when > a struct has an __attribute__((packed)) or and __attribute__((aligned(X))), > and AFAICT this case can not be detected at runtime with current BTF info. Ah, okay. So it is a failure of BTF. That was indeed not clear.