Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2281772imn; Mon, 1 Aug 2022 18:53:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR5K13zzkbJHtnig7RhMD+IxNlHFsH83mEZAlzy3OkHpAEkfAvvUyGYrCskbMehVGEkYw0C3 X-Received: by 2002:a17:90b:1bc7:b0:1ef:d6f3:b3d0 with SMTP id oa7-20020a17090b1bc700b001efd6f3b3d0mr22622246pjb.4.1659405193436; Mon, 01 Aug 2022 18:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659405193; cv=none; d=google.com; s=arc-20160816; b=RlPUrONy+7EgofuJd4SnkrSoFtWI4r/lXi7aBOd7ujDBo1NecDG3tXywsJcJvb3asm 3m0g856HvJd9LqqzneMLf7n6WPRvut9znBQNQFd/K6YWYwyyhZ6IETFwqkBqvDHyGfox muojT0VwxIHH/Iz9qoknZX7FztY6A4Pk2I0dzHxeKUIBX5uo5eNPbyNHF2Ve4BbsdRj8 /DMkVwm5F1UXMUWFFYyah1XrccXzD1X3SjjrGyW6ALvcB6DTDqlvmFWFIVLQHr7pj25d jtt806F28uPwcYuRD41xoPtdJOemayKx3FdKR4mMIUGWtb26m2WDzvZBmOWeMor9eaEG aH7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Nhii1t/XyNNztYkVw12bOByUgHGve1MKXdIRyWE/gEE=; b=g7WsdQf4PEsBRfabDSv2z283rs5cOLUeEKnIzgTm/Gx9tbOmA8gbpVBXkgRMI/90+x VAA8HgSz2999laudqu/+TAXaBNYCRi05VTLXwIxKCJqS6Z7M25ms2+tHOKeSrAChpKgV XObNRCdoKriLn4WxafvluEVZToC1rkGtDDo+MSMZZRduumErg7hE26FZ1zvB+GSR0mxS LS2y2V5npEPpicyjD+kzKzO76vDknh8MYvKE4DANw2XGw9uczObwJLnBzD1n12FATO1i zxUuKJojRpgDO8grJ1LhkT9QxIxuWpIa1sRha/TG4ejTjJKCp4Ihz3KZ7zdJi49EMZgF VmAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=H7nG71Gw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nu5-20020a17090b1b0500b001f528a40baasi558311pjb.35.2022.08.01.18.52.59; Mon, 01 Aug 2022 18:53:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=H7nG71Gw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235526AbiHBBvz (ORCPT + 99 others); Mon, 1 Aug 2022 21:51:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235499AbiHBBvq (ORCPT ); Mon, 1 Aug 2022 21:51:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8405446D9A; Mon, 1 Aug 2022 18:51:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E192E61043; Tue, 2 Aug 2022 01:51:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 539F2C433C1; Tue, 2 Aug 2022 01:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659405101; bh=Cmqk+Safb+OhqlJuP/ABtXHVHQNIhLizb1za8f0+5uQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H7nG71GwvulAzC0TjP08CXespIHyK6y/A+KZw4C6JmTAeMfN5wTE+PYYTAQhd3LSF m5U9RzBrES2O2IHP9zCrv+idgdHshoY8yz7aSWCQ8JwvsgxmD2OguUYJNny/7d09EJ hflZroEokUwdmSFhmkQhVOzLZWnZB7+V9YXR3NRSokF5fe/1SMsnKJ8O5LKz0ROPqE 75g2aC7CA0TMkE16xAJ9Wa4uIj3qe1bABurVZF5Ke0W8hHmeQySj9FAA3HylO12Fpq BqeT+PbXW7pM9+dfeHCCzIs6xwF+DzyAsh/FxeSfVv1RbIFD9LcXXufsRTKq3srX6P 8mJ7AfFvnbCNQ== From: Miguel Ojeda To: Linus Torvalds , Greg Kroah-Hartman Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Jarkko Sakkinen , Miguel Ojeda , Kees Cook , Alex Gaynor , Wedson Almeida Filho , Gary Guo , Boqun Feng , Matthew Wilcox Subject: [PATCH v8 04/31] kallsyms: support "big" kernel symbols Date: Tue, 2 Aug 2022 03:49:51 +0200 Message-Id: <20220802015052.10452-5-ojeda@kernel.org> In-Reply-To: <20220802015052.10452-1-ojeda@kernel.org> References: <20220802015052.10452-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 Rust symbols can become quite long due to namespacing introduced by modules, types, traits, generics, etc. Increasing to 255 is not enough in some cases, therefore introduce longer lengths to the symbol table. In order to avoid increasing all lengths to 2 bytes (since most of them are small, including many Rust ones), use ULEB128 to keep smaller symbols in 1 byte, with the rest in 2 bytes. Reviewed-by: Kees Cook Co-developed-by: Alex Gaynor Signed-off-by: Alex Gaynor Co-developed-by: Wedson Almeida Filho Signed-off-by: Wedson Almeida Filho Co-developed-by: Gary Guo Signed-off-by: Gary Guo Co-developed-by: Boqun Feng Signed-off-by: Boqun Feng Co-developed-by: Matthew Wilcox Signed-off-by: Matthew Wilcox Signed-off-by: Miguel Ojeda --- kernel/kallsyms.c | 26 ++++++++++++++++++++++---- scripts/kallsyms.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index fbdf8d3279ac..87e2b1638115 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -70,12 +70,20 @@ static unsigned int kallsyms_expand_symbol(unsigned int off, data = &kallsyms_names[off]; len = *data; data++; + off++; + + /* If MSB is 1, it is a "big" symbol, so needs an additional byte. */ + if ((len & 0x80) != 0) { + len = (len & 0x7F) | (*data << 7); + data++; + off++; + } /* * Update the offset to return the offset for the next symbol on * the compressed stream. */ - off += len + 1; + off += len; /* * For every byte on the compressed symbol data, copy the table @@ -128,7 +136,7 @@ static char kallsyms_get_symbol_type(unsigned int off) static unsigned int get_symbol_offset(unsigned long pos) { const u8 *name; - int i; + int i, len; /* * Use the closest marker we have. We have markers every 256 positions, @@ -142,8 +150,18 @@ static unsigned int get_symbol_offset(unsigned long pos) * so we just need to add the len to the current pointer for every * symbol we wish to skip. */ - for (i = 0; i < (pos & 0xFF); i++) - name = name + (*name) + 1; + for (i = 0; i < (pos & 0xFF); i++) { + len = *name; + + /* + * If MSB is 1, it is a "big" symbol, so we need to look into + * the next byte (and skip it, too). + */ + if ((len & 0x80) != 0) + len = ((len & 0x7F) | (name[1] << 7)) + 1; + + name = name + len + 1; + } return name - kallsyms_names; } diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index f543b1c4f99f..9da3b7767e9d 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -481,12 +481,35 @@ static void write_src(void) if ((i & 0xFF) == 0) markers[i >> 8] = off; - printf("\t.byte 0x%02x", table[i]->len); + /* There cannot be any symbol of length zero. */ + if (table[i]->len == 0) { + fprintf(stderr, "kallsyms failure: " + "unexpected zero symbol length\n"); + exit(EXIT_FAILURE); + } + + /* Only lengths that fit in up-to-two-byte ULEB128 are supported. */ + if (table[i]->len > 0x3FFF) { + fprintf(stderr, "kallsyms failure: " + "unexpected huge symbol length\n"); + exit(EXIT_FAILURE); + } + + /* Encode length with ULEB128. */ + if (table[i]->len <= 0x7F) { + /* Most symbols use a single byte for the length. */ + printf("\t.byte 0x%02x", table[i]->len); + off += table[i]->len + 1; + } else { + /* "Big" symbols use two bytes. */ + printf("\t.byte 0x%02x, 0x%02x", + (table[i]->len & 0x7F) | 0x80, + (table[i]->len >> 7) & 0x7F); + off += table[i]->len + 2; + } for (k = 0; k < table[i]->len; k++) printf(", 0x%02x", table[i]->sym[k]); printf("\n"); - - off += table[i]->len + 1; } printf("\n"); -- 2.37.1