Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1716108ioo; Mon, 23 May 2022 01:18:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1PQeu9MS5C7CRWTy/PRhd2NScrki1vdcnIPmsvmMxjcQqCrEFrD50KnmESKjCV7y4o12h X-Received: by 2002:a17:903:2443:b0:162:223c:c0e9 with SMTP id l3-20020a170903244300b00162223cc0e9mr4502286pls.68.1653293911088; Mon, 23 May 2022 01:18:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653293911; cv=none; d=google.com; s=arc-20160816; b=rOPCBn+uGuzOzyw9Tc9VVRSYSUvzLgUtme5nKzUPGrO5NrLFggziJhcRQLNwRUtO1h 2nT82FsMYw6gaF8TRxhFjJLDRN/FwRBOFw4qTlR4yfBd5SmyReuxGENTuRpRMWqyaBkv Y2VoJNWD5pJza/smDF9C17ZUdSWc7Z5ARYzVbf9LLdqFdnsj6vKmhwgy/xUW7gE3+09B TzQEbgfdutFa58itw5AThxQ3g6/FIDGUd4zIihEVsrfPnnm6dC6ar+nufVjsHq3EtVp6 SVBjuAV+9FjKR5yEAfDjhLD3Nb7Aky5j3X4FD8rbDx5a8RkKAb445tvp6HzCfXEVqbMl Ux7Q== 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=D8PSsUBoH29uhdM0fvBHQmAB7PhZbXoNvqmbXQFgsB4=; b=xu+MHN4BEQbjKVUP+zF5drO3xvo8TC9g5FBmQYtXKGPHgknU1f1kXj4hyzPk7wpOya 1RukIE3dHAdxZAZO5FOR3ZGaDogRtA38e+1bUAPzMKSi7MuftnNYqJSVINa+zY1vRleY V+JhK/IKg6uHNSZFUi4BYzdxkUO0Wig5CuLADzJjxz6W6YeCdSye/pOlIbwraSLbkfzT Gd2FbQ9uL1/M7PCEYy1RSXBXZs1Q1SdkDEHWC6cvUSsrvLa++mOfXG3BrSpebKN9pNhv jgOPDoexoqF12XfHeRM1aRIU1sVPSdg6zlaruv5uTDrzxl+PJqY4P4KSSRNaQFdUcS6z FMSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rfRQy85L; 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=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b22-20020a63d316000000b0039da5aa4ed6si10808770pgg.710.2022.05.23.01.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 01:18:31 -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=@kernel.org header.s=k20201202 header.b=rfRQy85L; 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=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EC9DE3FBFA; Mon, 23 May 2022 00:21:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352165AbiEWCDT (ORCPT + 99 others); Sun, 22 May 2022 22:03:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352156AbiEWCDH (ORCPT ); Sun, 22 May 2022 22:03:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FC0538BCF; Sun, 22 May 2022 19:03:06 -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 8566C60FA0; Mon, 23 May 2022 02:03:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9118DC34113; Mon, 23 May 2022 02:02:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653271385; bh=Rx67V/3ZnuvpkTw7Rx8SDl5zyELYse/bArY7g8AfpSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rfRQy85LXLrx/wrMkNTWFvAjc3ugEyNp4Hi2X4rWw4+xo4pQB8PijF2PscfjNZOKI OM7qBcMOhjAPN6c94rZsF7pIiuy2cjx7bnbC8qCCeEHZL3evivYqDg0X7zSGpPMRTg 60DB3HNfQnFcbk28jlVLvdIYO9EWgCCaRlh5GDWUNkphWEASRkqdN0ZqwM7VtGovzM QIiXXOiEVtaGl719Kau5F459QL63bMaijqZVeqBHEhUKiTAktBQgUJe/fDCCTqxBas v0YyaVbiWC6eRHtdAJitWaVZgk12Llca7qQfTZD4Z8EhWHm/fA9zuQSyOaXnpdCKIh Gld6H6fCucC1w== 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 , Petr Mladek , Alex Gaynor , Wedson Almeida Filho , Gary Guo , Boqun Feng , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Joe Lawrence , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , live-patching@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH v7 03/25] kallsyms: increase maximum kernel symbol length to 512 Date: Mon, 23 May 2022 04:01:16 +0200 Message-Id: <20220523020209.11810-4-ojeda@kernel.org> In-Reply-To: <20220523020209.11810-1-ojeda@kernel.org> References: <20220523020209.11810-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.0 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. For instance, the following code: pub mod my_module { pub struct MyType; pub struct MyGenericType(T); pub trait MyTrait { fn my_method() -> u32; } impl MyTrait for MyGenericType { fn my_method() -> u32 { 42 } } } generates a symbol of length 96 when using the upcoming v0 mangling scheme: _RNvXNtCshGpAVYOtgW1_7example9my_moduleINtB2_13MyGenericTypeNtB2_6MyTypeENtB2_7MyTrait9my_method At the moment, Rust symbols may reach up to 300 in length. Setting 512 as the maximum seems like a reasonable choice to keep some headroom. Reviewed-by: Kees Cook Reviewed-by: Petr Mladek 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 Signed-off-by: Miguel Ojeda --- This is a prerequisite patch, independently submitted at: https://lore.kernel.org/lkml/20220506203443.24721-4-ojeda@kernel.org/ include/linux/kallsyms.h | 2 +- kernel/livepatch/core.c | 4 ++-- scripts/kallsyms.c | 4 ++-- tools/include/linux/kallsyms.h | 2 +- tools/lib/perf/include/perf/event.h | 2 +- tools/lib/symbol/kallsyms.h | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h index ce1bd2fbf23e..e5ad6e31697d 100644 --- a/include/linux/kallsyms.h +++ b/include/linux/kallsyms.h @@ -15,7 +15,7 @@ #include -#define KSYM_NAME_LEN 128 +#define KSYM_NAME_LEN 512 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s %s]") + \ (KSYM_NAME_LEN - 1) + \ 2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + \ diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index bc475e62279d..ec06ce59d728 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -213,7 +213,7 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab, * we use the smallest/strictest upper bound possible (56, based on * the current definition of MODULE_NAME_LEN) to prevent overflows. */ - BUILD_BUG_ON(MODULE_NAME_LEN < 56 || KSYM_NAME_LEN != 128); + BUILD_BUG_ON(MODULE_NAME_LEN < 56 || KSYM_NAME_LEN != 512); relas = (Elf_Rela *) relasec->sh_addr; /* For each rela in this klp relocation section */ @@ -227,7 +227,7 @@ static int klp_resolve_symbols(Elf_Shdr *sechdrs, const char *strtab, /* Format: .klp.sym.sym_objname.sym_name,sympos */ cnt = sscanf(strtab + sym->st_name, - ".klp.sym.%55[^.].%127[^,],%lu", + ".klp.sym.%55[^.].%511[^,],%lu", sym_objname, sym_name, &sympos); if (cnt != 3) { pr_err("symbol %s has an incorrectly formatted name\n", diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 7e99799aa7b9..275044b840dc 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -30,10 +30,10 @@ #define _stringify_1(x) #x #define _stringify(x) _stringify_1(x) -#define KSYM_NAME_LEN 128 +#define KSYM_NAME_LEN 512 /* A substantially bigger size than the current maximum. */ -#define KSYM_NAME_LEN_BUFFER 512 +#define KSYM_NAME_LEN_BUFFER 2048 _Static_assert( KSYM_NAME_LEN_BUFFER == KSYM_NAME_LEN * 4, "Please keep KSYM_NAME_LEN_BUFFER in sync with KSYM_NAME_LEN" diff --git a/tools/include/linux/kallsyms.h b/tools/include/linux/kallsyms.h index efb6c3f5f2a9..5a37ccbec54f 100644 --- a/tools/include/linux/kallsyms.h +++ b/tools/include/linux/kallsyms.h @@ -6,7 +6,7 @@ #include #include -#define KSYM_NAME_LEN 128 +#define KSYM_NAME_LEN 512 struct module; diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/perf/event.h index e7758707cadd..116a80c31675 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -95,7 +95,7 @@ struct perf_record_throttle { }; #ifndef KSYM_NAME_LEN -#define KSYM_NAME_LEN 256 +#define KSYM_NAME_LEN 512 #endif struct perf_record_ksymbol { diff --git a/tools/lib/symbol/kallsyms.h b/tools/lib/symbol/kallsyms.h index 72ab9870454b..542f9b059c3b 100644 --- a/tools/lib/symbol/kallsyms.h +++ b/tools/lib/symbol/kallsyms.h @@ -7,7 +7,7 @@ #include #ifndef KSYM_NAME_LEN -#define KSYM_NAME_LEN 256 +#define KSYM_NAME_LEN 512 #endif static inline u8 kallsyms2elf_binding(char type) -- 2.36.1