Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3007815pxb; Tue, 24 Aug 2021 12:48:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOpdn7vjqEKTj1ebM0lzRzzEqVeutFrxZQBgndRr4ZEJ/p0J5HfoZTv31b8Fuy5AlbLGWs X-Received: by 2002:a92:d586:: with SMTP id a6mr27194572iln.283.1629834530014; Tue, 24 Aug 2021 12:48:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629834530; cv=none; d=google.com; s=arc-20160816; b=uDdiLI4PmUZIm5+wXSLPYZPMKSWj837MXlIa/UU+NhjSJZ79IzLU/myCFbQYX/xJIM /KJDq5xjUolt4UXTu6Ps9ZnPGD6A4+QuTLKokt1wX24iOZeuxg0vd5xw+D0Uh0UAFKyD 3/RoyArPZvenQa54LcFtMme4tFGX9yneQl9ZYlhPp1F6Xb7L+hG6sdZoAbS2b8nyZvIK sgnFksC80bPlNeaKlExcMcoz/d6ALBnu+4bfbPHuWwQE3bD/9aStqqTF9AKce4cBH90v IuYlFysymbZc8JgQuE9w8BZc0zopBtTj3Eu0YSlAaOosPUX0VOXTeFbFljFcQHjtwpsb 8osA== 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=5xmXB2Lw/5xwUTRzhqLNhETYzTNETFh6DtMn8eUe4N4=; b=vJCSbabgYaI5Cn4OOXA5lx/aZPMKa0fjt090VtQI2WuByXDNi+frAFRJHlTjTw2MRP Yv5399vyO3MMhL7rZ+9/udrejFbtngxC2z2kdKAMGSwFRmKBydAHLi3K+KqMk3YAFKv9 hDzIG59oU8JJsUVBLw+qqDPLupRW8eJWdv5RpnN8islC4NNl0kfPI0pJDIA4n5ot1ao/ h+xw1ouRKwW+jx93JM8+mm4EHP4f+YHZA28Rore8SYqXQ2ezQS2VwJgGgE9E3jQ2dKhu 4tGhhubjL3woK0OaDJJSL2tffa/OWwBUhj+VmgqlSN6eknSpKSabMDgUoBeU5vcHcpw9 6iFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=GV04Oz1m; 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 n13si18600961ili.37.2021.08.24.12.48.37; Tue, 24 Aug 2021 12:48:49 -0700 (PDT) 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; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=GV04Oz1m; 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 S235104AbhHXTr7 (ORCPT + 99 others); Tue, 24 Aug 2021 15:47:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbhHXTr6 (ORCPT ); Tue, 24 Aug 2021 15:47:58 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E19FDC061757; Tue, 24 Aug 2021 12:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=5xmXB2Lw/5xwUTRzhqLNhETYzTNETFh6DtMn8eUe4N4=; b=GV04Oz1moYv6gNOH40ylMi/NQa metvJKbOP2iPdDUhWKcAC8Ky5DqjfpI6Yqk6gOUWOsKtTyyaTzcyZDpERAg/6ykMJCVJx76NCGt3T Rifsl17evmXj7yJiLKaoQCu4n9LEGMGHOLMTmLTS7IB5JFRqwoS42RzlUOLJm8XrTjWv6vHpsQ7Kh uq/TfeaXsTFIzm+eXTO/B7TGb09kwPk8vudY6XQjqnuhn8wMLCaYjPn8OXpDJAg/EOCTFRXzwiP+Z uiN58m6+nptSOvFikZVJcpPVMhCBTL9DPuL60e89nTC1Omdujf4+NdE0qnXwWK63PTzTH/R9rkoCm ZPIGPeJg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mIcNq-00CgII-Jj; Tue, 24 Aug 2021 19:46:54 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 493BA981198; Tue, 24 Aug 2021 21:46:52 +0200 (CEST) Date: Tue, 24 Aug 2021 21:46:52 +0200 From: Peter Zijlstra To: Sami Tolvanen Cc: x86@kernel.org, Kees Cook , Josh Poimboeuf , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Steven Rostedt Subject: Re: [PATCH v2 00/14] x86: Add support for Clang CFI Message-ID: <20210824194652.GB17784@worktop.programming.kicks-ass.net> References: <20210823171318.2801096-1-samitolvanen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210823171318.2801096-1-samitolvanen@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 23, 2021 at 10:13:04AM -0700, Sami Tolvanen wrote: > This series adds support for Clang's Control-Flow Integrity (CFI) > checking to x86_64. With CFI, the compiler injects a runtime > check before each indirect function call to ensure the target is > a valid function with the correct static type. This restricts > possible call targets and makes it more difficult for an attacker > to exploit bugs that allow the modification of stored function > pointers. For more details, see: If I understand this right; tp_stub_func() in kernel/tracepoint.c violates this (as would much of the HAVE_STATIC_CALL=n code, luckily that is not a valid x86_64 configuration). Specifically, we assign &tp_stub_func to tracepoint_func::func, but that function pointer is only ever indirectly called when cast to the tracepoint prototype: ((void(*)(void *, proto))(it_func))(__data, args); (see DEFINE_TRACE_FN() in linux/tracepoint.h) This means the indirect function type and the target function type mismatch, resulting in that runtime check you added to trigger. Hitting tp_stub_func() at runtime is exceedingly rare, but possible. I realize this is strictly UB per C, but realistically any CDECL ABI requires that any function with arbitrary signature: void foo(...) { } translates to the exact same code. Specifically on x86-64, the super impressive: foo: RET And as such this works just fine. Except now you wrecked it.