From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9142DC4338F for ; Thu, 5 Aug 2021 23:28:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BE826113B for ; Thu, 5 Aug 2021 23:28:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242347AbhHEX3J (ORCPT ); Thu, 5 Aug 2021 19:29:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236895AbhHEX3H (ORCPT ); Thu, 5 Aug 2021 19:29:07 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30161C0613D5 for ; Thu, 5 Aug 2021 16:28:52 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id o7-20020a05600c5107b0290257f956e02dso7536102wms.1 for ; Thu, 05 Aug 2021 16:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=es0c3UxZ2e0+HJ2C3RZ1dKundYuljCUkYocdB08kQuo=; b=X851qTKkbNn0uyUqdHEwWSWMD0UlYkODROOF3fPzBJ0PjY2idf9i8rHXRd9PPNcLmo H8ptG7hza5Rnw2Dzofc5nNyeGaTjL3ErNphunDCrd0qy2J31+P17wToqIxAb9xmGHAJI M49dcMzETFDQ9Cv8vvPgUMo18QKeRtwhRPEmnZ1+xqjuAak+AbdYyB4i+/kj7f4YFlLz +WhH8HcvjrFjHQjQerhgnnZM2qhnJ2KdjsN8WZcPqQ/m1qQKkvy9gd8Kull8FHKKwt4S afeske3DOgRAx9/LjiXHPEwbFIolEhzQfakhtdFRGn6NlqVwYt3o2vNYxyC+ttWD4Pcf UmEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=es0c3UxZ2e0+HJ2C3RZ1dKundYuljCUkYocdB08kQuo=; b=HXLw5jkHsHYBVGHVPR597fCXgcSrgfUn3jDGhyefaNywcup8XOcs4IeHyeouDD6KEB Dz9UZNJZOXw/KlZsbfgsZjGLObzPMOiKwfegA0LERT/HFg2+bSU+x6IxQS7ZUV4v4O+Z sQ6m69s8eWetJ6HE8dTyCFnY4bHYv4D/fd2htGoqoBlPNbQo4s4c5Nci5pyaJMgfsmCn APxbh6zLI0hK+AMvgDbEyJgAaslcxgfZed1Y35TaXHS5lzF1SVjfFVBpqldNL94Z6+Wn htfJiV1P+TCHI15RgnNT0fCfJAMq2JvkylaLD6n/vu6wJjjnK+kXYzspyMI56tnh/DHZ Hwfg== X-Gm-Message-State: AOAM531ZNfNlFLJm5L3csT6IMCXD+E3eO/mn07FkBb8mcxhkYAyPKHcV f4CV7LONfHBU30H7UQTpo58= X-Google-Smtp-Source: ABdhPJw0jEDrxkw3B2nUsA5wTXAt7+cIgJRZGtrtv+zWFAuSUaEwUkV7HPPMZdyKNbfw9FH67i9lEw== X-Received: by 2002:a1c:5449:: with SMTP id p9mr17467719wmi.101.1628206130686; Thu, 05 Aug 2021 16:28:50 -0700 (PDT) Received: from localhost.localdomain (i59F7252E.versanet.de. [89.247.37.46]) by smtp.gmail.com with ESMTPSA id l4sm7516042wrw.32.2021.08.05.16.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 16:28:49 -0700 (PDT) From: Padmanabha Srinivasaiah To: Jessica Yu , Kees Cook , nathan@kernel.org, ndesaulniers@google.com, samitolvanen@google.com Cc: treasure4paddy@gmail.com, Miroslav Benes , Stephen Boyd , "Gustavo A. R. Silva" , Joe Perches , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: [PATCH v4] kallsyms: strip CLANG CFI postfix ".cfi_jt" Date: Fri, 6 Aug 2021 01:27:38 +0200 Message-Id: <20210805232741.9501-1-treasure4paddy@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Clang CFI adds a postfix ".cfi_jt" to a symbols of extern functions. For e.g. 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 v4: - Remove redundant check; irrespective of LTO type (THIN/FULL), LTO_CLANG will be always enabled. Hence will be used as entry flag to check various postfix patterns. - And prior to stripping postfix ".cfi_jt", added a comment to justify why we are doing so. Change in v3: - Modified commit message to indicate fix is for Clang CFI postfix - Rebased on recent patch from ndesaulniers@google.com. https://lore.kernel.org/lkml/ 20210707181814.365496-1-ndesaulniers@google.com/#t - 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 | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 5cabe4dd3ff4..1b40bcf20fe6 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -174,13 +174,15 @@ 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)) return false; - res = strstr(s, ".llvm."); - if (res) { - *res = '\0'; - return true; + if (IS_ENABLED(CONFIG_LTO_CLANG_THIN)) { + res = strstr(s, ".llvm."); + if (res) { + *res = '\0'; + return true; + } } /* @@ -194,6 +196,17 @@ static bool cleanup_symbol_name(char *s) return false; res = strrchr(s, '$'); + if (!res) { + /* + * In case of non static function symbol , + * the local jump table will have entry as .cfi_jt. + * + * Such expansion breaks some built-in components, + * e.g. syscall tracer. Hence remove postfix ".cfi_jt". + */ + res = strstr(s, ".cfi_jt"); + } + if (res) { *res = '\0'; return true; -- 2.17.1