Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp289923pxb; Thu, 12 Aug 2021 16:43:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzzA3NN0NbrgcZbhgJCRB0N86qGox+jMbdPAq2Yj5lIKIatppvC/ixl2gOxdBJgeL2OuGW X-Received: by 2002:a02:90cb:: with SMTP id c11mr6091438jag.53.1628811798938; Thu, 12 Aug 2021 16:43:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628811798; cv=none; d=google.com; s=arc-20160816; b=bfFGlb0Wuv+YaU0acd8iPYTP+lLRVtKwjfEaw+2oXzbBTfNa85ZVw8dcPugch/HNR6 2AumAGYsnhjZ8jW6VboOlX4e5a6SdD6XD19XesJD6TvTbkMfkB863IX1fxVIEiwuCJXA bQWnD1aruK8Y+SHyX3efgres8irqsi9A+WBg+OaGkyuqNu7YlMIX1kOS2Ft4oTuZHNju Y6iM6x9WT4veEbMLVZspBS8M1MJDh5UgEaRvvMRZwtNpwYTCI4TmbdNsCvGECuJTM5lA v15WD55Vcl/pbJKl2hjhS8ZdruF2GuKeonpY0wqYYAmDMocTWxor1r9TukF7kAM7dSP4 iJhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=WAs5yGGrrPs05Rwlue3cPAfgQcKWa7aULg+SByGEVDk=; b=M5iChOdMYshFOIpTiGiQTzTo3BVvlJGxvg0xJkJuULgtaDb4sq+HMy/c8em1mIaH45 ej6bq7r6KwxY+np1VE1vwohyxZjR8tH1H/E6xxPRyVSq4r85WRAzwVroq/wZFMYyE+1d cN8JFFqFbNuE1NXrCccV6l/4SWTOBHvr7pM23Hu1GepGLW5CVk/fd7bICqc6gV3XCVQh E6szJlTBUtZeLf0j4fZMzt3q8mUtbzvGAVOVMiiFl+F6zfiqT1+JQQj0rW4gfO0IHcLT /WcYAIe/vriPIhpc39YtsdyJxX+hqh//i0jdaJfYcLC4o8cGH5Iy3TxtEx5ajrE0Ex7M 16JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=DVRYoece; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z4si3792712ilh.138.2021.08.12.16.43.08; Thu, 12 Aug 2021 16:43:18 -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=@google.com header.s=20161025 header.b=DVRYoece; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237374AbhHLXGE (ORCPT + 99 others); Thu, 12 Aug 2021 19:06:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229919AbhHLXGD (ORCPT ); Thu, 12 Aug 2021 19:06:03 -0400 Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD11CC061756 for ; Thu, 12 Aug 2021 16:05:37 -0700 (PDT) Received: by mail-yb1-xb2f.google.com with SMTP id k65so15109227yba.13 for ; Thu, 12 Aug 2021 16:05:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WAs5yGGrrPs05Rwlue3cPAfgQcKWa7aULg+SByGEVDk=; b=DVRYoece1BGsz/06lnEBAmoea9LRG/ssByvuEa6EbtN/vGaHRqJTi+4VqY8lrjo1/n inq31Tc2qMj6Ii5gIJK0fMljbZR029n7Oyg0oiNnJ/rsj8hjvrWVRtI2kgYbal5DtX6C lI+O5XvkK4QFeYF4fk9QPJ6k7bJ/KfRItEpaOOYykYzD+IrWnQS7chEfbTzpbFGWvTxn U6JAsB5maJ6OouHqJuDLNXX2UKcGjFAMTBpjBQs9nkyKy0kpPX4bZz3Q/rRObFvud1El CkF/NgQAU4fswhKtEyQOYPXKHywpZUqGMgZFoDnl9I1aoMzKfRNL8cjn7F+VAHcKkNma wxwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WAs5yGGrrPs05Rwlue3cPAfgQcKWa7aULg+SByGEVDk=; b=K5vLBY1zK8FJDz00TZpPWFjh7jHxs8mpCJ6qFewUFwkXobwnPVXSPdLbZhpmVXD+P+ 39d4wIymH233tpjqfhf1CJEwPDsTHMqtK89dPgw6A/Ddoo/BjaTZkT2HpWEurHN8C0Cb 5epC8cPIto6EgWRLg8h54r5jJ1z36IePeHAYyMTSi/+oDXXRq2ahcklsX7ScGrFgA70j aD+PZzuO7AMQ3Z8nfAeXS7nqpvnkmiX22qBsqJR8ewFbVkO9+ewBSPhUwv0l54twQ9tX c/q4igtk17mgsYIQJ/9UU57znXhKYpmhdLpGadNUeFRi0PUVZVbw2QsA7XGgT0RIC7mT SHFQ== X-Gm-Message-State: AOAM530YtMFQ36yjYH99cbNPSeFEAjMgMG/BM1YHjf3mzytD71lmtbau l4mWJVXJaR9G3JI3BjHOMTMlXY+eKca5G8Xx3VXotQ== X-Received: by 2002:a25:26c3:: with SMTP id m186mr7496137ybm.293.1628809536796; Thu, 12 Aug 2021 16:05:36 -0700 (PDT) MIME-Version: 1.0 References: <20210805232741.9501-1-treasure4paddy@gmail.com> In-Reply-To: <20210805232741.9501-1-treasure4paddy@gmail.com> From: Sami Tolvanen Date: Thu, 12 Aug 2021 16:05:25 -0700 Message-ID: Subject: Re: [PATCH v4] kallsyms: strip CLANG CFI postfix ".cfi_jt" To: Padmanabha Srinivasaiah , Nick Desaulniers Cc: Jessica Yu , Kees Cook , Nathan Chancellor , Miroslav Benes , Stephen Boyd , "Gustavo A. R. Silva" , Joe Perches , LKML , clang-built-linux Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 5, 2021 at 4:28 PM Padmanabha Srinivasaiah wrote: > > 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; > + } > } I confirmed that LLVM renames these also with full LTO, so the config check can be dropped here. > > /* > @@ -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; Otherwise, the logic looks pretty good to me. Nick, are you planning to resend your earlier patch? Should this be just folded into the next version? Sami