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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 724D6C433E9 for ; Thu, 18 Mar 2021 21:42:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C50764F45 for ; Thu, 18 Mar 2021 21:42:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233225AbhCRVmJ (ORCPT ); Thu, 18 Mar 2021 17:42:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233243AbhCRVmF (ORCPT ); Thu, 18 Mar 2021 17:42:05 -0400 Received: from mail-ua1-x934.google.com (mail-ua1-x934.google.com [IPv6:2607:f8b0:4864:20::934]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E62B1C06175F for ; Thu, 18 Mar 2021 14:41:15 -0700 (PDT) Received: by mail-ua1-x934.google.com with SMTP id b10so2395064uap.4 for ; Thu, 18 Mar 2021 14:41:15 -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=S+dtVAUVV+mOR0Fzj0Z90UC8t6lRmPnn/hBpUO6M6Ms=; b=kSXVwz/FZC+WpWQB/aGK9DOPu/ajHGciWvYsOcBoA08P2Lnqtj7wOrf8dZ6auNljTJ 9QlM8ON25d0LHP1BBy4wcnyPzh1vqo7wzYc9ZHKCWsvXk6wRXrz7bnph+co4lGaiBe1U GPk5jrj2K9mTZHyq6QKspCmINSQHwHaH0+xkoKVVNeaQYdYJB9d8VSLDETaN7yEJcnZr 5LJggvUx6k6av5QidARixRz9rJU0dYvgsrxrhEzbzqm4reIeZZEw3EYvPFndTZf4LTgw KwMukHwUAG20BQ614YEt8nG1pyvtKolhObYPjFyygTvMvr+8602BA21r+fs5TigrF0/w i1Vw== 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=S+dtVAUVV+mOR0Fzj0Z90UC8t6lRmPnn/hBpUO6M6Ms=; b=thi8ISC8yznK0KAEmr1a+V9hh7tCGlfwZX+KsdtUyhSXENm7xoEnUZhdBx5D+b/py9 BgTTwzTWBZhoWfPvB8xtbvvrKp4x/7MMk4K3lZXvBnZr9fsbA7PNzn7WqOnZOKqtTA/y SIW2EQMdJh62I+OcaWlwsv4cirBMOIzX/UBH/LNZyLZNn2/P16/aBku9zJ+LdnuuN2D4 1c1zjwdvsM22MZPaJ0yR8ZvSvBwoh0Jql9aw3HYsVOCNL+ye2440PFE+e0ZgarZssu2N Pu8wikAqHzD/5g8KtiMDadNa8fKu4+UdFYz7ulpzinkFw81YwaT/iiNtPAfuLeGk6ns8 N1Uw== X-Gm-Message-State: AOAM531uY/MImeJUjr1d31QJ+wzS+49uqlEwyimdcfx+KkgZzZ9omEG5 u1hMQ7Sk0HTOe9RhRfjNTYR5j3gRPrDScMET5wVLWw== X-Google-Smtp-Source: ABdhPJzCEQzYkNsCoJUS10DgD6+JUA1cBSzuavn2A8KRdSpseJN1j+Mrv0FTmfbfmt5jjm1OJkiESZMfey2NR729Ct8= X-Received: by 2002:ab0:5e9:: with SMTP id e96mr3726573uae.89.1616103674608; Thu, 18 Mar 2021 14:41:14 -0700 (PDT) MIME-Version: 1.0 References: <20210318171111.706303-1-samitolvanen@google.com> <20210318171111.706303-8-samitolvanen@google.com> In-Reply-To: From: Sami Tolvanen Date: Thu, 18 Mar 2021 14:41:03 -0700 Message-ID: Subject: Re: [PATCH v2 07/17] kallsyms: strip ThinLTO hashes from static functions To: Nick Desaulniers Cc: Kees Cook , Nathan Chancellor , Masahiro Yamada , Will Deacon , Jessica Yu , Arnd Bergmann , Tejun Heo , "Paul E. McKenney" , Christoph Hellwig , bpf , linux-hardening@vger.kernel.org, linux-arch , Linux ARM , Linux Kbuild mailing list , PCI , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Thu, Mar 18, 2021 at 12:00 PM Nick Desaulniers wrote: > > On Thu, Mar 18, 2021 at 10:11 AM Sami Tolvanen wrote: > > > > With CONFIG_CFI_CLANG and ThinLTO, Clang appends a hash to the names > > of all static functions not marked __used. This can break userspace > > tools that don't expect the function name to change, so strip out the > > hash from the output. > > > > Suggested-by: Jack Pham > > Signed-off-by: Sami Tolvanen > > Reviewed-by: Kees Cook > > --- > > kernel/kallsyms.c | 54 ++++++++++++++++++++++++++++++++++++++++++----- > > 1 file changed, 49 insertions(+), 5 deletions(-) > > > > diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c > > index 8043a90aa50e..17d3a704bafa 100644 > > --- a/kernel/kallsyms.c > > +++ b/kernel/kallsyms.c > > @@ -161,6 +161,26 @@ static unsigned long kallsyms_sym_address(int idx) > > return kallsyms_relative_base - 1 - kallsyms_offsets[idx]; > > } > > > > +#if defined(CONFIG_CFI_CLANG) && defined(CONFIG_LTO_CLANG_THIN) > > +/* > > + * LLVM appends a hash to static function names when ThinLTO and CFI are > > + * both enabled, which causes confusion and potentially breaks user space > > Might be nice to add an example, something along the lines of: > ie. foo() becomes foo$asfdasdfasdfasdf() Agreed, I'll update the comment in v3. > > > + * tools, so we will strip the postfix from expanded symbol names. > > s/postfix/suffix/ ? Ack. > > > + */ > > +static inline char *cleanup_symbol_name(char *s) > > +{ > > + char *res = NULL; > > + > > + res = strrchr(s, '$'); > > + if (res) > > + *res = '\0'; > > + > > + return res; > > +} > > +#else > > +static inline char *cleanup_symbol_name(char *s) { return NULL; } > > +#endif > > Might be nicer to return a `bool` and have the larger definition > `return res != NULL`). Not sure what a caller would do with `res` if > it was not `NULL`? Sure, I'll change this to bool. Sami