Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp502313pxb; Thu, 19 Nov 2020 06:49:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJyBfOQ1QsW6BswWmecPdR6Be6BxhHoFK/OJQk5+ZfnoRK1ubRfgz8iEoki7PVc6CUZ70xF0 X-Received: by 2002:a50:e443:: with SMTP id e3mr31979435edm.160.1605797359088; Thu, 19 Nov 2020 06:49:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605797359; cv=none; d=google.com; s=arc-20160816; b=okRxKlWQA7qwCFA4Bj1tLpr/haJHywQw1klVsIqrO15fql2U2m92+OPkcTfpobRa7s GJSamQeg2rnQVcRhn4pePciIgrwUb2PX9JCmxFuQ3vILk9JWf+WfaGmNQxr/gjMF4BmV jc9jqDIUBsy7gC31zrIFQuAM3FeegpSgwfUkHJu3SPLYi/kwaG+YX7+h7olkb7yZbgxJ pJ3q9zOwp88cOaNaVAexiaP5Ai6eeysqkaa7PebkW5Mb8ldgo7tXYd0au3viWPxqEmZ7 ZAsl1HAHLx9Xl7oJbye4XbhhzdSVh+OCHIzNYHGNjGYaZZiOrXsBpwBQTdeTAt7z9dxi XVAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=VOZkdPpbkVKkRTd3iSutk6MjmVOBFZRNHbAVxy6ZPwg=; b=YB8Oe6S/AMhHnoICLMmD5QqUiGgifW8087BJvo1YZEr/jzhyEYpW3084UZ3QXDDvSK spOJkRpArr7VYQrXHz9/LjWbc5CjQ4kYF6pHsmsT2ySTwKvjPT5TEzjLHZrVKjqv87Ri lVU227OTbFtXdi194ZEMT4pQRdX4X8dyN7wfNxe4a+LSD6Bh9g5sZ6q6IKzK/SRrgHo8 ffpcO25d+E2zbzHWsPOLrckvKrtxsyoGYfQqbXrp/U1T9szapOh4iUn0qSrEvjWZPwav j5m9xI/GkSWl2oywKgTZoLtWVvseR+e5o7aq4oJMVbPpFXG52StyVX8a2ZK3ZCQ2yvuG kiLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r15si18008494ejy.36.2020.11.19.06.48.56; Thu, 19 Nov 2020 06:49:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728421AbgKSOqs (ORCPT + 99 others); Thu, 19 Nov 2020 09:46:48 -0500 Received: from gate.crashing.org ([63.228.1.57]:45519 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728036AbgKSOqr (ORCPT ); Thu, 19 Nov 2020 09:46:47 -0500 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 0AJEbiJe017745; Thu, 19 Nov 2020 08:37:44 -0600 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 0AJEbarp017727; Thu, 19 Nov 2020 08:37:36 -0600 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Thu, 19 Nov 2020 08:37:35 -0600 From: Segher Boessenkool To: Peter Zijlstra Cc: Steven Rostedt , Florian Weimer , Nick Desaulniers , Sami Tolvanen , Mathieu Desnoyers , linux-kernel , Matt Mullins , Ingo Molnar , Alexei Starovoitov , Daniel Borkmann , Dmitry Vyukov , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , netdev , bpf , Kees Cook , Josh Poimboeuf , linux-toolchains@vger.kernel.org Subject: Re: violating function pointer signature Message-ID: <20201119143735.GU2672@gate.crashing.org> References: <375636043.48251.1605642440621.JavaMail.zimbra@efficios.com> <20201117153451.3015c5c9@gandalf.local.home> <20201118132136.GJ3121378@hirez.programming.kicks-ass.net> <20201118121730.12ee645b@gandalf.local.home> <20201118181226.GK2672@gate.crashing.org> <87o8jutt2h.fsf@mid.deneb.enyo.de> <20201118135823.3f0d24b7@gandalf.local.home> <20201118191127.GM2672@gate.crashing.org> <20201119083648.GE3121392@hirez.programming.kicks-ass.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201119083648.GE3121392@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.4.2.3i Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 19, 2020 at 09:36:48AM +0100, Peter Zijlstra wrote: > On Wed, Nov 18, 2020 at 01:11:27PM -0600, Segher Boessenkool wrote: > > Calling this via a different declared function type is undefined > > behaviour, but that is independent of how the function is *defined*. > > Your program can make ducks appear from your nose even if that function > > is never called, if you do that. Just don't do UB, not even once! > > Ah, see, here I think we disagree. UB is a flaw of the spec, but the > real world often has very sane behaviour there (sometimes also very > much not). That attitude summons ducks. > In this particular instance the behaviour is UB because the C spec > doesn't want to pin down the calling convention, which is something I > can understand. How do you know? Were you at the meetings where this was decided? The most frequent reason something is made UB is when there are multiple existing implementations with irreconcilable differences. > But once you combine the C spec with the ABI(s) at hand, > there really isn't two ways about it. This has to work, under the > premise that the ABI defines a caller cleanup calling convention. This is not clear at all (and what "caller cleanup calling convention" would mean isn't either). A function call at the C level does not necessarily correspond at all with a function call at the ABI level, to begin with. > So in the view that the compiler is a glorified assembler, But it isn't. > Note that we have a fairly extensive tradition of defining away UB with > language extentions, -fno-strict-overflow, -fno-strict-aliasing, These are options to make a large swath of not correct C programs compile (and often work) anyway. This is useful because there are so many such programs, because a) people did not lint; and/or b) the problem never was obvious with some other (or older) compiler; and/or c) people do not care about writing portable C and prefer writing in their own non-C dialect. > -fno-delete-null-pointer-checks etc.. This was added as a security hardening feature. It of course also is useful for other things -- most flags are. It was not added to make yet another dialect. Segher