Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp90544rdb; Tue, 19 Dec 2023 10:08:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3eAUZAEThs5epTRDn44wcwcZfx40863lLIFJCfgEjywCd3gyKeG/4GY9WVuGhJuBIwdw7 X-Received: by 2002:a05:6512:31d2:b0:50b:f0a2:25dd with SMTP id j18-20020a05651231d200b0050bf0a225ddmr10640235lfe.3.1703009308545; Tue, 19 Dec 2023 10:08:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703009308; cv=none; d=google.com; s=arc-20160816; b=pBBlNTEjMQyBuOwvgszlwtZGdzlBuDEKS/Oj0EMURujPB74Bsy57+w9vzhKb0x46rd I9mYHRtfbbny4s4wZdrzxjQcH3yt+lkbLExFTaFQbQNTULbYmWbJSFE1U1Miqt+SNk0O 8ffUmed7jEmqFtCR0BUbY6E2/Q43JMPRsi344bOICiIAjybdD/vkiXD+9PbfKqTwYNWf UrcSQNHMpcDLVQo2m5uHp7gzCOFCyhgiOMbNdx3PNIHai4aHAEnI/sDQE4kG1RtXisdv bWZupjmKUZIEITR1fCDofN5Jw39LtJwBn9Cy8s7+pFXKSXmtWrXUTou5OyIbubjA+/lY Ugmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=rTD6xzBqwx9cf0sR+icSknwqdpHbRxYA35sj8sLWN/I=; fh=RfEQeWezrqmWNVY72zZGcyD76OqorrXLRZu0zrG/9sE=; b=im3P/c6H9qoTg/kjbckxLPa8U9xQBoOtKRjvSXp6dnFOUl1gU0FTvlJJP7hX1s9anZ 3FlUe/SUhDM/F8kUqHf9TvPZHYh8ON0ik5KGSGnqGUYzyUkROEgqNqZR/7CcBT/5gIsK XvZroYL5m0Pi/SJnh6snO34HzVlG9guAlzETE41U0hAbuPG9QE6GMCCJKJ3vb3MRZvd9 03TwByIcIGuc0tTxoboicRPqfbzNxFFBfiBUnLjRHHybS7O/DYU6tvpGbakTSzpVEuap U0mTIDGyT68Sa+XZz8KdGvb5ZeGdSIUsxTIwdMwp7dvhrV5EEKyOdGrqyBT03NA+8Hi6 0KTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b="BMf+Ql/c"; spf=pass (google.com: domain of linux-kernel+bounces-5751-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5751-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cb5-20020a170906a44500b00a235d296f10si1694567ejb.490.2023.12.19.10.08.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 10:08:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5751-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b="BMf+Ql/c"; spf=pass (google.com: domain of linux-kernel+bounces-5751-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5751-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 380FF1F29A47 for ; Tue, 19 Dec 2023 17:59:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3EBCB38F87; Tue, 19 Dec 2023 17:55:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="BMf+Ql/c" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.smtpout.orange.fr (smtp-20.smtpout.orange.fr [80.12.242.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAB7D37D22; Tue, 19 Dec 2023 17:55:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Received: from [192.168.1.18] ([92.140.202.140]) by smtp.orange.fr with ESMTPA id FeJbrhqYW2UQhFeJbrRRBY; Tue, 19 Dec 2023 18:55:40 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1703008540; bh=rTD6xzBqwx9cf0sR+icSknwqdpHbRxYA35sj8sLWN/I=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=BMf+Ql/cyX4tDJ4LZbGkJap+tCfXfDvEvc3RQ8uz68KTvJnH9lCg3hsyFeRlGmwSQ JVgHkEMt0lbUA1jo5hf1NUZRVQD2f0iBAJKXas9sXQCNUqJKDCfs6h7dIPgyiqmJz/ Wwn2eBNgv79fs7/nDxpmWwo4gsVELvSp2RE+Y13c23tEtEajRa5t2iM1I3p6srdSF0 0L38m4w3j2lip87ReGvLEAWdCHcYZ5CMq4SnHRlS7eYFZdPv8ABhzh2/5l/99m6YFG h7/7mwn36onmPz5MrlIn+jCKpCvqOZkT/BIFk8Si+l7Z7H56g4thbXjZaORjHTG0k3 sk9yGnX+zm4eg== X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 19 Dec 2023 18:55:40 +0100 X-ME-IP: 92.140.202.140 Message-ID: <6eccd268-9042-4887-9131-b5932c72b6c4@wanadoo.fr> Date: Tue, 19 Dec 2023 18:55:35 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] x86/callthunks: Fix some potential string truncation in callthunks_debugfs_init() To: Sohil Mehta , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org References: <8c2b24df3c077e55b2a4d91a7ffd08fa48e28d0a.1702803679.git.christophe.jaillet@wanadoo.fr> <4d4e488d-45d6-4496-b165-c349c67d4f11@intel.com> Content-Language: fr, en-US From: Christophe JAILLET In-Reply-To: <4d4e488d-45d6-4496-b165-c349c67d4f11@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 19/12/2023 à 12:02, Sohil Mehta a écrit : > On 12/17/2023 2:31 PM, Christophe JAILLET wrote: >> When compiled with W=1, we get: >> arch/x86/kernel/callthunks.c: In function ‘callthunks_debugfs_init’: >> arch/x86/kernel/callthunks.c:394:35: error: ‘%lu’ directive writing between 1 and 10 bytes into a region of size 7 [-Werror=format-overflow=] >> 394 | sprintf(name, "cpu%lu", cpu); >> | ^~~ >> arch/x86/kernel/callthunks.c:394:31: note: directive argument in the range [0, 4294967294] >> 394 | sprintf(name, "cpu%lu", cpu); >> | ^~~~~~~~ >> arch/x86/kernel/callthunks.c:394:17: note: ‘sprintf’ output between 5 and 14 bytes into a destination of size 10 >> 394 | sprintf(name, "cpu%lu", cpu); >> | >> >> So, give some more space to 'name' to silence the warning. > > It might be useful to specify that "some more space" hasn't been > arbitrarily decided. It took me a few minutes to figure that out. > > With the max cpu number being 4294967294 with 10 characters, a total of > 14 chars would be enough to print "cpu%lu". From my POV, it is what the gcc warning already says, but I (or anyone else) can tweak the wording to make it more explicit. Let me know if you want a v2. CJ > > >> (and fix the issue should a lucky one have a config with so many >> CPU!) >> Signed-off-by: Christophe JAILLET >> --- >> arch/x86/kernel/callthunks.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> > > Apart from that, please feel free to add: > > Reviewed-by: Sohil Mehta > >> diff --git a/arch/x86/kernel/callthunks.c b/arch/x86/kernel/callthunks.c >> index cf7e5be1b844..26182a7d12b3 100644 >> --- a/arch/x86/kernel/callthunks.c >> +++ b/arch/x86/kernel/callthunks.c >> @@ -388,7 +388,7 @@ static int __init callthunks_debugfs_init(void) >> dir = debugfs_create_dir("callthunks", NULL); >> for_each_possible_cpu(cpu) { >> void *arg = (void *)cpu; >> - char name [10]; >> + char name[14]; >> >> sprintf(name, "cpu%lu", cpu); >> debugfs_create_file(name, 0644, dir, arg, &dfs_ops); > > >