Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4901273iob; Mon, 9 May 2022 04:27:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjid/lflrC0mGIQ+gxuOsagPseEz5HNDvdAz2hU3DiWurM7422Y1R5a11VQzGQW/5frpwX X-Received: by 2002:a05:6a00:140e:b0:4e1:c81a:625c with SMTP id l14-20020a056a00140e00b004e1c81a625cmr15671864pfu.39.1652095653441; Mon, 09 May 2022 04:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652095653; cv=none; d=google.com; s=arc-20160816; b=dW3LSlgbZf8/+Iy2/BSkqR/Qb5KRJgC5Q23lKkKY0MAIF/rfeBh9Y2xc7YkEqYf2LP 0r3J0N0EwRyg5yWrl+TBCzhgWEG/rzJ2Mkxscu7hTlpGbmv0OJY0gJuT9JCP2ggwwzPu 5UysYhjb25TTbTTPN5oYxtcTnohWyMEVXKhxW3QKi1CLdboIthxvsEnsafTTQ4pSSNNC sZF1HvO76QTd+OKDHpFcg088WB5b/s9TBKzNWq5yWVqAFF77ZUQoViJTEZghY0bnmd33 ezaR+CsEHRvc9aZXm8aJsuTd5v6iPAUgzv/+b8QuildgMjk6Hg7DvdXFXqcYw/v1WmnI cKMA== 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=QP971CEm/gqaPtjbPgJbB2cVshPX7zV35zNPNUUytEE=; b=hTE2yyew1guuYWVbA8XJkSxLJAq/N9uCeT34g3WnBmZGKVlo80sr/vZXEC9fKf4Vko nD0aAwIEbH9MS1YRuu33cDoyhYQShcRZ/k8CC6jd2MrUPeC54NKQ63ncL18MN48Jz0fE BG1S05gyIQAhHC1U/DnbryKcL1bsA7H9oUidwxhJRgQgyimYaPjF7xxikEalQdIAwkVR jmoBZlJWRIIufzUWdDvmFt/ZSnUieLTAm7fxQ7wZRTAJRPOj4aZUn9awe3knN4ST2S0C 4unnDTG6HRnRWUpYKNBHf9MoVdUPv1DXBQZePTVkeSrDw/uH1exJri3WvzzgIyqjr6J9 ZOsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Cd11zdVY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c2-20020a056a00248200b00510625a3267si15925986pfv.118.2022.05.09.04.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 04:27:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Cd11zdVY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B5F4C224A6D; Mon, 9 May 2022 03:35:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1446072AbiEGIgG (ORCPT + 99 others); Sat, 7 May 2022 04:36:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388495AbiEGIgD (ORCPT ); Sat, 7 May 2022 04:36:03 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92BFA3FBCA for ; Sat, 7 May 2022 01:32:17 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id e5so7951828pgc.5 for ; Sat, 07 May 2022 01:32:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=QP971CEm/gqaPtjbPgJbB2cVshPX7zV35zNPNUUytEE=; b=Cd11zdVYVrW4dHXPGz+5a3aU6WkljkI+c1wPzYxUlM4CH8OJT8tvX85ZYBB1ysr88Y 5826ZNws6+BrvXVbp7n4/5l4d6ubGoTSJ0/OQILoJEakkrTZzqxHZ+lBTHpnFL7pR8jW CeWv0BYJ43pVB3DbVsW9NhsyF1HfVgotcsQKc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QP971CEm/gqaPtjbPgJbB2cVshPX7zV35zNPNUUytEE=; b=VDKogZiSKMIgBcCOQGwsVN+Y++9iSSLvM0aY3qXzuD4MRa0dpXYGjzhFdf3EzZr81E cremC8NlsB/hY8T4M0L6B32ulcC3Y2XgwVJa9P4Es9C7jVcNAdX5HJJJ+ET3FJC4UAoU UB+QBS9Onunu3ORPcr/8S1Kcaug6IAijytpPH911uAE/pxa1fPZm5k3hd6yI6eCjjg4s sL73dfgxBXeeo4eD2nPsbrouA1QuEW8S0BH8ZIcPfrVHyqlVqEodQFjQpMayTiipYjtF uFHPFB5dmx07fTdEyxgbGnyCikCXLhRSqXm0s9s9ukIJwrTbhNGl0ZtxcoKxnc/vG915 gjgw== X-Gm-Message-State: AOAM530mO5MAqfMvW5dTTCiLJdjVZV2i+0Xcku5fW7POMZfbjwbEMhmu TRDZmJ528oLQaVXz57ktvEQdFw== X-Received: by 2002:a63:5516:0:b0:3c6:53e9:30b3 with SMTP id j22-20020a635516000000b003c653e930b3mr4513369pgb.273.1651912337096; Sat, 07 May 2022 01:32:17 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id bg7-20020a1709028e8700b0015e8d4eb295sm3084422plb.223.2022.05.07.01.32.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 May 2022 01:32:16 -0700 (PDT) Date: Sat, 7 May 2022 01:32:15 -0700 From: Kees Cook To: Miguel Ojeda Cc: Linus Torvalds , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Jarkko Sakkinen , Alex Gaynor , Wedson Almeida Filho Subject: Re: [PATCH v6 17/23] scripts: decode_stacktrace: demangle Rust symbols Message-ID: <202205070122.B240F989@keescook> References: <20220507052451.12890-1-ojeda@kernel.org> <20220507052451.12890-18-ojeda@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220507052451.12890-18-ojeda@kernel.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 07, 2022 at 07:24:15AM +0200, Miguel Ojeda wrote: > Recent versions of both Binutils (`c++filt`) and LLVM (`llvm-cxxfilt`) > provide Rust v0 mangling support. > > Co-developed-by: Alex Gaynor > Signed-off-by: Alex Gaynor > Co-developed-by: Wedson Almeida Filho > Signed-off-by: Wedson Almeida Filho > Signed-off-by: Miguel Ojeda > --- > I would like to use this patch for discussing the demangling topic. > > The following discusses the different approaches we could take. > > > # Leave demangling to userspace > > This is the easiest and less invasive approach, the one implemented > by this patch. > > The `decode_stacktrace.sh` script is already needed to map > the offsets to the source code. Therefore, we could also take > the chance to demangle the symbols here. > > With this approach, we do not need to introduce any change in the > `vsprintf` machinery and we minimize the risk of breaking user tools. > > Note that, if we take this approach, it is likely we want to ask > for a minimum version of either of the tools (since there may be > users of the script that do not have recent enough toolchains). For the first in-tree Rust support, I think this is entirely the right approach. > # Demangling in kernelspace on-the-fly Please no. :) I don't see a benefit compared to doing it at compile-time. > Furthermore, this approach (and the ones below) likely require adding > a new `%p` specifier (or a new modifier to existing ones) if we do > not want to affect non-backtrace uses of the `B`/`S` ones. Also, > it is unclear whether we should write the demangled versions in an > extra, different line or replace the real symbol -- we could be > breaking user tools relying on parsing backtraces (e.g. our own > `decode_stacktrace.sh`). For instance, they could be relying on > having real symbols there, or may break due to e.g. spaces. I may need some examples here for what you're thinking will cause problems. Why a new specifier? Won't demangling just give us text? Is the concern about breaking backtrace parsers that only understand C symbols? > # Demangling at compile-time > > This implies having kallsyms demangle all the Rust symbols. > > The size of this data is around the same order of magnitude of the > non-demangled ones. However, this is notably more than the demangling > code (see previous point), e.g. 120 KiB (uncompressed) in a > small kernel. It seems all of that would be in the build-time helper, not the kernel image, though, so that seems better than run-time demangling. > # Demangling at compile-time and substituting symbols by hashes Nah; this is even less readable than the mangled symbols. :) I don't think the symbol length should be a concern. (Though maybe there are some crash parsers that we can buffer overflow!) > scripts/decode_stacktrace.sh | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) Reviewed-by: Kees Cook -- Kees Cook