Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4617060iob; Sun, 8 May 2022 19:22:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRXObij9eZi9ypJCx2GjeOihOJEXjnFYcyLs9tGgA4l3QCEpDOrQFKDRDCmVl48m5SETVK X-Received: by 2002:a05:6a00:1582:b0:510:4e67:31d7 with SMTP id u2-20020a056a00158200b005104e6731d7mr13993855pfk.80.1652062921580; Sun, 08 May 2022 19:22:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652062921; cv=none; d=google.com; s=arc-20160816; b=O1UYxKktedroVd2zUbnFN5FjwwGdECtVP6UzbzSeoMJ+EJChegxVvDjvttyu+tr+h1 qWr+L0j5Rd7TYMlxSKKF3QvOILjP/3wnvihGXbBWOXBq52YjhlOsaskerq3HLPbto6Vz EMc9VpT/zAh4Bq2aRvQtKAtheydU7RzTxI5tMZP4RaPbjlD/WGjA4+om+vX7AvJJc7Xa lQpzvuWT2JWZjs6rBBIGZ5i4Er945eQ2ywS0XL7C8hyQBbbR2beenvjn3Q+kxsOM8Xqo DAx9h6T2CRLVNNjiIgfeCr98V72w4KLoSYmneFX96F8k4qLed3O4bMCSvQP7AuuK/hAI EniA== 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=wtpoGHTdD0ZL4EAYtqgz5/gDcanwIR7daQCc0cUTixw=; b=pCW2crXURLX4QiudGcQ/VklmMDqlSHgh5qP5HWLX0Uy/qpkj/lChKRDxElD27PAoz/ VYUnXHU0D0JEHeldXlZT/jHyT2r5X7GvLspxBhlJ7nYspUbzMEwyrOorZxzuT/6cDrU8 UQe+I6Nkc3eLLsfGqfpbNPol135SUKtt7o98bJZGhhL7BS2CkiHcngZkIDy1BoNl7p5R P2RT+4+RYo8p6NhUDguBbO9OAItX0NeDMfT9kjn2uJULbFfk1zldXfUkvMR0EA+NtrZp n/n1A2kO9U7kt8GgYXqb+pZd/dWPjzbAyVjbPdkAKV3algoq0LmutimArDb6/FDWHyFI dX2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EpY6GvAv; 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 pj11-20020a17090b4f4b00b001d987943475si18997242pjb.181.2022.05.08.19.22.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 19:22:01 -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=EpY6GvAv; 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 12B16434AA; Sun, 8 May 2022 19:21:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239720AbiEFUjq (ORCPT + 99 others); Fri, 6 May 2022 16:39:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443262AbiEFUjn (ORCPT ); Fri, 6 May 2022 16:39:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE9AF13F26; Fri, 6 May 2022 13:35:54 -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 ams.source.kernel.org (Postfix) with ESMTPS id 958B4B83993; Fri, 6 May 2022 20:35:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44B5BC385A9; Fri, 6 May 2022 20:35:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651869352; bh=3kPhcKaDX/Q+2C1Refp+7gz4Jh/EZkT9U6Y5DeG8zHM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EpY6GvAv2zKwPBid1bffm6mOZGnHWgr0qQdBgKHGiz7jrAC0hVk7t257LF8qRmj9k s0UAWzMlltrC5KhBgUxvmyzDKJDyqyVrhTn5TO3fx3uwWtmVgUr8csoLXWIgEKzYj1 XYrkJAoxusE0ZWliYA6AADMnxt+1UK+SNA/Ha0a7ro51z/voI7jFmknRzHIgR//fcs uWB+1+19v7OK7MKi056I5XaN1zqB5VWxAXk4jB1lEVA3vSmtn0R3DUCKrZKKPm6amv 2rNEMVrEaDR8vaRFW5/d2s1m3CekHNXG7cwMw4vSdTN42brodD6QfpPSc1rdxRDcOj jh0cvEWB8FeZQ== From: Miguel Ojeda To: Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Andrew Morton , Kefeng Wang , Sergey Senozhatsky , Kees Cook , Miguel Ojeda , Stephen Boyd , Christophe Leroy , Boqun Feng , Alex Gaynor , Gary Guo , Changbin Du , Wedson Almeida Filho , Adrian Hunter , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: rust-for-linux@vger.kernel.org Subject: [PATCH v2 3/3] kallsyms: increase maximum kernel symbol length to 512 Date: Fri, 6 May 2022 22:34:24 +0200 Message-Id: <20220506203443.24721-4-ojeda@kernel.org> In-Reply-To: <20220506203443.24721-1-ojeda@kernel.org> References: <20220506203443.24721-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. 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 --- v2: - Collected Reviewed-bys. 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.35.3