Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5623421pxb; Mon, 28 Mar 2022 15:07:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2nBxRszQNnmJM91vTpmW4vQ0WCVHWpfLByDoYuooOK+XOb6t3kyIpbnoFjoAwGk5+QWCp X-Received: by 2002:a9d:6248:0:b0:5cb:508c:d38f with SMTP id i8-20020a9d6248000000b005cb508cd38fmr11079324otk.246.1648505219757; Mon, 28 Mar 2022 15:06:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648505219; cv=none; d=google.com; s=arc-20160816; b=tBp1TZM/xBYXzVyee+JJ9gnWYB9zcncO/juQ0i74Tk0PPmtX1eBWvv4MCpRdQHvYj5 WX4bG7ojUDD8nLKvsn3AvSoiWCtmeut/16+/UH3wkZ63jvG535AM8941D5ivNRMT4vQC c2aAAgL5YZrCQREG+xRtl6nfBqcVAJ796CGCh5yWPS0IJmVbhhwDwGQGMiWOEtLn4rS5 vxqYtO92g1DpayfpR7mHtnBnssDSfN+v94l2l85EWjjp9z96bKZhNd7PG1btNgy1WRgv jO+JVMMIqoitZskzoUqr+3BSy0r6bCSpRgzCEdLsdA7WwuP6EPJczuXMDU85MeZt2wRp 02hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=V8SPwDvoJviYgsUTGhN1PbWTTa7UH/mLN46SQAz/mHM=; b=mdNaDidMyCbHxRPDxjfq19EHaSmdCM2eK8+nWBKUiOWWrXtXUUP9auzUXi/zlQ/Vh2 5v0CM9PkdWfIWFlCq7v82zBrZ2hkVukiOQkF+039BwbaoWD/7Lty8pLreGSKPX05pqvH 9wA7RK2vgrr3Sklrku6KgM/65G6xDavGB7MSU4WFLDwF3jYXhQHCjsR3wX7QuaFOFIGb 0atgF6rx/SvvCNMVSiyxKDv3AESM/pzRqNz211OOp8hhGA8l8ACI81MiAEN1GBq/ruNN UjhMp4XcBvC4a/RfiS8/NYw28hfPUkROfhql6ybdxrlJXHQSOgSe3BmKUEVxxGRTjfgw p+XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LeSH7zKY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id v187-20020aca61c4000000b002ef0c347684si10623383oib.260.2022.03.28.15.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 15:06:59 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LeSH7zKY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4C9DC2D1F3; Mon, 28 Mar 2022 14:28:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242155AbiC1L7y (ORCPT + 99 others); Mon, 28 Mar 2022 07:59:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242153AbiC1L5t (ORCPT ); Mon, 28 Mar 2022 07:57:49 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BEA631DFB; Mon, 28 Mar 2022 04:54:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=V8SPwDvoJviYgsUTGhN1PbWTTa7UH/mLN46SQAz/mHM=; b=LeSH7zKYa2ASEHhCVpTn2c0IRh 08dAntK5bJWlCZMV/6R+8Ea3GZNpADKzqX32Lheclvr5DzcF/cDB1PZosWLuoXBqxdUgdMZdpl8hP 2/AjAtRXaojXWOuAmg/RPcN7AbJXz9OK3QZrWwSAQ7eRize9TTenjXk4bh3cKAKyngJUWmL/uUj+F lafpZQHgS200OScp4Q7we+evlYQZg7Sfi1PUeWZf79TUtaR/PQ2f7SKohLGuYw67I0SK+c1587mDn 2J0NUCfDM5t+6vAGPs39FJofyDY7eVTyCsA/dSbszDaRg6U7C166QERGq93riN+uVPf6SH/DfVcyc /MhIntCg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nYnx7-00GsqX-2c; Mon, 28 Mar 2022 11:54:29 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id F01849861E7; Mon, 28 Mar 2022 13:54:26 +0200 (CEST) Date: Mon, 28 Mar 2022 13:54:26 +0200 From: Peter Zijlstra To: Jakub Jelinek Cc: Mark Rutland , Segher Boessenkool , Nick Desaulniers , Borislav Petkov , Nathan Chancellor , x86-ml , lkml , llvm@lists.linux.dev, Josh Poimboeuf , linux-toolchains@vger.kernel.org Subject: Re: clang memcpy calls Message-ID: <20220328115426.GB8939@worktop.programming.kicks-ass.net> References: <20220325151238.GB614@gate.crashing.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 28, 2022 at 12:20:39PM +0200, Jakub Jelinek wrote: > On Mon, Mar 28, 2022 at 10:52:54AM +0100, Mark Rutland wrote: > > I think we're talking past each other here, so let me be more precise. :) > > > > The key thing is that when the user passes `-fsantize=address`, instrumentation > > is added by (a part of) the compiler. That instrumentation is added under some > > assumptions as to how the compiler as a whole will behave. > > > > With that in mind, the question is how is __attribute__((no_sanitize_address)) > > intended to work when considering all the usual expectations around how the > > compiler can play with memcpy and similar? > > no_sanitize_address or lack thereof is whether the current function > shouldn't be or should be ASan instrumented, not on whether other functions > it calls are instrumented or not. memcpy/memmove/memset are just a tiny bit > special case because the compiler can add them on their own even if they > aren't present in the source (there are a few others the compiler can > pattern match too) and various builtins can be on the other side expanded > inline instead of called, so one then gets the sanitization status of the > function in which it is used rather than whether the out of line > implementation of the function is sanitized. > > If coexistence of instrumented and non-instrumented memcpy etc. was the goal > (it clearly wasn't), then the sanitizer libraries wouldn't be overriding > memcpy calls, but instead the compiler would redirect calls to memcpy in > instrumented functions to say __asan_memcpy which then would be > instrumented. This then leaves us holding the pieces because this behaviour is actively wrong. A non-instrumented function *MUST*NOT* call an instrumented function, ever. This very much violates how we use/expect __attribute__((no_sanitize_address)) to work. If we use that on a function, we expect/rely on that function (nor any compiler tranformation thereof) to *NOT* have instrumentation. This is a hard correctness requirement that cannot be argued with. So there's two options: A) compiler generates implicit mem*() calls with the knowledge that mem*() is not instrumentet, and as such will also emit instrumentation for it when so required (or calls mem*_asan() like functions. B) compiler knows mem*() are instrumented, at which point the implicit mem*() calls are no longer equivalent under __attribute__((no_sanitize_address)) and will no longer perform these substitutions. At some point this becomes a choice between being able to boot or having KASAN, choice is simple.