Re: [RFC PATCH] gcov: add basic gcov_info validation to gcov initialization

From: Peter Oberparleiter
Date: Mon Jun 07 2021 - 05:59:54 EST


On 02.06.2021 12:24, Luis Henriques wrote:
> Add a basic gcov_info struct validation helper to gcc to ensure we have
> sane from the compiler.
>
> Signed-off-by: Luis Henriques <lhenriques@xxxxxxx>
> ---
> Hi!
>
> I know this won't really validate the gcov_info struct, but it will at
> least prevent kernel crashes in simple scenarios (such as the one I'm
> seeing with gcc 9.3.1).

Thanks for your suggestion of adding validity checking for the gcov_info
struct. The goal you aim at is definitely something that we want to have
to reduce the impact of fallout from changes to GCC's gcov_info struct.

In my opinion though the approach you described - looking at the
contents of specific fields in gcov_info - isn't the correct way to go
forward. Since you cannot know how gcov_info changed, accessing any data
in it is very dangerous. Even if there's no out-of-bounds access (if the
struct's size was reduced) the field you are checking could have moved
elsewhere so the meaningfulness of the check is very limited.

In a previous discussion on the same topic I proposed a different
approach for a build-time check that would fully check the compatibility
of kernel code and GCC-emitted gcov-related data structures. See:

https://lore.kernel.org/patchwork/patch/1393585/#1592411

Unfortunately I have not yet found the time to implement this approach
but it's still on my to-do-list.

Regarding the cause of the error you're seeing I'll have a look at the
corresponding GCC source to see if there's anything that could be
causing the issue.


Regards,
Peter Oberparleiter

--
Peter Oberparleiter
Linux on Z Development - IBM Germany