From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 6BCF9279DCA; Fri, 13 Jun 2025 08:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749803209; cv=none; b=bPC7d23Qz0eHuBJ1QECQA2lKlBLyPloN2PkqZmbRwxT5Swzgy4aJhDIwpofWFCV+9oZvN84q2v1ycdyi9l+d5o7ndYlzqWe961pK/QLDRV8/PyU5afT/j6o06dTejq95umD0iycTHnn9WGQipCiVqDxQ6QL7mIWU9eN0jqyyfyQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749803209; c=relaxed/simple; bh=oy7cnpuIfUbxnBIHzSxSzs3wF3pN160eEFEtn1XrHHA=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=PGjcvFLqwwHFY7Wvxpv8rNgBQzvR8EAtgx5Io/C9T2cNTKGlVikOWVQLHWaMdS/YQae6FUbnv+rHqNJDYeOE8Po+TweENGgpLf2UyhS4a8mgqfgFC6xhoFkxQRGZmwUm5ttDGSOg8lGTiKLVbRct9KUf3LQexZKVe53Ol82WLNI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=BnJGbMk/; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="BnJGbMk/" Received: by mail.gandi.net (Postfix) with ESMTPSA id B142A41C06; Fri, 13 Jun 2025 08:26:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1749803203; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oy7cnpuIfUbxnBIHzSxSzs3wF3pN160eEFEtn1XrHHA=; b=BnJGbMk/e7fYDOccAaKbhkPl6Zkb+CJk54xIzM7oGJ/68LdgKmC814rIU32t6tdn2RLttv x15WZiOubSuud24F243NbAQNPG2k3Dui7U5bdWbzo6Lo7AjeJ+KSplTU5N9Z/cTjXj0Rr9 AtxWE42xFJSR7fqyJtvD37GTtg2rovAwTR+VAfdN1C4ZXMlk7rhOwNdTxFQnBalxqPz9tm e/OD8ENjC+yzoBhzLvEBBNcwIj7ZN9YK2gi89xBilq+iVetQOvwYaFKA3l+J6erZ08hSMo zVQuK+p9cI9MOofvRUYJC5RnI8Wf/o3bDNy4BjM6rT5BKMfG/sqEM22GLR1tVQ== Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 13 Jun 2025 10:26:37 +0200 Message-Id: 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" , , "H. Peter Anvin" , "Menglong Dong" , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , "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" , , "Thomas Petazzoni" , "Bastien Curutchet" , , , , =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= , , , , , , Subject: Re: [PATCH bpf 2/7] bpf/x86: prevent trampoline attachment when args location on stack is uncertain From: =?utf-8?q?Alexis_Lothor=C3=A9?= To: "Peter Zijlstra" X-Mailer: aerc 0.20.1-0-g2ecb8770224a 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> In-Reply-To: <20250613081150.GJ2273038@noisy.programming.kicks-ass.net> X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddugddujeegiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepggfgtgffkfevuffhvffofhgjsehtqhertdertdejnecuhfhrohhmpeetlhgvgihishcunfhothhhohhrrocuoegrlhgvgihishdrlhhothhhohhrvgessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepvdfftdejhefhieelvefhgeffvddulefhfeegleegkefgffejgeffjeeigfdtveeinecuffhomhgrihhnpehlihhnuhigsggrshgvrdhorhhgpdgsohhothhlihhnrdgtohhmnecukfhppedvrgdtvdemkeegvdekmehfleegtgemvgdttdemmehfkeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdgrtddvmeekgedvkeemfhelgegtmegvtddtmeemfhekhedphhgvlhhopehlohgtrghlhhhoshhtpdhmrghilhhfrhhomheprghlvgigihhsrdhlohhthhhorhgvsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopeehkedprhgtphhtthhopehpvghtvghriiesihhnfhhrrgguvggrugdrohhrghdprhgtphhtthhopegrshhtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhesihhoghgvrghrsghogidrnhgvthdprhgtphhtthhopegrnhgurhhiihesk hgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgrrhhtihhnrdhlrghusehlihhnuhigrdguvghvpdhrtghpthhtohepvgguugihiiekjeesghhmrghilhdrtghomhdprhgtphhtthhopehsohhngheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohephihonhhghhhonhhgrdhsohhngheslhhinhhugidruggvvh X-GND-Sasl: alexis.lothore@bootlin.com 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=C3=A9 (eBPF Found= ation) 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. --=20 Alexis Lothor=C3=A9, Bootlin Embedded Linux and Kernel engineering https://bootlin.com