Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4757326iob; Mon, 9 May 2022 00:26:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbheFbQlwMGK82txe/FUwPHTLLcneG8l1qu129AWh0op1AuYn4LeXfGFTCGxdqZfwalpiH X-Received: by 2002:a05:6a00:1784:b0:50d:d8cb:7a4f with SMTP id s4-20020a056a00178400b0050dd8cb7a4fmr14697177pfg.23.1652081182161; Mon, 09 May 2022 00:26:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652081182; cv=none; d=google.com; s=arc-20160816; b=BXZFjvyCYExdoP9y/AgnawEK4Rynuztu8nC7iNqyjIhHTviiVVggQ1/arpXIPHYAY7 7wghMnWOpR29pnVZwX9Uh7IycWC6g56uTyXp2PfUbt49UAlEg6ZkXnkNc/bo7Hf6ZvPd yr18zzyKmxnOkKcD8KKmryvYX4nvPPcdrKzqoL1HltjI00GdfK72ydABIe6U5UJqW469 1+1ktDRApRpvGhYBirNQKyADVgGrUybJhI3yKpgWPlxCMJaEPqV7tRzi+phPEpVCH8zK aDCy5k1vKTjj6cSKlL+Fq6AHNtoSaQ/oX8wZDOMe06ybo4gHmh35s5podqfPPPGDNTVW ICLQ== 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=+SopFE/JC/DkiQNx1UuHI2rTVW1DqIzJKj77dZKXJYY=; b=GrNu9Cwseka+xIdLRO9U7nkvbXfvGFkfW+xl8rs+8/rUvMjdRfVLZq4LUt+fMgiUkT 8Q2QsyU6/yM9KEon+itSUerqCHUCSvhuPozL+uu3SLYTOEWEi3uj7K+V+QN3v9LfjF5H oqu1u0BdDv/UyP7wMLzKneWkqHOQVym7vb+k4H8XoUNeWK/rt7D7W+URvUvsDiVS1pQe nYmF5h1wh/seKn6pnnYZTzBpy8A+Z4/Vn3pd4DyxOTqGn+RABxwBC5ecBuzA95UBwEu2 tHKgDICNYsgchYA672C/VU2CVYRc3MszIJuVD3sUsj4uujhv7PsXIM8UTWMA2ojLwZXl o8cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rmiXhR1O; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s11-20020a17090302cb00b0015cf377e71esi10820162plk.523.2022.05.09.00.26.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 00:26:22 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rmiXhR1O; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A81181B436B; Mon, 9 May 2022 00:24:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445550AbiEGF35 (ORCPT + 99 others); Sat, 7 May 2022 01:29:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383040AbiEGF3q (ORCPT ); Sat, 7 May 2022 01:29:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C301A2AC66; Fri, 6 May 2022 22:26:00 -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 1C0C460765; Sat, 7 May 2022 05:26:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9369C385A6; Sat, 7 May 2022 05:25:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651901159; bh=EfXe1+t/mG9oLzOV4hng373jNmpcc2pJ6ttj78rYzWg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rmiXhR1O+1cwRH8Drtqg0AATaH3ODNQD8b6m9gPcwljjSezKSaVYDJwN7xlEfv4ib mEHUZBAbp/9U4cRmCRPrcus486CvI9q9bjL8KuyXqLHLlcn+wEeanfAH2VhFzYny0W uffB+uUPXbuITM2xz7nMORrZ2giMcbeiKZEuKkHmiyofI0rQ14spvc9KSxhchPXvtK r0I56/f4opZp2KsQt1fGkCLy846paf8EhMvutKG8MibXSinHSpUyFPGRMeHJ/zzQZG MmKX+vihp1iNsv04EnE8P+5Z7nffvxzSog1CNFu79fzGLOr4UmxlMuv/l3CD7FZ+IP yy750cqULFO1w== 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 v6 02/23] kallsyms: support "big" kernel symbols Date: Sat, 7 May 2022 07:24:00 +0200 Message-Id: <20220507052451.12890-3-ojeda@kernel.org> In-Reply-To: <20220507052451.12890-1-ojeda@kernel.org> References: <20220507052451.12890-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 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, and therefore we need to 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), we 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 --- This is a prerequisite patch, independently submitted at: https://lore.kernel.org/lkml/20220506203443.24721-3-ojeda@kernel.org/ 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 79f2eb617a62..e8d2262ef2d2 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -69,12 +69,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 @@ -127,7 +135,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, @@ -141,8 +149,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 82d6508bdf29..7e99799aa7b9 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -480,12 +480,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.35.3