From nobody Fri Dec 19 14:36:59 2025 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 D535132C33A for ; Wed, 5 Nov 2025 14:24:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762352683; cv=none; b=J5nFUOvel855UW8fG4qOUWMV75hphLthdYHzxTONey1kNSmovP7vY2BH92HD8Ua3PYQFIEUfwaSpywTo8zO29nuLGG13mcclgS0yfJBAtSfq3kgOdeaolUTdlE/kHh+hAawVLqoCi9LZwoapPNNde6w8PMQdGdIOUl9gVjIhGYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762352683; c=relaxed/simple; bh=qPNXWEHipoavN9pVpXbfbNKpPRagLspNBeYsffAEsIo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KCY4wzvjeSOO2HvgXvy9Xwiws4odnof5MHsk+g+WNuwQfKUe3RpdV6yKQKz6Q/QLLynmfF7f1VdyotLKvLnnYHPC3xxEz/YNHSI/z8uzdJeuyLsK2JMwew5w6WuuDsUOtsdKBI/SQ68mQU4O0THZA+Pz53E1kV4oWc+Hw9F85sY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=ZIhE1Iz8; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=ZIhE1Iz8; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="ZIhE1Iz8"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="ZIhE1Iz8" Received: from pathway.suse.cz (unknown [10.100.201.202]) by smtp-out2.suse.de (Postfix) with ESMTP id 9746D1F394; Wed, 5 Nov 2025 14:24:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762352677; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Glw8CB41dEHHbXisbpnYd6qd/VUwdMvAcibSgKx99aY=; b=ZIhE1Iz8PPjn13xSGL+MmieL7h+9wcbaNO4DpHayfLdZqIiakc2buekR++Rda/RvMqhOYs mTGt6bbEk9x0j6GRqMg5wrrNZYJsSZPrB+kBe6FfLLvnQXL14JrJQdYoLhNO+VqlkZkJKm rXnCyM098qYnP+WbLNKMK4U3JguNNGA= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762352677; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Glw8CB41dEHHbXisbpnYd6qd/VUwdMvAcibSgKx99aY=; b=ZIhE1Iz8PPjn13xSGL+MmieL7h+9wcbaNO4DpHayfLdZqIiakc2buekR++Rda/RvMqhOYs mTGt6bbEk9x0j6GRqMg5wrrNZYJsSZPrB+kBe6FfLLvnQXL14JrJQdYoLhNO+VqlkZkJKm rXnCyM098qYnP+WbLNKMK4U3JguNNGA= From: Petr Mladek To: Petr Pavlu , Steven Rostedt , Alexei Starovoitov , Andrew Morton , Kees Cook Cc: Daniel Borkmann , John Fastabend , Masami Hiramatsu , Mark Rutland , Luis Chamberlain , Daniel Gomez , Sami Tolvanen , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-modules@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH 5/6] kallsyms: Clean up @namebuf initialization in kallsyms_lookup_buildid() Date: Wed, 5 Nov 2025 15:23:17 +0100 Message-ID: <20251105142319.1139183-6-pmladek@suse.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251105142319.1139183-1-pmladek@suse.com> References: <20251105142319.1139183-1-pmladek@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-5.30 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCPT_COUNT_TWELVE(0.00)[17]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TAGGED_RCPT(0.00)[]; FREEMAIL_CC(0.00)[iogearbox.net,gmail.com,kernel.org,arm.com,google.com,vger.kernel.org,suse.com]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:email]; R_RATELIMIT(0.00)[to_ip_from(RLh88t7rzwwfj8wh1imqozhtme)]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Flag: NO X-Spam-Score: -5.30 X-Spam-Level: Content-Type: text/plain; charset="utf-8" The function kallsyms_lookup_buildid() initializes the given @namebuf by clearing the first and the last byte. It is not clear why. The 1st byte makes sense because some callers ignore the return code and expect that the buffer contains a valid string, for example: - function_stat_show() - kallsyms_lookup() - kallsyms_lookup_buildid() The initialization of the last byte does not make much sense because it can later be overwritten. Fortunately, it seems that all called functions behave correctly: - kallsyms_expand_symbol() explicitly adds the trailing '\0' at the end of the function. - All *__address_lookup() functions either use the safe strscpy() or they do not touch the buffer at all. Document the reason for clearing the first byte. And remove the useless initialization of the last byte. Signed-off-by: Petr Mladek Reviewed-by: Aaron Tomlin --- kernel/kallsyms.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 71868a76e9a1..ff7017337535 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -352,7 +352,12 @@ static int kallsyms_lookup_buildid(unsigned long addr, { int ret; =20 - namebuf[KSYM_NAME_LEN - 1] =3D 0; + /* + * kallsyms_lookus() returns pointer to namebuf on success and + * NULL on error. But some callers ignore the return value. + * Instead they expect @namebuf filled either with valid + * or empty string. + */ namebuf[0] =3D 0; =20 if (is_ksym_addr(addr)) { --=20 2.51.1