Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp881285pxb; Wed, 27 Oct 2021 14:23:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNU80WzfJpPKMUSnUR6Wz12MJaxI+iw8qqsls7BWV5zY3aqcARRTTW1iqM2C4StzUNYtuF X-Received: by 2002:a05:6402:22d6:: with SMTP id dm22mr411226edb.209.1635369780101; Wed, 27 Oct 2021 14:23:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635369780; cv=none; d=google.com; s=arc-20160816; b=wyAV9Yjy485O5gk0N3uk7ygSHpqOP8QCFiW/iZuLcoNWmSlHM37zHA9eKfb4xuF+Mh NSMpqbsKwKmK7z72sn/ErSakvB72sSuDjesY+mpArBYn0pM302j0In9lH0BBrLVJ3yQK 4GmUyXVXeUGCj1VmuNGcXz1KK2ci3xAX2Cz28ogjavYHAY3BPgaePVtsrGlAVLpdhgFL atBbQpWBUmbCHSEGswBxrBS9skJ4HcBZRgrJ11y6ZxWISNfv3qLtd9dmyVCE8eJJHlxZ xeGTZAGBVxDBUc503op0/OOHTADuHZHnOsbczrb/+JERUaHrOojb7OvnDgLdaIp/Yazz k+Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=ZedZRARp1Bshr6CcHiFF7Iph4UIiWU09M7uz/SobNVQ=; b=J6fXWlu7/r0/wBuGA3U9y0rQBA28LWrFrbFduJTVgIetvoxwDuWDw7pychBHWtOmtx lf+J9fEvnMTVGLRrkEnJCdd14TaBAFB4mhFw9vJwnomTkbNDw7/pLy/rYTvQDljuTwOt O9JdeUDlMBH8frvwNJQUsN73XkBxoW3MsY7wQs9W4jneb7vF3Fw3o7JNj4xop7ka79Je mBhCRtQaWAjYKIBo1HC5Bq8hTEN7e9Uw5K841nt6jsbD7FgA6NtlMBQ+mbLlzXuAWluw mG8ONQSE9/b4bzBn8n9+idXVamLigZt6KD/6UOl0WOlHKxO2k8W9aI8CsYgCsXYndCa0 9oSg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k3si1171662ejj.462.2021.10.27.14.22.35; Wed, 27 Oct 2021 14:23:00 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239480AbhJ0KF0 convert rfc822-to-8bit (ORCPT + 97 others); Wed, 27 Oct 2021 06:05:26 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.85.151]:26456 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239461AbhJ0KFZ (ORCPT ); Wed, 27 Oct 2021 06:05:25 -0400 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-212-F1zRjfSTOoCL9nIp_zwQSg-1; Wed, 27 Oct 2021 11:02:57 +0100 X-MC-Unique: F1zRjfSTOoCL9nIp_zwQSg-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.24; Wed, 27 Oct 2021 11:02:56 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.024; Wed, 27 Oct 2021 11:02:56 +0100 From: David Laight To: 'Peter Zijlstra' , Sami Tolvanen CC: "x86@kernel.org" , Kees Cook , "Josh Poimboeuf" , Nathan Chancellor , "Nick Desaulniers" , Sedat Dilek , Steven Rostedt , "linux-hardening@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "llvm@lists.linux.dev" , "ardb@kernel.org" , "mark.rutland@arm.com" Subject: RE: [PATCH v5 00/15] x86: Add support for Clang CFI Thread-Topic: [PATCH v5 00/15] x86: Add support for Clang CFI Thread-Index: AQHXyqbRFu1L74SRSES6mpaoExEoXavmm4bQ Date: Wed, 27 Oct 2021 10:02:56 +0000 Message-ID: <7ebed28b73bb48cd9b69e9097f0aa613@AcuMS.aculab.com> References: <20211013181658.1020262-1-samitolvanen@google.com> <20211026201622.GG174703@worktop.programming.kicks-ass.net> In-Reply-To: <20211026201622.GG174703@worktop.programming.kicks-ass.net> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra > Sent: 26 October 2021 21:16 > > On Wed, Oct 13, 2021 at 11:16:43AM -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: > > > > https://clang.llvm.org/docs/ControlFlowIntegrity.html > > So, if I understand this right, the compiler emits, for every function > two things: 1) the actual funcion and 2) a jump-table entry. > > Then, every time the address of a function is taken, 2) is given instead > of the expected 1), right? > > But how does this work with things like static_call(), which we give a > function address (now a jump-table entry) and use that to write direct > call instructions? > > Should not this jump-table thingy get converted to an actual function > address somewhere around arch_static_call_transform() ? This also seems > relevant for arm64 (which already has CLANG_CFI supported) given: > > https://lkml.kernel.org/r/20211025122102.46089-3-frederic@kernel.org > > Or am I still not understanding this CFI thing? From what I remember the compiler adds code prior to every jump indirect to check that the function address is in the list of valid functions (with a suitable prototype - or some similar check). So it add a run-time search to every indirect call. What would be more sensible would be a hidden extra parameter that is a hash of the prototype that is saved just before the entry point. Then the caller and called function could both check. That is still a moderate cost for an indirect call. Anything that can write asm can get around any check - it just gets a bit harder. But overwritten function pointers would be detected - which I assume is the main threat. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)