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]
Date:   Thu, 2 Nov 2023 12:50:01 +0100
From:   Uros Bizjak <ubizjak@...il.com>
To:     Peter Zijlstra <peterz@...radead.org>
Cc:     x86@...nel.org, linux-kernel@...r.kernel.org,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...nel.org>, Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        "H. Peter Anvin" <hpa@...or.com>
Subject: Re: [PATCH 2/3] x86/callthunks: Handle %rip-relative relocations in
 call thunk template

On Thu, Nov 2, 2023 at 12:44 PM Peter Zijlstra <peterz@...radead.org> wrote:
>
> On Thu, Nov 02, 2023 at 12:25:47PM +0100, Uros Bizjak wrote:
>
> > @@ -166,13 +168,51 @@ static const u8 nops[] = {
> >       0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
> >  };
> >
> > +#define apply_reloc_n(n_, p_, d_)                            \
> > +     do {                                                    \
> > +             s32 v = *(s##n_ *)(p_);                         \
> > +             v += (d_);                                      \
> > +             BUG_ON((v >> 31) != (v >> (n_-1)));             \
> > +             *(s##n_ *)(p_) = (s##n_)v;                      \
> > +     } while (0)
> > +
> > +static __always_inline
> > +void apply_reloc(int n, void *ptr, uintptr_t diff)
> > +{
> > +     switch (n) {
> > +     case 4: apply_reloc_n(32, ptr, diff); break;
> > +     default: BUG();
> > +     }
> > +}
> > +
> > +static void apply_relocation(u8 *buf, size_t len, u8 *dest, u8 *src)
> > +{
> > +     for (int next, i = 0; i < len; i = next) {
> > +             struct insn insn;
> > +
> > +             if (WARN_ON_ONCE(insn_decode_kernel(&insn, &buf[i])))
> > +                     return;
> > +
> > +             next = i + insn.length;
> > +
> > +             if (insn_rip_relative(&insn))
> > +                     apply_reloc(insn.displacement.nbytes,
> > +                                 buf + i + insn_offset_displacement(&insn),
> > +                                 src - dest);
> > +     }
> > +}
>
> Isn't it simpler to use apply_relocation() from alternative.c?

Yes, I was looking at that function, but somehow thought that it is a
bit overkill here, since we just need a %rip-relative reloc.

> Remove static, add decl, stuff like that?

On second thought, you are right. Should I move the above function
somewhere (reloc.c?) , or can I just use it from alternative.c and add
decl (where?) ?

Thanks,
Uros.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ