Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4764114iob; Mon, 9 May 2022 00:39:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5/VWWs7q3vAjg/+rfwk/y/4tbsCcVai9ZtkNYmYjxUEjILHeBmuHk7550UX04Rm5Ady3r X-Received: by 2002:a05:6a00:2444:b0:4fd:db81:cbdd with SMTP id d4-20020a056a00244400b004fddb81cbddmr14549199pfj.32.1652081953313; Mon, 09 May 2022 00:39:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652081953; cv=none; d=google.com; s=arc-20160816; b=Ex5Xz3/1TQsPkF2tfickVFpkYNhJFDMf9u2l0odyGA9/iOVQFeG3nMpVaQFCEKrt4R Zl+FVzF+IdBjD6UzLL6vmkG01Q+1csOa0G8rFj9/8bFQqscbUx4CK/i+5PNlKLhFNbsN pYolupFzFNUDrt6SWt2Xn5qWzDAI1LYH4Qf82vBP1cnFiziZSzNPs7kjGcHIWwoxviRB fVHSY4mnDA8F96LerOtxd2hWT3cC1hWDXWEfROq5cGDSGbu7EsTPFveYNcD87CER7vXc Hs+tBUzvfMx7rUPHwjSs76EDTa0+IB52JHVxzytmRuZe242R3KbG+zzMv8y0ZKAtdOKj iSKg== 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=uvsxQRT5QULmzgUEdwEhkB0GXePMIpAFY0G7N07vldg=; b=HYe8T354zhMlI70Rwnu58BH8oo1rMXxTC8FjQObAEBQKOTjBnCGqzh33N0f2Leid7y uViagTpi8TTYMBJuDPEbsEdarCVKd2BlLm7jK3qB2A+b/hGUvfjhdEhMwxOc74dQCHE4 l2r0hJViN7TztrSo0QZ470eCzHojBcIBTJqNswHL/qZn65PZeFvEcIsdSv9/k21hsREW I+ToriJ7GlH9zHh5ttKzqloT+/n9Dl6wrtVRpgtObMOiwlmED1mN/azdsHGuOitjlctw JT1hrJE5Mm05ossBsEpqy1ivEt2kaLY/9lgw5kqH3IkdzyYWtWmhO89mVsQTABSwgH2D qTMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uQ8vQAto; 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 d7-20020a056a00244700b0050ad0f19e40si13920356pfj.53.2022.05.09.00.39.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 00:39:13 -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=uQ8vQAto; 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 E40DB1C06DE; Mon, 9 May 2022 00:34:54 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383208AbiEGF3q (ORCPT + 99 others); Sat, 7 May 2022 01:29:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382889AbiEGF3o (ORCPT ); Sat, 7 May 2022 01:29:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9341144A02; Fri, 6 May 2022 22:25:56 -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 89A4260765; Sat, 7 May 2022 05:25:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43419C385AE; Sat, 7 May 2022 05:25:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651901156; bh=6BK6vCkagIsVFppz/JVipf1RmADhTrfcI9FSaf5gg8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uQ8vQAtoXbOMdKZs/Hb+kb+e+YEdLkz/KofQ0W2Nd8OoTZB+8YeP7qsPTPtQrB5sD /ONF6g0iQiKKER3hd+X99A/WY68QdiZ7mvmTTMQte+jQK8pnqya3qO2rE6gva/7J9+ voktOZD/xtROG33LLMoBPHHP5/CoG6aykhPwk39aM9qA5l/o1rCEBu82UzodbsOOWc eQMUSOfKscygnFpIO/XdVdQ6wZ+AiyQ+SGXwD3d4jAWcHCZMUV4/SCcd46DmRu40K4 1vZGDChQjcn7DVBnxTMqaWbzkYoSZlr95VwUdcu8cZCXKzKVDuh4yLgdgj38cHjuMI MIRVlBTfuIelQ== 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 , Boqun Feng , Kees Cook Subject: [PATCH v6 01/23] kallsyms: avoid hardcoding the buffer size Date: Sat, 7 May 2022 07:23:59 +0200 Message-Id: <20220507052451.12890-2-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 From: Boqun Feng This makes it easier to update the size later on. Furthermore, a static assert is added to ensure both are updated when that happens. The relationship used is one that keeps the new size (512+1) close to the original buffer size (500). Reviewed-by: Kees Cook Signed-off-by: Boqun Feng Co-developed-by: Miguel Ojeda Signed-off-by: Miguel Ojeda --- This is a prerequisite patch, independently submitted at: https://lore.kernel.org/lkml/20220506203443.24721-2-ojeda@kernel.org/ scripts/kallsyms.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 8caabddf817c..82d6508bdf29 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -27,8 +27,18 @@ #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 512 +_Static_assert( + KSYM_NAME_LEN_BUFFER == KSYM_NAME_LEN * 4, + "Please keep KSYM_NAME_LEN_BUFFER in sync with KSYM_NAME_LEN" +); + struct sym_entry { unsigned long long addr; unsigned int len; @@ -197,15 +207,15 @@ 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, 500, in) == NULL) + if (rc != EOF && fgets(name, sizeof(name), in) == NULL) fprintf(stderr, "Read error or end of file.\n"); return NULL; } -- 2.35.3