From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.zytor.com (terminus.zytor.com [198.137.202.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A53782836E for ; Fri, 13 Feb 2026 20:16:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771013768; cv=none; b=NV7KiWxUqTQzdR8JNtyq16ZfDg73JzKHKxd3pH6fC6qnMFK6/bd6vkHATENfOFbZrq0zuvtgSSKNzVWvV90XMZk+KywOWZ0uxouUC8b28nB7yWNxfviSUEeI3EX5CeaT7v4csq0NANkpC4HJIwOeuYk61Sv0Olsh1FOQC5DduLw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771013768; c=relaxed/simple; bh=D/vQfMmpOk+oM7sjN94Vmj6cgJDNTX8tK9JLGjaOic4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=YTgoAMt4//EourA8xiv8irHswG3BD9eQ0iffp56+8Y+0lDCmseDWj1Bsv3q3uD1sWunqMxSGXE2EoBO/UR3zjPmeTsNlgl26/s0LYjTMjdM1A9H1WkSkM3Jf7xlEBSFUKoiwPFCdPAlOzfzKSIUDTnDVXBbjHgRMPeop2FmiOa8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com; spf=pass smtp.mailfrom=zytor.com; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b=Q8JknV61; arc=none smtp.client-ip=198.137.202.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zytor.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b="Q8JknV61" Received: from [IPV6:2607:fb90:3709:ce04:bf4c:86df:148a:f3f5] ([IPv6:2607:fb90:3709:ce04:bf4c:86df:148a:f3f5]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 61DKFP30951681 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Fri, 13 Feb 2026 12:15:29 -0800 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 61DKFP30951681 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2026012301; t=1771013732; bh=4LtGXBWMDDYrbXtDdNAKFY3eqPdYZY3ZLOKT0HuKQoU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Q8JknV61IF2RoGXMDYRSHZuGC+D/QZh9p945t6QgCZmAMv40YaDXqK/f80C8e7ECF TRR2lIcdVEPSgXNRwpnAxQkrwkiGTYLhUUO5KhTrkVrtXEFEJcxlMjjq7oeQEVnxe7 /c4Din5CGyQLJCmWBFUR1V/uD2TPYKPFmONHUQr2RQMtZdjqk4jgZEKBsu862meOYQ 0o5DN1+zJ+gkrTJVLKgy3+qiCrqlTDj/qK8mHVlbVxfjREJjBDpLDC9HxBZB8BJEr5 896R8yQC8sZ24lTDMVQeItnSjzhmP/KGtMSa7NBMIn6Y7MdEDaBUGJ/tegBIDXI/5J o69lBzBXWTD3Q== Message-ID: <38812166-bd47-4f6c-9e31-21f3f99ed2bf@zytor.com> Date: Fri, 13 Feb 2026 12:15:24 -0800 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 v5 2/3] x86/cpu: Check if feature string is non-zero To: Maciej Wieczor-Retman , Sohil Mehta Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Peter Zijlstra , pawel.chmielewski@linux.intel.com, Maciej Wieczor-Retman , linux-kernel@vger.kernel.org References: <184500c5-9e72-400e-8db2-22774c4856e6@intel.com> Content-Language: en-US, sv-SE From: "H. Peter Anvin" In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2026-02-13 02:02, Maciej Wieczor-Retman wrote: > On 2026-02-12 at 16:28:10 -0800, Sohil Mehta wrote: >> On 2/12/2026 7:35 AM, Maciej Wieczor-Retman wrote: >> >>> >>> +const char *x86_cap_name(unsigned int bit) >>> +{ >>> + unsigned int word = bit >> 5; >>> + static char undef_buf[16]; >>> + const char *name = NULL; >>> + >>> + if (likely(word < NCAPINTS)) >>> + name = x86_cap_flags[bit]; >>> + else if (likely(word < NCAPINTS + NBUGINTS)) >>> + name = x86_bug_flags[bit - 32 * NCAPINTS]; >>> + >>> + if (name) >>> + return name; >>> + >>> + snprintf(undef_buf, sizeof(undef_buf), "%u:%u", word, bit & 31); >>> + return undef_buf; >>> +} >>> + >> >> Isn't it unsafe to return undef_buf because the pointer is local to this >> function even though it is marked static? >> >> For example, the consecutive calls below would overwrite the value >> stored at that address. > > I just rechecked and after I caused that pr_warn_once() to be executed the > strings are printed correctly. > > Looking a bit further down, the pointers of the returned const char* are two > distinct values. So I assume because there are two calls to x86_cap_name() in > the pr_warn_once() the two static undef_buf char arrays are statically allocated > and there is no overwriting, but please correct me if that assumption is wrong. > At the very least the buffer would need to be percpu for it to be safe. On the other hand, there aren't a whole lot of places that uses this and the buffer needed isn't that big, so the best way is probably to have the caller pass in a buffer pointer on the stack. The callers are typically going to be large functions which require a stack frame anyway. -hpa