Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp258836pxt; Wed, 4 Aug 2021 10:21:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNgr3neqw/ozsCu2wWcB490f1UDW++y6ZeNefIQD+0wDuguzNu9DK62bZbDp5Pfje2zMI1 X-Received: by 2002:a92:907:: with SMTP id y7mr145871ilg.260.1628097676223; Wed, 04 Aug 2021 10:21:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628097676; cv=none; d=google.com; s=arc-20160816; b=xLY44XeZ7BUGV1el0zATonDNuYAByGTHffhC8e85AndHRW4+LkOFY7UHSpfeUQEqLn i7VPh6UgEdGppZ4y+hstJ9fJ3mdzac6RSET43wdN9gZFTcD28BLgVlLV4i6lmVrY3xWS icQOX/xZeN8j3H1uhZD21t7njQFi8RZrcNtZq5/4+4MHoBthggoqfGnpF0G0xAJDcsKB nRrDQlDUjmug8n94jcmCcs6vBxXdcUNzYJQVxt5CgCFKHAZm8FPXFj/4414dvTfqoSAM ZWewHyO6b2LSRIWICSu/dj8FL5Vkj3kiSG6gvq/DHDiMfA+QFgloCDl0t7V84fHTSPXv Tbgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=5Qo9QHnK3biCSTh8bimTB9CTycQIbbuDw05aJ2yEchU=; b=AxUP0a7H0WQVj7mMH+TQQqX5P2bdkYtMC1QhWiMk3Ho4aWD9EnFMT4bndoD6q2nons edFtKpHLNOyv/9uO5aulB9gVG4DeWBN0AexzKSa5avy1NG3yHZg+yPBj8sltxRSbb2d2 Ul8+3PPG1++Tx+qPvCKmhouXpLfZ/v3mGg4iI6LEYwlJqG9Ir72Unj/zXcBbSpzsl8o8 ZP03izjI62gBvIEGgcSGBhSU/z/eapaJXp3j7XG/XssLE9JIfkvZ92aDTDLYEjigfqRD EL6YObn5jjaaSv7MKdc2NBfOhku0INVUarVWmtmvj6yCEUtH3UrqT/31XN9W0AOeq0kF q9jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Zi+J54b6; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s13si3236591ilp.102.2021.08.04.10.21.04; Wed, 04 Aug 2021 10:21:16 -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=@gmail.com header.s=20161025 header.b=Zi+J54b6; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240027AbhHDRSO (ORCPT + 99 others); Wed, 4 Aug 2021 13:18:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239891AbhHDRSK (ORCPT ); Wed, 4 Aug 2021 13:18:10 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C775C061798 for ; Wed, 4 Aug 2021 10:17:52 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id x11so4793652ejj.8 for ; Wed, 04 Aug 2021 10:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=5Qo9QHnK3biCSTh8bimTB9CTycQIbbuDw05aJ2yEchU=; b=Zi+J54b61qNJKO3sahowtmeG1rTakq9aSxnXnCOwW070cpE1Pi8O7iJTIKbyDWcmQS sMH/JvSW70s1k9HkyKIlqXgPYwcVJj7AKqOvwCmANruYgldJ7T1fAjcjhEJWvppsF9FB BAZSz9Fshv0+3WUlD8WQQD/0ZvmtjZbnMRwPAdfCg74qDyc9Op+ar0UqkjR8mB96cSid zPH37kw886pPvcO4SBRVfDPLw/nfAq/fgRCg3X1edkutMseFEI5ZIBF7ldYfL0fnItkI pKizeD/j32K7p0W0rdspqfk/hTJFy+10yvoGdmGyRcKVwKDrSgPEZzYpO8biIJHSMb0m 1aYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=5Qo9QHnK3biCSTh8bimTB9CTycQIbbuDw05aJ2yEchU=; b=pqoPmVGLnNQiPILPAICfJVCYz3/C6zHGhmKCta1ppoTP9sHdwGe9YuyQV3myGhb7e0 5p1YZS2uVEuYkXSKz0iN1ipx6D08M/aYzErDZXh6iWnBPidYWfDSJ17R6IQRd1Mkz6Nz u7M5fM/OTdQjymAXxq2tDBNwIfacBwzhPUNjsXttsQLfY3W5673R1q1kgCf9+FHUwCmP cZSzI2MJHhPhI6/9Zms5MjkBwQBWlcBwE7FC/ONZmuO06v3ozgcJgxY3D7LAek5UMrXK OiW/tq2fTx+cGGzBtHAREEgaDdqc+oXv2E7K41aGzXP4WU9U6d0mwM36lTYqU9DVW5lQ UEOg== X-Gm-Message-State: AOAM531KwaKbjYwjLYE0PhhtzWD+/tfVjaTVZYhpuKNJzPVepKZCO9e9 wsMcOqyBcUuiS8jUogplqkE= X-Received: by 2002:a17:906:d153:: with SMTP id br19mr302615ejb.166.1628097470629; Wed, 04 Aug 2021 10:17:50 -0700 (PDT) Received: from pswork ([62.96.250.75]) by smtp.gmail.com with ESMTPSA id u4sm835516eje.81.2021.08.04.10.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Aug 2021 10:17:50 -0700 (PDT) Date: Wed, 4 Aug 2021 19:17:49 +0200 From: Padmanabha Srinivasaiah To: Sami Tolvanen Cc: Jessica Yu , Kees Cook , Nathan Chancellor , Nick Desaulniers , Miroslav Benes , Stephen Boyd , "Gustavo A. R. Silva" , Joe Perches , LKML , clang-built-linux Subject: Re: [PATCH v3] kallsyms: strip CLANG CFI postfix ".cfi_jt" Message-ID: <20210804171749.GA5563@pswork> References: <20210729205317.25685-1-treasure4paddy@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 03, 2021 at 09:28:23AM -0700, Sami Tolvanen wrote: > Hi, > > On Thu, Jul 29, 2021 at 1:54 PM Padmanabha Srinivasaiah > wrote: > > > > Clang CFI adds a postfix ".cfi_jt" to a symbols of extern functions. > > For example this breaks syscall tracer that doesn't expect such postfix, > > so strip out the postfix from the expanded symbol. > > > > Signed-off-by: Padmanabha Srinivasaiah > > --- > > > > Change in v3: > > - Modified commit message to indicate fix is for Clang CFI postfix > > - Rebased on recent patch from ndesaulniers@google.com. > > - Fix is enabled even for CONFIG_LTO_CLANG > > > > Change in v2: > > - Use existing routine in kallsyms to strip postfix ".cfi_jt" from > > extern function name. > > - Modified the commit message accordingly > > > > kernel/kallsyms.c | 21 +++++++++++++++------ > > 1 file changed, 15 insertions(+), 6 deletions(-) > > > > diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c > > index 5cabe4dd3ff4..67d015854cbd 100644 > > --- a/kernel/kallsyms.c > > +++ b/kernel/kallsyms.c > > @@ -174,7 +174,8 @@ static bool cleanup_symbol_name(char *s) > > * foo.llvm.974640843467629774. This can break hooking of static > > * functions with kprobes. > > */ > > - if (!IS_ENABLED(CONFIG_LTO_CLANG_THIN)) > > + if (!(IS_ENABLED(CONFIG_LTO_CLANG) || > > + IS_ENABLED(CONFIG_LTO_CLANG_THIN))) > > This is redundant. LTO_CLANG is selected for both LTO modes, so > there's no need to also check for LTO_CLANG_THIN here. > As my setup is little endian, couldn't verify for below condition and was the reason to add such check. Sure will remove it. " select ARCH_SUPPORTS_LTO_CLANG if CPU_LITTLE_ENDIAN select ARCH_SUPPORTS_LTO_CLANG_THIN" > > return false; > > > > res = strstr(s, ".llvm."); > > However, we should probably check for ".llvm." only with LTO_CLANG_THIN. > Thank you for the input, will regenrate the patch with suggested check > > @@ -184,16 +185,24 @@ static bool cleanup_symbol_name(char *s) > > } > > > > /* > > - * LLVM appends a hash to static function names when ThinLTO and CFI > > - * are both enabled, i.e. foo() becomes > > - * foo$707af9a22804d33c81801f27dcfe489b. This causes confusion and > > - * potentially breaks user space tools, so we strip the suffix from > > - * expanded symbol names. > > + * LLVM appends a hash to static function names when both > > + * (Thin/FULL) LTO and CFI are enabled, i.e. foo() becomes > > + * foo$707af9a22804d33c81801f27dcfe489b. > > That's not quite right, the hash is only appended with ThinLTO. I > would leave this comment untouched. > sure, will revert it. > > + * > > + * In case of non static function symbol , > > + * the local jump table will have entry as .cfi_jt. > > + * > > + * This causes confusion and potentially breaks > > + * user space tools and some built-in components. > > + * So we strip the suffix from expanded symbol names. > > */ > > if (!IS_ENABLED(CONFIG_CFI_CLANG)) > > return false; > > > > res = strrchr(s, '$'); > > + if (!res) > > + res = strstr(s, ".cfi_jt"); > > And add a comment about stripping .cfi_jt from jump table symbols > before this part. > sure, will add it > > + > > if (res) { > > *res = '\0'; > > return true; > > -- > > 2.17.1 > > > > Sami