Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1007834rwb; Tue, 27 Sep 2022 07:20:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Co0z9ZLgRC4Gq55z1sPmuaenxc1Xy6kmvIanjiOfOmfrPVAueg2jGfKzFsZo5L4xfjLY/ X-Received: by 2002:a17:907:3f90:b0:782:ff26:6e8a with SMTP id hr16-20020a1709073f9000b00782ff266e8amr13758720ejc.192.1664288400523; Tue, 27 Sep 2022 07:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664288400; cv=none; d=google.com; s=arc-20160816; b=D967xNw3H2tRZ1dVpTHOmpB8HDHdIP1ShCLieVfiVru+OXKkwLmrIkHMYnwa5JIhTD 1ItbtBgInUqb5SjLi8NIh73Akier18zm0X54gKqA7T7qEgP3o4vdn+oOuFZmY++scSuu EqbRa5Mlnm0b/SybOcJ6eDYCZIjYuAubQB6ws88w4j8vC4zlOz8agLzIsa1c1DgScksO FFZWaKsye3aXqdkvxqVf1MIGwZVCErR09rnm3khqttLXQkfG0aqmhGBKgAR+2DP4gI5I 7h8wEkkAFg8tPk3ji+eX1yLPnK5MFNbgfr6gEb5aX9Puv/Nsm9hAd346TV2uZDOGp+PU 55Yg== 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=czc19qja57lHhc/tFsaSd0Nh+RAwtk1yS81TRnnv0c8=; b=sjNiIVp71ZmjvlOy3Kp6pfKaZu+S01fbvHL0Y3M6nLQJcPo8EcqI61zNfPlnDVF02r 50LUktjrKSfPqcrczDU0SfCrLmouH2XMgN8gnztAWoef/3zYjhfT/oWi3aDKhyT6AFE2 M/ZInUGZlbQKnL7N6CqK2cuZq/LqrJM6ImJ1zDrQrZ9z77FCYPs7LsG/VLICdLGBDE2i WVY3VhYr81zBxSAN59+kHhploOHsmDO6Id5mOLgB6IAW7Xg4jJCwKuXDp/c87u+jC+Hq c+VePpOM/05AvtKjW6gtMyg80L2ywXPr2vIKjxl3aOeZc+c5qzrMfXIjjACa6XgQDUGY i0xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YN3VOrp1; 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 dp22-20020a170906c15600b00779a69067afsi1555598ejc.830.2022.09.27.07.19.34; Tue, 27 Sep 2022 07:20:00 -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=YN3VOrp1; 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 S232565AbiI0NQe (ORCPT + 99 others); Tue, 27 Sep 2022 09:16:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232542AbiI0NQC (ORCPT ); Tue, 27 Sep 2022 09:16:02 -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 E2F7B1408E; Tue, 27 Sep 2022 06:15:58 -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 A757B61977; Tue, 27 Sep 2022 13:15:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD417C433C1; Tue, 27 Sep 2022 13:15:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664284557; bh=vAAEpjl7gdo2NZ1wWJKQpSd6KTl+oelIC5q3HFgBipw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YN3VOrp1+OULQhIhLpElyhPgoYjbxY+JsYn/DwC7xRRiaQ4i3YhT+r59ayKuKLEHi dHMKv4eplFYHd5tzdRzs2+puUwzqwTU+8ySK8JB9/4933T87DJPRNh2N003h52QaFV 0bD9JEaMivZZSfwnUgqru8/AS8mN9ol4EeLZ4YGasXz7+hwapF4KZpZiYN00+9071j Oungei7XjHc7GiZessEoymIRa/1bEI/Yps2cI9lixJHpEEO2nkL+vZSSzJyMb/eQ1+ hcYHlcYVytbFMhQ63di0mlWSUSyun3+9pFYlhaWyf6ZB9TkA1ghykZuDSn1WI8cKyt HWUPPGnt9r1xQ== 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 , Boqun Feng , Kees Cook Subject: [PATCH v10 02/27] kallsyms: avoid hardcoding buffer size Date: Tue, 27 Sep 2022 15:14:33 +0200 Message-Id: <20220927131518.30000-3-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 From: Boqun Feng This introduces `KSYM_NAME_LEN_BUFFER` in place of the previously hardcoded size of the input buffer. It will also make it easier to update the size in a single place in a later patch. Reviewed-by: Kees Cook Signed-off-by: Boqun Feng Co-developed-by: Miguel Ojeda Signed-off-by: Miguel Ojeda --- scripts/kallsyms.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 8551513f9311..25e2fe5fbcd4 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -27,8 +27,14 @@ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) +#define _stringify_1(x) #x +#define _stringify(x) _stringify_1(x) + #define KSYM_NAME_LEN 128 +/* A substantially bigger size than the current maximum. */ +#define KSYM_NAME_LEN_BUFFER 499 + struct sym_entry { unsigned long long addr; unsigned int len; @@ -198,13 +204,13 @@ static void check_symbol_range(const char *sym, unsigned long long addr, static struct sym_entry *read_symbol(FILE *in) { - char name[500], type; + char name[KSYM_NAME_LEN_BUFFER+1], type; unsigned long long addr; unsigned int len; struct sym_entry *sym; int rc; - rc = fscanf(in, "%llx %c %499s\n", &addr, &type, name); + rc = fscanf(in, "%llx %c %" _stringify(KSYM_NAME_LEN_BUFFER) "s\n", &addr, &type, name); if (rc != 3) { if (rc != EOF && fgets(name, ARRAY_SIZE(name), in) == NULL) fprintf(stderr, "Read error or end of file.\n"); -- 2.37.3