public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Luis Henriques <lhenriques@suse.de>
To: Peter Oberparleiter <oberpar@linux.ibm.com>
Cc: linux-kernel@vger.kernel.org
Subject: gcov: NULL pointer dereference with gcc 9.3.1
Date: Tue, 1 Jun 2021 16:56:50 +0100	[thread overview]
Message-ID: <YLZYwgs5hyzFZMlw@suse.de> (raw)

Hi!

Maybe this is a known (gcc?) issue, but I'm seeing a NULL pointer splat if
I instrument my kernel (or a module, more specifically) using gcc 9.3.1.

It looks like, during initialization in __gcov_init(), gcov_info struct is
invalid: the filename seems to be correct but ->function is NULL and
->n_functions contains garbage.  This will result in the NULL pointer if,
for example, I run:

  # echo 1 > /sys/kernel/debug/gcov/reset

Other installed gcc versions (7.5.0 and 10.3.0) work fine.

Is this a know issue with this specific gcc versions?  Anyway, it may
be worth having something like (not tested!):

diff --git a/kernel/gcov/gcc_base.c b/kernel/gcov/gcc_base.c
index 3cf736b9f880..de3ea47f4f62 100644
--- a/kernel/gcov/gcc_base.c
+++ b/kernel/gcov/gcc_base.c
@@ -13,6 +13,11 @@ void __gcov_init(struct gcov_info *info)
 {
 	static unsigned int gcov_version;
 
+	if (!info || !info->functions) {
+		pr_err_once("Invalid gcov_info structure\n");
+		return;
+	}
+
 	mutex_lock(&gcov_lock);
 	if (gcov_version == 0) {
 		gcov_version = gcov_info_version(info);

And also something similar in the clang code, I guess.

I can send a real (tested) patch if you wish, but I just wanted to know if
I'm missing something first.

Cheers,
--
Luis

             reply	other threads:[~2021-06-01 15:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-01 15:56 Luis Henriques [this message]
2021-06-02 10:24 ` [RFC PATCH] gcov: add basic gcov_info validation to gcov initialization Luis Henriques
2021-06-07  9:59   ` Peter Oberparleiter
2021-06-07 10:48     ` Luis Henriques
2021-06-02 12:35 ` gcov: NULL pointer dereference with gcc 9.3.1 Peter Oberparleiter
2021-06-02 14:22   ` Luis Henriques
2021-06-07 14:32     ` Peter Oberparleiter
2021-06-08 12:46       ` Luis Henriques

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YLZYwgs5hyzFZMlw@suse.de \
    --to=lhenriques@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oberpar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox