Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4433405pxb; Thu, 14 Oct 2021 05:13:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGZWF0gzKXp5K4eIHPwzrRwt60bBeJErH1jN+YASu61y9h1zbWVxJvccYI+vGYetmo1TgL X-Received: by 2002:a62:e40a:0:b0:44d:a86:43ce with SMTP id r10-20020a62e40a000000b0044d0a8643cemr5044522pfh.69.1634213588298; Thu, 14 Oct 2021 05:13:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634213588; cv=none; d=google.com; s=arc-20160816; b=Kz+ktFz+2nWYvr7ANkWvp9mwMoDbYEauuNHvFTQdPA4L2CEAqfPAvB5xQmGbBCyVFd m1ILSk89FQvqQucjxLWmmZvBPk+rFjIt4h8gA7t7QzB/SqKzf6oMBJhMS/gDFkoVEVtm TIt5YGq2Jzua8E400EeDUKYl5fAspD83WEU07wasvBOd7ntpQw153oH8o0zQMZ9uxO5s K38UQ55IsGkMvAvK6hN7JdYIAQV9QR7S/uSm0U3IshHQmp4zTlFyYBinyoPJzcYi7FOk nzoanw8Hvr0mv3X9YVR1OGxrpQThKWsXqIxQFkg14Kee1a5UnTydhR8HaNs/G9JkUCLn TISA== 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=ZMyXicVPK+418sO0IkpvfxexKs54FvpkvATrHGg61HU=; b=RTFtH3YwBe69mbfMIz7SDtXXSCIKNEV54UsBa2LkFyCrUoLpfo+uSFXWrnCcHVenHN M5G8xqwyaUlbQgQ+gn2N2b49BanoiSXd+dEWstJQStCd12qRaHC2eUa6yax+VOsY2Lkx bHRxAYg+ew3rGG0/Vv/6mZlw9NyPvWDqCN3LOu+MSaT2XIszW5LvZ+ouEfk9wXto0ZHH EJIx4+o0WWA+9mT7TcmkGR29lG0YMqiBi8fm65ROB09ZO0gyzj8WzyAqilF3iWw+AiwE j3QPiFB/RslQw02MehG9fRJ35QMWBAWh0yvwACNqrAF82P2mtpSL6744kyFa8RporDM0 yr+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=I+4uzH8d; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k6si13554498pjt.7.2021.10.14.05.12.53; Thu, 14 Oct 2021 05:13:08 -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=@alien8.de header.s=dkim header.b=I+4uzH8d; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230422AbhJNLXv (ORCPT + 99 others); Thu, 14 Oct 2021 07:23:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230241AbhJNLXr (ORCPT ); Thu, 14 Oct 2021 07:23:47 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C0AFC061570; Thu, 14 Oct 2021 04:21:41 -0700 (PDT) Received: from zn.tnic (p200300ec2f0c7200b0e4a365e78c79f0.dip0.t-ipconnect.de [IPv6:2003:ec:2f0c:7200:b0e4:a365:e78c:79f0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id CC2DE1EC0295; Thu, 14 Oct 2021 13:21:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1634210499; 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: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=ZMyXicVPK+418sO0IkpvfxexKs54FvpkvATrHGg61HU=; b=I+4uzH8dHQ5I3LryUUwdKW1lHdViRHIUPN909vfyqKjQHPR8IWALQE/nvwze85e9bp45MS cqSN8H4Qi8pXIB6uOVzlOasS3dTeWcbDtOZ14sYZzhqMFsGfbnkOpP6/jJeruV5CGG4as3 pa8y8z6IbPSQ/msLy5vAbtnRVoU2OHw= Date: Thu, 14 Oct 2021 13:21:38 +0200 From: Borislav Petkov To: Sami Tolvanen Cc: x86@kernel.org, Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH v5 09/15] x86: Use an opaque type for functions not callable from C Message-ID: References: <20211013181658.1020262-1-samitolvanen@google.com> <20211013181658.1020262-10-samitolvanen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20211013181658.1020262-10-samitolvanen@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 13, 2021 at 11:16:52AM -0700, Sami Tolvanen wrote: > The kernel has several assembly functions that are not directly callable > from C. Use an opaque type for these function prototypes to make misuse > harder, and to avoid the need to annotate references to these functions > for Clang's Control-Flow Integrity (CFI). > > Suggested-by: Andy Lutomirski > Suggested-by: Alexander Lobakin > Signed-off-by: Sami Tolvanen > Reviewed-by: Kees Cook > Tested-by: Nick Desaulniers > Tested-by: Sedat Dilek > --- > arch/x86/include/asm/ftrace.h | 2 +- > arch/x86/include/asm/idtentry.h | 10 +++++----- > arch/x86/include/asm/page_64.h | 7 ++++--- > arch/x86/include/asm/paravirt_types.h | 3 ++- > arch/x86/include/asm/processor.h | 2 +- > arch/x86/include/asm/proto.h | 25 +++++++++++++------------ > arch/x86/include/asm/uaccess_64.h | 9 +++------ > arch/x86/kernel/alternative.c | 2 +- > arch/x86/kernel/ftrace.c | 2 +- > arch/x86/kernel/paravirt.c | 4 ++-- > arch/x86/kvm/emulate.c | 4 ++-- > arch/x86/kvm/kvm_emulate.h | 9 ++------- > arch/x86/xen/enlighten_pv.c | 6 +++--- > arch/x86/xen/xen-ops.h | 10 +++++----- > 14 files changed, 45 insertions(+), 50 deletions(-) No matter from which direction I look at it, wrapping some functions which a crazy macro doesn't look good. So what's the plan here? Everytime someone adds an asm function which is not callable from C but forgets to use that magic macro, someone from team CFI will send a patch fixing that? I.e., a whack-a-mole game? If we're going to do that keep-CFI-working game, we might just as well not do the macro but use the C code it evaluates to, so that at least it looks ok-ish: DECLARE_NOT_CALLED_FROM_C(int3_magic); vs extern const u8 int3_magic[]; (Just picked one at random). Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette