Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp968480rwb; Tue, 27 Sep 2022 06:55:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7VRMLcABMF+y0aYY4wNgdDCLbd0FHmxXNiqUbV/TsuHh0kT500z5K1J/bhA20+sNTnxjES X-Received: by 2002:a17:906:5d04:b0:77f:ca9f:33d1 with SMTP id g4-20020a1709065d0400b0077fca9f33d1mr23301644ejt.526.1664286944965; Tue, 27 Sep 2022 06:55:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664286944; cv=none; d=google.com; s=arc-20160816; b=Lb6phnju272IOPxjutj+oviGRkcbXMiPafLIQoxCPBQn+LebWB4vC/8Oai3yMgvHzO eaQGQcJsm02kHtnSPt3fb7VHNmE/NwXLwFsv1xVbk1Vtd+dJd8GwrEOcVf4c+J+l+qoK +vzUChgsrOu5dsarO0tAXRxlC3yB9q5eOZ6IpvM6jSB1y3ea/ICas7jwIwFXrBuwy4Wo 6IgH/XBBp2RH3iLT5EnoF8Ro6BKYHxfTVmZC0yfUMllkwnLNlcaTlq7WezA88D0z8+Z+ UO3igP8rFYdzuvMGvhRFDAEYxBaRBiot7FUoxwxEHxrJ7DZpNufP5VH938f5/FAE7yGD Qfjw== 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=un5nbxfxjv3Gs9LUh5NszAXtRqJpUy14IYAt+Vi2XQI=; b=icNoBsQaQo/Xqnkbz3Xl8dUZ4H2ywUx1q5GHGqt2FQgV/zaeWfJshJ79+yd+QM+gmP 30gmLmE7jH0SLGv8SUctITjxFCL6r8xWpuHsVbmB8aEwEVkIaPJB0xR9UJow/LwyTG7I jDuzpevgmKZE3AXpfi4dRK773ibuB5hnPECnwHmpRKRcqFk9RcZaMRrfTEkE7gATBvJX sz4dWxzQLQKpML68rAR4rQUgjY0GXutXhRJazCcXpnB4aFoi/Xy5s7ry+14WkemtvdWc sEFUjdN/sQgwPWzUnf83IJmG3ruMjNvJv9wNzQ0shWzWXRwttlsF8EFWnx05peKehiHE 0PVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=a1l+RHpD; 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 f11-20020a056402194b00b0043d9ec0eb4fsi1829977edz.16.2022.09.27.06.55.19; Tue, 27 Sep 2022 06:55:44 -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=a1l+RHpD; 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 S232584AbiI0NQj (ORCPT + 99 others); Tue, 27 Sep 2022 09:16:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232576AbiI0NQI (ORCPT ); Tue, 27 Sep 2022 09:16:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA9515A01; Tue, 27 Sep 2022 06:16:05 -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 9ED3261990; Tue, 27 Sep 2022 13:16:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAE48C43470; Tue, 27 Sep 2022 13:16:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664284564; bh=8r0zoTSImOZrA/8nQ8Zb1n00YNiHWkghR7s9YBs524E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a1l+RHpDsq40AJXmFQDAzSjf/c7vCPVCWla9h5TbsJw/dQV3rdbZ6niSsYDWDG+ik GkNrgmcs5Ax/JfxLSsvO551NSZUjxvto4dxJpc25hmwKXR0L6weD8gCe9z98Oy/neZ S7nfTpMajsm4VVNBsTR7XZz4UcXQKZGogtwyV4LSNa+Ch2NpJChg547ckmhAWUfXak mmP2EIYTlkz4u6r3HaNPYQT2n/pkEoHPv8ROiElmdyA9Q0bsecJs3RTMAB8eiy0ZGw uH9cH2jwmEn/CfYC4mRzhNShlcul/pKQD8xfOFyTrvE2jcNiA8wFTeNoD36SnJaUWX nTdgoCbognrzQ== From: Miguel Ojeda To: Linus Torvalds , Greg Kroah-Hartman Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, patches@lists.linux.dev, Jarkko Sakkinen , Miguel Ojeda , Kees Cook , Alex Gaynor , Wedson Almeida Filho , Gary Guo , Boqun Feng , Matthew Wilcox Subject: [PATCH v10 04/27] kallsyms: support "big" kernel symbols Date: Tue, 27 Sep 2022 15:14:35 +0200 Message-Id: <20220927131518.30000-5-ojeda@kernel.org> In-Reply-To: <20220927131518.30000-1-ojeda@kernel.org> References: <20220927131518.30000-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 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 3e7e2c2ad2f7..fc5e26348d25 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -50,12 +50,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 @@ -108,7 +116,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, @@ -122,8 +130,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 411ff5058b51..6502c4001f01 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -487,12 +487,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.3