Re: [PATCH v10 10/15] FG-KASLR: use a scripted approach to handle .text.* sections

From: Peter Zijlstra
Date: Fri Feb 11 2022 - 10:38:47 EST


On Wed, Feb 09, 2022 at 07:57:47PM +0100, Alexander Lobakin wrote:
> +sub read_sections {
> + open(my $fh, "\"$readelf\" -SW \"$file\" 2>/dev/null |")
> + or die "$0: ERROR: failed to execute \"$readelf\": $!";
> +
> + while (<$fh>) {
> + my $name;
> + my $align;
> + chomp;
> +
> + ($name, $align) = $_ =~ /^\s*\[[\s0-9]*\]\s*(\.\S*)\s*[A-Z]*\s*[0-9a-f]{16}\s*[0-9a-f]*\s*[0-9a-f]*\s*[0-9a-f]*\s*[0-9a-f]{2}\s*[A-Z]{2}\s*[0-9]\s*[0-9]\s*([0-9]*)$/;

Is there really no readable way to write this?

> +
> + if (!defined($name)) {
> + next;
> + }
> +
> + ## Clang 13 onwards emits __cfi_check_fail only on final
> + ## linking, so it won't appear in .o files and will be
> + ## missing in @sections. Add it manually to prevent
> + ## spawning orphans.
> + if ($name eq ".text.__cfi_check_fail") {
> + $has_ccf = 1;
> + }

How is that relevant, x86-64 doesn't and won't do clang-cfi.