lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAFP8O3+Rrs7rs5nO3cQbpeayE2vQXTmaaaEfY_weyCGCuBYrFQ@mail.gmail.com>
Date:   Wed, 6 Sep 2023 11:27:44 -0700
From:   Fangrui Song <maskray@...gle.com>
To:     Song Liu <songliubraving@...a.com>
Cc:     Kees Cook <keescook@...omium.org>, Song Liu <song@...nel.org>,
        LKML <linux-kernel@...r.kernel.org>,
        Kernel Team <kernel-team@...a.com>,
        "x86@...nel.org" <x86@...nel.org>,
        clang-built-linux <llvm@...ts.linux.dev>,
        "linux-hardening@...r.kernel.org" <linux-hardening@...r.kernel.org>
Subject: Re: [PATCH] x86/vmlinux: Fix linker fill bytes for ld.lld

On Wed, Sep 6, 2023 at 11:16 AM Song Liu <songliubraving@...a.com> wrote:
>
>
>
> > On Sep 6, 2023, at 11:06 AM, Kees Cook <keescook@...omium.org> wrote:
> >
> > On Wed, Sep 06, 2023 at 10:52:15AM -0700, Song Liu wrote:
> >> With ":text =0xcccc", ld.lld fills unused text area with 0xcccc0000.
> >> Example objdump -D output:
> >>
> >> ffffffff82b04203:       00 00                   add    %al,(%rax)
> >> ffffffff82b04205:       cc                      int3
> >> ffffffff82b04206:       cc                      int3
> >> ffffffff82b04207:       00 00                   add    %al,(%rax)
> >> ffffffff82b04209:       cc                      int3
> >> ffffffff82b0420a:       cc                      int3
> >>
> >> Replace it with ":text =0xcccccccc", so we get the following instead:
> >>
> >> ffffffff82b04203:       cc                      int3
> >> ffffffff82b04204:       cc                      int3
> >> ffffffff82b04205:       cc                      int3
> >> ffffffff82b04206:       cc                      int3
> >> ffffffff82b04207:       cc                      int3
> >> ffffffff82b04208:       cc                      int3
> >>
> >> gcc/ld doesn't seem to have the same issue. The generated code stays the
> >> same for gcc/ld.
> >>
> >> Cc: Kees Cook <keescook@...omium.org>
> >> Cc: x86@...nel.org
> >> Signed-off-by: Song Liu <song@...nel.org>
> >
> > Ah! Thanks for the catch... I wonder if ld.lld should be fixed too? My
> > understanding was that ":text =...." was defined as being explicitly
> > u16?
>
> Per my experiment, gcc/ld gives same output for :text =0xcc, :text =0xcccc,
> and :text =0xcccccccc; while ld.lld handles :text = as u32, so :text =0xcc
> with ld.lld gives:
>
> ffffffff82b042a1:       00 cc                   add    %cl,%ah
> ffffffff82b042a3:       00 00                   add    %al,(%rax)
> ffffffff82b042a5:       00 cc                   add    %cl,%ah
> ffffffff82b042a7:       00 00                   add    %al,(%rax)
> ffffffff82b042a9:       00 cc                   add    %cl,%ah
> ffffffff82b042ab:       00 00                   add    %al,(%rax)
>
> I am not sure what the right behavior is per specification.
>
> Thanks,
> Song

AFAIK GNU ld's behavior is not documented here
https://sourceware.org/binutils/docs/ld/Output-Section-Fill.html

The Output Section Fill syntax allows an expression. It seems that if
you use =0xcc+0, GNU ld will use a 4-byte filler as well, similar to
gold and ld.lld.

Frankly, I feel that GNU ld behavior should not be relied upon. lld's
comment states that it is a deliberate choice to follow gold instead
of GNU ld here.

I'll elaborate a bit and add this discrepancy to my
https://maskray.me/blog/2020-12-19-lld-and-gnu-linker-incompatibilities
:)



-- 
宋方睿

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ