From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 72E412C81 for ; Sat, 16 Oct 2021 21:12:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634418726; 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: in-reply-to:in-reply-to:references:references; bh=NjDNk6B/N6Q1irkDiWN3RyxwNrYWGdj8hgHHx1uvt14=; b=BuXiPspPwsAMdcZs2o7EHp8y5M1CGBolb0e+l8k7e3E/MJBgR7wBur5BIf3ddENmynWv0P LyagOhsnQuB2aUOvFXGQmLcOj19w37FWKcpSwkmwBTnU7VXrjhPqwJAek18DVX8p7188P1 X0bWTPglFbDDWUG30Pem6g1b1cNjgtw= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-310-431iHi0gMNOdlRBmInke8A-1; Sat, 16 Oct 2021 17:12:05 -0400 X-MC-Unique: 431iHi0gMNOdlRBmInke8A-1 Received: by mail-qv1-f69.google.com with SMTP id if11-20020a0562141c4b00b0038317257571so11238611qvb.3 for ; Sat, 16 Oct 2021 14:12:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NjDNk6B/N6Q1irkDiWN3RyxwNrYWGdj8hgHHx1uvt14=; b=AhkI7Bo3IiCz2qc5OEuTDxiwsmEVhcSW00DCXsev3fW4xWwWTz55z+UpMda46pxkXF oAhCdP9IqE3rbTaMcb3ymVM4aS8PY8Ol2Pk4k4T2SOWfz+BF7F0kELZodNW55vqpKFi5 FKu0Ma1p/NpXOE3lD7oOpqvQvea7ffXJ2q2wH9KjDRwprCz8rPtkaxwkGSstG7Jy/n+5 GD0Bcc8VyXVUObXvxhwBfCa5G/Z/DnLChnZOlnqA69Ii7KFQjoCjFUaoWYBSd0BcDoqe /eoZvZ8Czh3mGqLgaoL5Et8oP9BwRgruy0zSV0YXJv4ts7O3ExRhJIYsHgB/hSgkmxKU p5qQ== X-Gm-Message-State: AOAM530jFZFAxxWV5s2OCtMLqwChkQeFVNSMu8eV/VaMr01x/WnnPDsb YHMwKotcCxpvKK2lslIEK02X0Ipw7ueh82wfOVvLSO57LA1gJX1z/9HuAasATZ2dF5Z66BslhvO U33Brm2FnY6037Q== X-Received: by 2002:ac8:5a96:: with SMTP id c22mr22223715qtc.266.1634418724704; Sat, 16 Oct 2021 14:12:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVGk5UnzfsoIArgonptC4VlypIIv1AYjcxHn9hf+CT+hjv4CCjkR/qLas5v6PvM1LoiiypmQ== X-Received: by 2002:ac8:5a96:: with SMTP id c22mr22223703qtc.266.1634418724447; Sat, 16 Oct 2021 14:12:04 -0700 (PDT) Received: from treble ([2600:1700:6e32:6c00::15]) by smtp.gmail.com with ESMTPSA id z186sm4435014qke.59.2021.10.16.14.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Oct 2021 14:12:03 -0700 (PDT) Date: Sat, 16 Oct 2021 14:12:00 -0700 From: Josh Poimboeuf To: Sami Tolvanen Cc: Andy Lutomirski , Thomas Gleixner , the arch/x86 maintainers , Kees Cook , "Peter Zijlstra (Intel)" , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, Linux Kernel Mailing List , llvm@lists.linux.dev Subject: Re: [PATCH v5 03/15] linkage: Add DECLARE_NOT_CALLED_FROM_C Message-ID: <20211016211200.umf7okyvtet5ayrd@treble> References: <20211013181658.1020262-1-samitolvanen@google.com> <20211013181658.1020262-4-samitolvanen@google.com> <7377e6b9-7130-4c20-a0c8-16de4620c995@www.fastmail.com> <8735p25llh.ffs@tglx> <87zgra41dh.ffs@tglx> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jpoimboe@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline On Fri, Oct 15, 2021 at 01:37:02PM -0700, Sami Tolvanen wrote: > > But we *also* have the read-the-address thing: > > > > void something(void) > > { > > /* actual C body */ > > } > > alternative_call(something, someotherthing, ...); > > > > That wants to expand to assembly code that does: > > > > CALL [target] > > > > where [target] is the actual first instruction of real code and not > > a CFI prologue. > > Yes, here we would ideally want to avoid the CFI stub for better > performance, but nothing actually breaks even if we don't. That's because there's no CFI involved in alternative_call(). It doesn't use function pointers. It uses direct calls. So all the discussion about clear_page_*() is completely irrelevant. It has nothing to do with CFI. Same for copy_user_enhanced_fast_string() and friends. > > And this all wants to work both for asm-defined functions and > > C-defined functions. This really is orthogonal to the > > is-it-asm-or-is-it-C things. All four combinations are possible. > > > > Does this make any sense? Not really, I think Sami debunked most of your theories :-) I think you're misunderstanding how Clang CFI works. It doesn't instrument the target function. It hooks into the caller's function pointer relocation, so when I try to call func_ptr(), the compiler hijacks the function pointer and forces me to call into a func_ptr.cfi_jt() checking function instead. > > I kind of thing we want the attributes and the builtin, along the lines of: > > > > asm("call %m", function_nocfi_address(something)); > > > > or however else we wire it up. > > > > (And, of course, the things that aren't C functions at all, like > > exception entries, should be opaque.) > > I agree, there are cases where having a function attribute and/or a > built-in to stop the compiler from interfering would be useful. I'll > dust off my patch series and see how the LLVM folks feel about it. With all the talk about function attributes I still haven't heard a clear and specific case where one is needed. If you take out the things that don't actually need the DEFINE_NOT_CALLED_FROM_C() annotation then all you have left is the need for opaque structs as far as I can tell. -- Josh