From nobody Mon Feb 9 05:58:20 2026 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 878A033032C for ; Wed, 12 Nov 2025 14:20:41 +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=1762957243; cv=none; b=KEmcNht6o75QBVRR1G/KqDYkFz8rtsemJROfywiS/cLCU3Q/dhC9o6VqA1mJkHzVlcc+/hOaUi/QQ6WqZ7acu4MhWsieY3Ke2sWFtkgxqe5Zxq6XGi9C29fdepmAZJfuKOWs9CUfqJiVEHjEa5fpAB7Oiii5mfp/Ciw+ROzJZD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762957243; c=relaxed/simple; bh=NPULls7NkZK7K8UN1fMarpplKLfCVpzfoJgnXnPgubc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DaXhMYcgNwZDwQBsFSLLxjUVcrqMlHEsMubZGkODOM3McueLASwi1lUqlZro83d4WKf2qIXF2HUUeoIFIqGlTcrMuzpeQRYi7ElOlw25HhJOSvApVuHGgBA/afS545CEJpiprzc/zep4ULyTwNqlq56+pjaA5YJdsmALJ94A1zA= 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=TrfHGZSV; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=TrfHGZSV; 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="TrfHGZSV"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="TrfHGZSV" Received: from pathway.suse.cz (unknown [10.100.208.146]) by smtp-out2.suse.de (Postfix) with ESMTP id 79C641F811; Wed, 12 Nov 2025 14:20:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762957239; 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=cCOyARWGSi/xRdC07nt6pnjrsJIRTjWjs9bqoN8osVM=; b=TrfHGZSVK23k5MKwRs1KajqP/vUjGuEmN67vyNHectie79yXG77mc/IHmx2uNraCUpwJ6w To49NkA9SgRoINCE++e0NW34So/Ajsf7+gcaDPMFZyGKgLNprZV4L2SG0B41CuHDEg7iDb mKJXx+r9VBra9lJjdygDTKEVKxzfzYI= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762957239; 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=cCOyARWGSi/xRdC07nt6pnjrsJIRTjWjs9bqoN8osVM=; b=TrfHGZSVK23k5MKwRs1KajqP/vUjGuEmN67vyNHectie79yXG77mc/IHmx2uNraCUpwJ6w To49NkA9SgRoINCE++e0NW34So/Ajsf7+gcaDPMFZyGKgLNprZV4L2SG0B41CuHDEg7iDb mKJXx+r9VBra9lJjdygDTKEVKxzfzYI= From: Petr Mladek To: Petr Pavlu , Steven Rostedt , Alexei Starovoitov , Andrew Morton , Kees Cook Cc: Aaron Tomlin , 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 v2 1/7] kallsyms: Clean up @namebuf initialization in kallsyms_lookup_buildid() Date: Wed, 12 Nov 2025 15:19:57 +0100 Message-ID: <20251112142003.182062-2-pmladek@suse.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251112142003.182062-1-pmladek@suse.com> References: <20251112142003.182062-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)[18]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TAGGED_RCPT(0.00)[]; FREEMAIL_CC(0.00)[atomlin.com,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,atomlin.com:email]; R_RATELIMIT(0.00)[to_ip_from(RLw9bydq1j5bti46rxed9sjz7y)]; 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. Reviewed-by: Aaron Tomlin Signed-off-by: Petr Mladek --- kernel/kallsyms.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 1e7635864124..e08c1e57fc0d 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 From nobody Mon Feb 9 05:58:20 2026 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 9739A2C0F6C for ; Wed, 12 Nov 2025 14:20:52 +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=1762957254; cv=none; b=XIJOhh0sOAgU8m3d9klsgCxtnN1ZIU3LlEBy5kP/NO8hIjyqSDDPPpurdcXA6NbaUseOGqVm9Ttt3dIpUEx7ymXMOcibqZstD0yADTrocyYKnDu0q9yi+II0EjWiO0JxRjDD6hET+EN4G081TomW3u+D8T4RnN7YXXtIAPsdnCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762957254; c=relaxed/simple; bh=PMLe2NtTfO8x7SDcutb9xCSuVGGAXm1wxNPsTX8IEsg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ClC/26V6JHl1PksUMd5+wJ8/eDw1KKl+xgDHT6XWgRLGVwwoZbR3KuPSzibnPbUHcLksVGOjUTBjvkkrkr7GicsCmS2M1PXCV3R3fcHFsdLK5iJ0PQRoLofoLQdxaWTFAh3k6MvkIkdwEoIdtWSmX67pHhrQlIz22mgrUpF+c8E= 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=mZcww2C1; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=qYriiYqz; 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="mZcww2C1"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="qYriiYqz" Received: from pathway.suse.cz (unknown [10.100.208.146]) by smtp-out2.suse.de (Postfix) with ESMTP id 78D051F807; Wed, 12 Nov 2025 14:20:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762957251; 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=FfvF234vWKCKB1nLJCrpAZU8zDmOaaizZkH1U/ILFM0=; b=mZcww2C16TuWjdqIjkr/hhIXrVdisUWC3wT7I9hXmg97M7bp/Y2MzU5N0q+GLM/XimUci0 Jxj6SwL0z1eca1n8hpjx8PjCSTIN/4ZMzfDlDcZ6Pk67sF79R0iBBXraAuR84kZ/RhCWme zo3a/zWDoQ5fRe9iP2pKbSQRM5C6iS4= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762957250; 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=FfvF234vWKCKB1nLJCrpAZU8zDmOaaizZkH1U/ILFM0=; b=qYriiYqzeyLyODTQdOw1Ee1YbpQlGRW0dWpbG1E0mDkBxGh8ZA03iOuCH61+fgV/LISsWj 1CUQEbN5eLbzksZS/4Rut8L0gw7JIIjSfGQjGPYZpOjadHyEbf/npKJv5jfjYs6z1tGSn/ crLLfNIlK1JOErgPZlf6VSbNBBo/Azw= From: Petr Mladek To: Petr Pavlu , Steven Rostedt , Alexei Starovoitov , Andrew Morton , Kees Cook Cc: Aaron Tomlin , 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 v2 2/7] kallsyms: Clean up modname and modbuildid initialization in kallsyms_lookup_buildid() Date: Wed, 12 Nov 2025 15:19:58 +0100 Message-ID: <20251112142003.182062-3-pmladek@suse.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251112142003.182062-1-pmladek@suse.com> References: <20251112142003.182062-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-Spam-Level: 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)[18]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TAGGED_RCPT(0.00)[]; FREEMAIL_CC(0.00)[atomlin.com,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:email,suse.com:mid]; R_RATELIMIT(0.00)[to_ip_from(RLw9bydq1j5bti46rxed9sjz7y)]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Flag: NO X-Spam-Score: -5.30 Content-Type: text/plain; charset="utf-8" The @modname and @modbuildid optional return parameters are set only when the symbol is in a module. Always initialize them so that they do not need to be cleared when the module is not in a module. It simplifies the logic and makes the code even slightly more safe. Note that bpf_address_lookup() function will get updated in a separate patch. Signed-off-by: Petr Mladek --- kernel/kallsyms.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index e08c1e57fc0d..ffb64eaa0505 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -359,6 +359,14 @@ static int kallsyms_lookup_buildid(unsigned long addr, * or empty string. */ namebuf[0] =3D 0; + /* + * Initialize the module-related return values. They are not set + * when the symbol is in vmlinux or it is a bpf address. + */ + if (modname) + *modname =3D NULL; + if (modbuildid) + *modbuildid =3D NULL; =20 if (is_ksym_addr(addr)) { unsigned long pos; @@ -367,10 +375,6 @@ static int kallsyms_lookup_buildid(unsigned long addr, /* Grab name */ kallsyms_expand_symbol(get_symbol_offset(pos), namebuf, KSYM_NAME_LEN); - if (modname) - *modname =3D NULL; - if (modbuildid) - *modbuildid =3D NULL; =20 return strlen(namebuf); } --=20 2.51.1 From nobody Mon Feb 9 05:58:20 2026 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 C304F28A1D5 for ; Wed, 12 Nov 2025 14:21:03 +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=1762957265; cv=none; b=EeoWNdGnHLQIlqc1Atr3GovUL7SxiWHE1JyNN/OeHKivPOrY/Kf2BZ4drrYVSXs13QeX1/zcMXvGtF3OvQZ1/OuYUAfVoAlY1xvS9t+jzzo3KH2PEthBNjd4CGdmC9NuFiiezMZCFFS6ZY8qzkkZutHjYQUXT05aaw+BlZOPPBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762957265; c=relaxed/simple; bh=L+21FgGFxbyB5fQzwZtH9DyvGokcavDoCgJHID86toM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hVa6iXxlKsfqY8WPiKj+vHacCcs3IikGS3KSDkDQfVhWYefmAUTWjEtDHOPG/v0v9kG/0nZIyWMSn0eSiWawyi4DY8xOhNWgjh8PVm5EkxLLdUMZF+mgM4B7gZrEgt/YkJC14nrVXM+GF2sztl+RXIZb6OFTNohIFYjahVLAIUM= 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=Wqi7Mo3z; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=Wqi7Mo3z; 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="Wqi7Mo3z"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="Wqi7Mo3z" Received: from pathway.suse.cz (unknown [10.100.208.146]) by smtp-out2.suse.de (Postfix) with ESMTP id 7150D1F7FA; Wed, 12 Nov 2025 14:21:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762957262; 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=qP8QlUZ0s55z6qhmwDjXxh+SigCtbX/rn988arBW42k=; b=Wqi7Mo3zGsGLvSllNuqtLSGEerqMg0dFrOc8arOJkp6Mp1szhET9FA1NnE5hQ18huN7E/Z OCBez5MFND42NVTDoCVCABqIenD5wayT4R3n6kgZ4qhUh4mdT8XdVuGcvrq4yrfYd6gUiI XSwbDavq/IHDsL6rKaetwY2oPGt5IKs= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762957262; 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=qP8QlUZ0s55z6qhmwDjXxh+SigCtbX/rn988arBW42k=; b=Wqi7Mo3zGsGLvSllNuqtLSGEerqMg0dFrOc8arOJkp6Mp1szhET9FA1NnE5hQ18huN7E/Z OCBez5MFND42NVTDoCVCABqIenD5wayT4R3n6kgZ4qhUh4mdT8XdVuGcvrq4yrfYd6gUiI XSwbDavq/IHDsL6rKaetwY2oPGt5IKs= From: Petr Mladek To: Petr Pavlu , Steven Rostedt , Alexei Starovoitov , Andrew Morton , Kees Cook Cc: Aaron Tomlin , 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 , Daniel Gomez Subject: [PATCH v2 3/7] module: Add helper function for reading module_buildid() Date: Wed, 12 Nov 2025 15:19:59 +0100 Message-ID: <20251112142003.182062-4-pmladek@suse.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251112142003.182062-1-pmladek@suse.com> References: <20251112142003.182062-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-Spam-Level: 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)[19]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TAGGED_RCPT(0.00)[]; FREEMAIL_CC(0.00)[atomlin.com,iogearbox.net,gmail.com,kernel.org,arm.com,google.com,vger.kernel.org,suse.com,samsung.com]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.com:mid]; R_RATELIMIT(0.00)[to_ip_from(RLw9bydq1j5bti46rxed9sjz7y)]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Flag: NO X-Spam-Score: -5.30 Content-Type: text/plain; charset="utf-8" Add a helper function for reading the optional "build_id" member of struct module. It is going to be used also in ftrace_mod_address_lookup(). Use "#ifdef" instead of "#if IS_ENABLED()" to match the declaration of the optional field in struct module. Reviewed-by: Daniel Gomez Reviewed-by: Petr Pavlu Signed-off-by: Petr Mladek --- include/linux/module.h | 9 +++++++++ kernel/module/kallsyms.c | 9 ++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index e135cc79acee..4decae2b1675 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -747,6 +747,15 @@ static inline void __module_get(struct module *module) __mod ? __mod->name : "kernel"; \ }) =20 +static inline const unsigned char *module_buildid(struct module *mod) +{ +#ifdef CONFIG_STACKTRACE_BUILD_ID + return mod->build_id; +#else + return NULL; +#endif +} + /* Dereference module function descriptor */ void *dereference_module_function_descriptor(struct module *mod, void *ptr= ); =20 diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c index 00a60796327c..0fc11e45df9b 100644 --- a/kernel/module/kallsyms.c +++ b/kernel/module/kallsyms.c @@ -334,13 +334,8 @@ int module_address_lookup(unsigned long addr, if (mod) { if (modname) *modname =3D mod->name; - if (modbuildid) { -#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) - *modbuildid =3D mod->build_id; -#else - *modbuildid =3D NULL; -#endif - } + if (modbuildid) + *modbuildid =3D module_buildid(mod); =20 sym =3D find_kallsyms_symbol(mod, addr, size, offset); =20 --=20 2.51.1 From nobody Mon Feb 9 05:58:20 2026 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 34650289811 for ; Wed, 12 Nov 2025 14:21:16 +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=1762957277; cv=none; b=k+8ohqRLYtGFdE6hNt8iu6Q+KRbY4esbNpSXN2joIzPZo+BYYJIE1tPGiZaBd93rOpLYg4w3hxCiNMSWxay7q+Ovb+kNbobMo9gQmfjPabMnjchWqhjIWUa1ShvYQP4nh+oVG2U0qvxjrOmfmMvXuNPxF2ddEdh4KA1J5pAHgGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762957277; c=relaxed/simple; bh=u3JhEMeaHqCCm3K2TgktQ2sf6pbkWpeo3IYBAWNLKUE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tvWfsCb27zLNQpBKIL5WeROExeJ5OJyzfz3JjDCi+L3VonAMywBqMzLi9qgkfaY8+sBsLsduKVZZPAfW5r5b4X9LRl28zMfCYR+EXZmIfCfJZS5EADEfaFMl3n6EqgMNBFk21yq1858ULAMfDBIoSt4CwKIQI4LMZms2sDVCcQ0= 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=BnLRB4F5; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=nfE6lf8+; 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="BnLRB4F5"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="nfE6lf8+" Received: from pathway.suse.cz (unknown [10.100.208.146]) by smtp-out2.suse.de (Postfix) with ESMTP id E55921F807; Wed, 12 Nov 2025 14:21:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762957274; 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=BqiSBpirJiJgacOo4S6qpog2Igj/FxV7fepY1Ud1yj0=; b=BnLRB4F5kJvWwq0uNFeHowmv1KnJLRD/SadwOgmpAPdbqJwMwnI2r67nMU7639gySQO1fw JaE3y0NsrSLvGGxVw9iHHz7i8Z+lbkGWc/CDpNdA3Gh0MkYEUAQPXr76+w/l+22E8RAm8m 7M67Qyji0EBagdLVxL6cWqvJYII5ebM= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762957273; 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=BqiSBpirJiJgacOo4S6qpog2Igj/FxV7fepY1Ud1yj0=; b=nfE6lf8+xSB8X6uMB6MAvfX9g5LM0PTktLSW/TjYc8aWLCrkOH2loOODKkGAZ7ffflRX/g 7JGH4bmjSV1stI5Nvw5xWQD+yt0coyQ5lnK9Q4yzEhFYwkTC8fOw+OPXGP7/DtyrDJG0+E ynBOFl4UpXHJAr2iReFapL95pgRSQZY= From: Petr Mladek To: Petr Pavlu , Steven Rostedt , Alexei Starovoitov , Andrew Morton , Kees Cook Cc: Aaron Tomlin , 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 v2 4/7] kallsyms: Cleanup code for appending the module buildid Date: Wed, 12 Nov 2025 15:20:00 +0100 Message-ID: <20251112142003.182062-5-pmladek@suse.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251112142003.182062-1-pmladek@suse.com> References: <20251112142003.182062-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)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; 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)[18]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_CC(0.00)[atomlin.com,iogearbox.net,gmail.com,kernel.org,arm.com,google.com,vger.kernel.org,suse.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_HAS_DN(0.00)[]; TAGGED_RCPT(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:email,pathway.suse.cz:helo]; R_RATELIMIT(0.00)[to_ip_from(RLw9bydq1j5bti46rxed9sjz7y)]; 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" Put the code for appending the optional "buildid" into a helper function, It makes __sprint_symbol() better readable. Also print a warning when the "modname" is set and the "buildid" isn't. It might catch a situation when some lookup function in kallsyms_lookup_buildid() does not handle the "buildid". Use pr_*_once() to avoid an infinite recursion when the function is called from printk(). The recursion is rather theoretical but better be on the safe side. Signed-off-by: Petr Mladek --- kernel/kallsyms.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index ffb64eaa0505..f25b122397ce 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -432,6 +432,37 @@ int lookup_symbol_name(unsigned long addr, char *symna= me) return lookup_module_symbol_name(addr, symname); } =20 +#ifdef CONFIG_STACKTRACE_BUILD_ID + +static int append_buildid(char *buffer, const char *modname, + const unsigned char *buildid) +{ + if (!modname) + return 0; + + if (!buildid) { + pr_warn_once("Undefined buildid for the module %s\n", modname); + return 0; + } + + /* build ID should match length of sprintf */ +#ifdef CONFIG_MODULES + static_assert(sizeof(typeof_member(struct module, build_id)) =3D=3D 20); +#endif + + return sprintf(buffer, " %20phN", buildid); +} + +#else /* CONFIG_STACKTRACE_BUILD_ID */ + +static int append_buildid(char *buffer, const char *modname, + const unsigned char *buildid) +{ + return 0; +} + +#endif /* CONFIG_STACKTRACE_BUILD_ID */ + /* Look up a kernel symbol and return it in a text buffer. */ static int __sprint_symbol(char *buffer, unsigned long address, int symbol_offset, int add_offset, int add_buildid) @@ -454,15 +485,8 @@ static int __sprint_symbol(char *buffer, unsigned long= address, =20 if (modname) { len +=3D sprintf(buffer + len, " [%s", modname); -#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) - if (add_buildid && buildid) { - /* build ID should match length of sprintf */ -#if IS_ENABLED(CONFIG_MODULES) - static_assert(sizeof(typeof_member(struct module, build_id)) =3D=3D 20); -#endif - len +=3D sprintf(buffer + len, " %20phN", buildid); - } -#endif + if (add_buildid) + len +=3D append_buildid(buffer + len, modname, buildid); len +=3D sprintf(buffer + len, "]"); } =20 --=20 2.51.1 From nobody Mon Feb 9 05:58:20 2026 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 1B9CC33B6C3 for ; Wed, 12 Nov 2025 14:21:27 +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=1762957290; cv=none; b=MK0iBUNM9aeGZA2McPYhxjHjBReByE3dpnmHJNc/FeyQhBhT+iKhDhCphLK/rSzE6sjC+1sru9TUUGz8vPBZRw3UMZ825bBFaAsSEOnoeeOIjVBAgTjCmWV3G5Im8SOG2fBmyYPels9MjthJxNGixvfjFpANfUML22N6wIi6iwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762957290; c=relaxed/simple; bh=mxHWdzO4dwX+BObrGKYvMuAa72kgBGhtSbLImU0cGIw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cMkIBOeP6l/tiwkU0PI3WO6PWgG387vszlGffnzKd61EIi2M9NlJDOSpbSkgkSTvGB5DilZd+geWKKvtLBErnvJ8TAG6M9EpXamWywMfHCp+UCj+9O59xZc+Kv/6Hq2WZePu1ndCcNinRBSByQDi/MYop6E6s+baIZpZgaYDfOY= 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=XUzFd6mO; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=XUzFd6mO; 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="XUzFd6mO"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="XUzFd6mO" Received: from pathway.suse.cz (unknown [10.100.208.146]) by smtp-out2.suse.de (Postfix) with ESMTP id 3ADC41F812; Wed, 12 Nov 2025 14:21:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762957285; 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=zpcxTfUXgq7Ejo6e4rnogFpcy04cmMoesux2qzsq6m8=; b=XUzFd6mOSUyS/QfRDzwqvkLYxFAEjSAkGruMQGKXG9+8H/dNuE8lVBC5GilvysKE5auiar cWOm9KUI/PhGxuyFvlRlmnMMV5rm7YZXsbZ1ydJHKsSQGlFb4tk6KejgVBg09X4qeXcSbO u9WmMYJjVZBhSEa8GAyJzlCJPGvlcY4= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762957285; 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=zpcxTfUXgq7Ejo6e4rnogFpcy04cmMoesux2qzsq6m8=; b=XUzFd6mOSUyS/QfRDzwqvkLYxFAEjSAkGruMQGKXG9+8H/dNuE8lVBC5GilvysKE5auiar cWOm9KUI/PhGxuyFvlRlmnMMV5rm7YZXsbZ1ydJHKsSQGlFb4tk6KejgVBg09X4qeXcSbO u9WmMYJjVZBhSEa8GAyJzlCJPGvlcY4= From: Petr Mladek To: Petr Pavlu , Steven Rostedt , Alexei Starovoitov , Andrew Morton , Kees Cook Cc: Aaron Tomlin , 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 v2 5/7] kallsyms/bpf: Rename __bpf_address_lookup() to bpf_address_lookup() Date: Wed, 12 Nov 2025 15:20:01 +0100 Message-ID: <20251112142003.182062-6-pmladek@suse.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251112142003.182062-1-pmladek@suse.com> References: <20251112142003.182062-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-Spam-Level: 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)[18]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TAGGED_RCPT(0.00)[]; FREEMAIL_CC(0.00)[atomlin.com,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)[pathway.suse.cz:helo,suse.com:email,suse.com:mid]; R_RATELIMIT(0.00)[to_ip_from(RLw9bydq1j5bti46rxed9sjz7y)]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Flag: NO X-Spam-Score: -5.30 Content-Type: text/plain; charset="utf-8" bpf_address_lookup() has been used only in kallsyms_lookup_buildid(). It was supposed to set @modname and @modbuildid when the symbol was in a module. But it always just cleared @modname because BPF symbols were never in a module. And it did not clear @modbuildid because the pointer was not passed. The wrapper is not longer needed. Both @modname and @modbuildid are newly always initialized to NULL in kallsyms_lookup_buildid(). Remove the wrapper and rename __bpf_address_lookup() to bpf_address_lookup() because this variant is used everywhere. Fixes: 9294523e3768 ("module: add printk formats to add module build ID to = stacktraces") Signed-off-by: Petr Mladek Acked-by: Alexei Starovoitov --- arch/arm64/net/bpf_jit_comp.c | 2 +- arch/powerpc/net/bpf_jit_comp.c | 2 +- include/linux/filter.h | 26 ++++---------------------- kernel/bpf/core.c | 4 ++-- kernel/kallsyms.c | 5 ++--- 5 files changed, 10 insertions(+), 29 deletions(-) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 0c9a50a1e73e..17e6a041ea4d 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -2939,7 +2939,7 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_t= ype poke_type, u64 plt_target =3D 0ULL; bool poking_bpf_entry; =20 - if (!__bpf_address_lookup((unsigned long)ip, &size, &offset, namebuf)) + if (!bpf_address_lookup((unsigned long)ip, &size, &offset, namebuf)) /* Only poking bpf text is supported. Since kernel function * entry is set up by ftrace, we reply on ftrace to poke kernel * functions. diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_com= p.c index 88ad5ba7b87f..21f7f26a5e2f 100644 --- a/arch/powerpc/net/bpf_jit_comp.c +++ b/arch/powerpc/net/bpf_jit_comp.c @@ -1122,7 +1122,7 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_t= ype poke_type, branch_flags =3D poke_type =3D=3D BPF_MOD_CALL ? BRANCH_SET_LINK : 0; =20 /* We currently only support poking bpf programs */ - if (!__bpf_address_lookup(bpf_func, &size, &offset, name)) { + if (!bpf_address_lookup(bpf_func, &size, &offset, name)) { pr_err("%s (0x%lx): kernel/modules are not supported\n", __func__, bpf_f= unc); return -EOPNOTSUPP; } diff --git a/include/linux/filter.h b/include/linux/filter.h index f5c859b8131a..d500338af6e0 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -1353,24 +1353,13 @@ static inline bool bpf_jit_kallsyms_enabled(void) return false; } =20 -int __bpf_address_lookup(unsigned long addr, unsigned long *size, - unsigned long *off, char *sym); +int bpf_address_lookup(unsigned long addr, unsigned long *size, + unsigned long *off, char *sym); bool is_bpf_text_address(unsigned long addr); int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type, char *sym); struct bpf_prog *bpf_prog_ksym_find(unsigned long addr); =20 -static inline int -bpf_address_lookup(unsigned long addr, unsigned long *size, - unsigned long *off, char **modname, char *sym) -{ - int ret =3D __bpf_address_lookup(addr, size, off, sym); - - if (ret && modname) - *modname =3D NULL; - return ret; -} - void bpf_prog_kallsyms_add(struct bpf_prog *fp); void bpf_prog_kallsyms_del(struct bpf_prog *fp); =20 @@ -1409,8 +1398,8 @@ static inline bool bpf_jit_kallsyms_enabled(void) } =20 static inline int -__bpf_address_lookup(unsigned long addr, unsigned long *size, - unsigned long *off, char *sym) +bpf_address_lookup(unsigned long addr, unsigned long *size, + unsigned long *off, char *sym) { return 0; } @@ -1431,13 +1420,6 @@ static inline struct bpf_prog *bpf_prog_ksym_find(un= signed long addr) return NULL; } =20 -static inline int -bpf_address_lookup(unsigned long addr, unsigned long *size, - unsigned long *off, char **modname, char *sym) -{ - return 0; -} - static inline void bpf_prog_kallsyms_add(struct bpf_prog *fp) { } diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index d595fe512498..c2278f392e93 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -713,8 +713,8 @@ static struct bpf_ksym *bpf_ksym_find(unsigned long add= r) return n ? container_of(n, struct bpf_ksym, tnode) : NULL; } =20 -int __bpf_address_lookup(unsigned long addr, unsigned long *size, - unsigned long *off, char *sym) +int bpf_address_lookup(unsigned long addr, unsigned long *size, + unsigned long *off, char *sym) { struct bpf_ksym *ksym; int ret =3D 0; diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index f25b122397ce..97b92fc8871d 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -342,7 +342,7 @@ int kallsyms_lookup_size_offset(unsigned long addr, uns= igned long *symbolsize, return 1; } return !!module_address_lookup(addr, symbolsize, offset, NULL, NULL, name= buf) || - !!__bpf_address_lookup(addr, symbolsize, offset, namebuf); + !!bpf_address_lookup(addr, symbolsize, offset, namebuf); } =20 static int kallsyms_lookup_buildid(unsigned long addr, @@ -383,8 +383,7 @@ static int kallsyms_lookup_buildid(unsigned long addr, ret =3D module_address_lookup(addr, symbolsize, offset, modname, modbuildid, namebuf); if (!ret) - ret =3D bpf_address_lookup(addr, symbolsize, - offset, modname, namebuf); + ret =3D bpf_address_lookup(addr, symbolsize, offset, namebuf); =20 if (!ret) ret =3D ftrace_mod_address_lookup(addr, symbolsize, --=20 2.51.1 From nobody Mon Feb 9 05:58:20 2026 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 E2E62334C35 for ; Wed, 12 Nov 2025 14:21:37 +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=1762957299; cv=none; b=P8/XjQoZQRJSPoo4K8Uh21BYupAB0yA8wx1kAxEJES4nxzHBAsDuIhZZ+NZxXuD6YB1rEuLMx4ncJZuykpRotiI1J7AKGl1HsyUmTvMsr5+8hFvXjFEBQaSGskioppSDlcw2KP6ki8W4f2gjT7s7WsDG581p01T1MogRiQGFtGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762957299; c=relaxed/simple; bh=3xFcdFAVAiwnQ0KWwv6CMVR/NIuvlwz20m6uT6E4qXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QS1BxMm41jEhjObb6TuAc4f8wYX4SlgzHOWgm8//p1KyxY2u4GlBXeVo3s/TlwVOEU61G9Ou6jFWwBAw4d4WjB15eUQRlmLsX8HpPklAokJhRmZYpmo+kw3IecSIyJxSHXDyx03Jo/wv8ic7IW5VzPs6KzzueabRgloAgPdRUwU= 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=V9COuMCa; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=V9COuMCa; 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="V9COuMCa"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="V9COuMCa" Received: from pathway.suse.cz (unknown [10.100.208.146]) by smtp-out2.suse.de (Postfix) with ESMTP id 080D21F7FA; Wed, 12 Nov 2025 14:21:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762957296; 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=evFpjNqjpWccBL5Ev7CM+eCXGSGu/p7G0azbkShutlQ=; b=V9COuMCaBHrWIOMgLYUC3PF+NF0h4Z5iLTqOaajMT+gSdDRSrI+eSKLAtiM813jT7QWOd2 2JrLd3C5h9C82Cvg9HA6jVgqgwV4ZQIBjEcOzFmQBSIh56PJ9eIi/oiv8WhiUxLBuc9L0p UA+UorVr3QH9Sox2wFsUjyskynJIssY= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762957296; 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=evFpjNqjpWccBL5Ev7CM+eCXGSGu/p7G0azbkShutlQ=; b=V9COuMCaBHrWIOMgLYUC3PF+NF0h4Z5iLTqOaajMT+gSdDRSrI+eSKLAtiM813jT7QWOd2 2JrLd3C5h9C82Cvg9HA6jVgqgwV4ZQIBjEcOzFmQBSIh56PJ9eIi/oiv8WhiUxLBuc9L0p UA+UorVr3QH9Sox2wFsUjyskynJIssY= From: Petr Mladek To: Petr Pavlu , Steven Rostedt , Alexei Starovoitov , Andrew Morton , Kees Cook Cc: Aaron Tomlin , 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 v2 6/7] kallsyms/ftrace: Set module buildid in ftrace_mod_address_lookup() Date: Wed, 12 Nov 2025 15:20:02 +0100 Message-ID: <20251112142003.182062-7-pmladek@suse.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251112142003.182062-1-pmladek@suse.com> References: <20251112142003.182062-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-Spam-Level: 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)[18]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TAGGED_RCPT(0.00)[]; FREEMAIL_CC(0.00)[atomlin.com,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)[goodmis.org:email,atomlin.com:email,pathway.suse.cz:helo,suse.com:email,suse.com:mid]; R_RATELIMIT(0.00)[to_ip_from(RLw9bydq1j5bti46rxed9sjz7y)]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-Spam-Flag: NO X-Spam-Score: -5.30 Content-Type: text/plain; charset="utf-8" __sprint_symbol() might access an invalid pointer when kallsyms_lookup_buildid() returns a symbol found by ftrace_mod_address_lookup(). The ftrace lookup function must set both @modname and @modbuildid the same way as module_address_lookup(). Fixes: 9294523e3768 ("module: add printk formats to add module build ID to = stacktraces") Reviewed-by: Aaron Tomlin Acked-by: Steven Rostedt (Google) Signed-off-by: Petr Mladek --- include/linux/ftrace.h | 6 ++++-- kernel/kallsyms.c | 4 ++-- kernel/trace/ftrace.c | 5 ++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 7ded7df6e9b5..a003cf1b32d0 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -87,11 +87,13 @@ struct ftrace_hash; defined(CONFIG_DYNAMIC_FTRACE) int ftrace_mod_address_lookup(unsigned long addr, unsigned long *size, - unsigned long *off, char **modname, char *sym); + unsigned long *off, char **modname, + const unsigned char **modbuildid, char *sym); #else static inline int ftrace_mod_address_lookup(unsigned long addr, unsigned long *size, - unsigned long *off, char **modname, char *sym) + unsigned long *off, char **modname, + const unsigned char **modbuildid, char *sym) { return 0; } diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 97b92fc8871d..5bc1646f8639 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -386,8 +386,8 @@ static int kallsyms_lookup_buildid(unsigned long addr, ret =3D bpf_address_lookup(addr, symbolsize, offset, namebuf); =20 if (!ret) - ret =3D ftrace_mod_address_lookup(addr, symbolsize, - offset, modname, namebuf); + ret =3D ftrace_mod_address_lookup(addr, symbolsize, offset, + modname, modbuildid, namebuf); =20 return ret; } diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 42bd2ba68a82..11f5096fb60c 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -7678,7 +7678,8 @@ ftrace_func_address_lookup(struct ftrace_mod_map *mod= _map, =20 int ftrace_mod_address_lookup(unsigned long addr, unsigned long *size, - unsigned long *off, char **modname, char *sym) + unsigned long *off, char **modname, + const unsigned char **modbuildid, char *sym) { struct ftrace_mod_map *mod_map; int ret =3D 0; @@ -7690,6 +7691,8 @@ ftrace_mod_address_lookup(unsigned long addr, unsigne= d long *size, if (ret) { if (modname) *modname =3D mod_map->mod->name; + if (modbuildid) + *modbuildid =3D module_buildid(mod_map->mod); break; } } --=20 2.51.1 From nobody Mon Feb 9 05:58:20 2026 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 B53B233032C for ; Wed, 12 Nov 2025 14:21:49 +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=1762957311; cv=none; b=AcwF2GAD/tOS6OeIy+9Lz8DuiJIcbNaCwJcRiK64OKKzMPXo6Aj9g9n72oSezxvjJIczsMsb+8N0wS0kjk70Tvz1xc3rsJT0+fKIHSQZoT29EDir1qNCV1rIeL62CycDTkNrG8fSrg7c3NOB2TeXY/J9nOjRlIyidg2dgP4U9lU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762957311; c=relaxed/simple; bh=DErfb1yw71TjXX1m2fEvBmVvRDvk5oiZa5z6kIuTRKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hHAtmmA55FYibab3nLmqaKKm3F/6iMLy9M/Wsre5kF/Ny+Z2PE8G/DLMwngYD9Amz/dsbTdbSjbslnOXJmVRcZ/rPpaiAf+4MHl4YOoi28R2szVgKTUnISfLhTFxriKufWUrOreJkfVYelNdg5XTs5xMTYZd0amuF0bKo2bamaM= 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=Fwm4E1Ut; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=ek/OUc1L; 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="Fwm4E1Ut"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="ek/OUc1L" Received: from pathway.suse.cz (unknown [10.100.208.146]) by smtp-out2.suse.de (Postfix) with ESMTP id E2A561F807; Wed, 12 Nov 2025 14:21:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762957308; 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=97I/A52s9/abeslkIlgFB5lHhNmcwVQr9GlDloyKxh0=; b=Fwm4E1Utf5nc5WoVAJu8cPbGqYJ663EAiMUr/dgD+haLJtJDSIcHPLVCstP0e3WjSOyVfL 39XTW3sBJh9rrJpBYxUGdJ/vEbrIGUF1xbftuqISTH9XzIGuFllUp4K1p6cRVP8z78xg9G Lx9r2Hkyv/iU1gSYpAnO1AI1iHmlcxs= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1762957307; 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=97I/A52s9/abeslkIlgFB5lHhNmcwVQr9GlDloyKxh0=; b=ek/OUc1L8yezFuEAGDJzTqJ+8mCV7yLr5PfXO+bwcp0xVnqW4RJjJ6UsOksg2or/65hKKb GF94DTt31+xP9WOXSka14/oe6F8IQ9cgWvXrVP3QKtCUe6Ax86F4RO8qb3QVsNLhyD24xm 8u8FIpZ5z2VqK5lcE6vsJa0kgttZ0Go= From: Petr Mladek To: Petr Pavlu , Steven Rostedt , Alexei Starovoitov , Andrew Morton , Kees Cook Cc: Aaron Tomlin , 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 v2 7/7] kallsyms: Prevent module removal when printing module name and buildid Date: Wed, 12 Nov 2025 15:20:03 +0100 Message-ID: <20251112142003.182062-8-pmladek@suse.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251112142003.182062-1-pmladek@suse.com> References: <20251112142003.182062-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)[18]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TAGGED_RCPT(0.00)[]; FREEMAIL_CC(0.00)[atomlin.com,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)[atomlin.com:email,pathway.suse.cz:helo]; R_RATELIMIT(0.00)[to_ip_from(RLw9bydq1j5bti46rxed9sjz7y)]; 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" kallsyms_lookup_buildid() copies the symbol name into the given buffer so that it can be safely read anytime later. But it just copies pointers to mod->name and mod->build_id which might get reused after the related struct module gets removed. The lifetime of struct module is synchronized using RCU. Take the rcu read lock for the entire __sprint_symbol(). Reviewed-by: Aaron Tomlin Signed-off-by: Petr Mladek --- kernel/kallsyms.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 5bc1646f8639..202d39f5493a 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -471,6 +471,9 @@ static int __sprint_symbol(char *buffer, unsigned long = address, unsigned long offset, size; int len; =20 + /* Prevent module removal until modname and modbuildid are printed */ + guard(rcu)(); + address +=3D symbol_offset; len =3D kallsyms_lookup_buildid(address, &size, &offset, &modname, &build= id, buffer); --=20 2.51.1