From: Peter Zijlstra <peterz@infradead.org>
To: Kees Cook <kees@kernel.org>
Cc: Gatlin Newhouse <gatlin.newhouse@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Marco Elver <elver@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Andrey Ryabinin <ryabinin.a.a@gmail.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
"Mike Rapoport (IBM)" <rppt@kernel.org>,
Baoquan He <bhe@redhat.com>,
Rick Edgecombe <rick.p.edgecombe@intel.com>,
Changbin Du <changbin.du@huawei.com>,
Pengfei Xu <pengfei.xu@intel.com>, Xin Li <xin3.li@intel.com>,
Jason Gunthorpe <jgg@ziepe.ca>, Uros Bizjak <ubizjak@gmail.com>,
Arnd Bergmann <arnd@arndb.de>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com,
linux-hardening@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH v3] x86/traps: Enable UBSAN traps on x86
Date: Fri, 28 Jun 2024 20:04:41 +0200 [thread overview]
Message-ID: <20240628180441.GJ31592@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <202406261205.E2435C68@keescook>
On Wed, Jun 26, 2024 at 12:07:52PM -0700, Kees Cook wrote:
> On Tue, Jun 25, 2024 at 11:37:19AM +0200, Peter Zijlstra wrote:
> > Also, wouldn't it be saner to write this something like:
> >
> > __always_inline int decode_bug(unsigned long addr, u32 *imm)
> > {
> > u8 v;
> >
> > if (addr < TASK_SIZE)
> > return BUG_NONE;
> >
> > v = *(u8 *)(addr++);
> > if (v == 0x67)
> > v = *(u8 *)(addr++);
> > if (v != 0x0f)
> > return BUG_NONE;
> > v = *(u8 *)(addr++);
> > if (v == 0x0b)
> > return BUG_UD2;
> > if (v != 0xb9)
> > return BUG_NONE;
> >
Looks like I lost:
v = *(u8 *)(addr++);
> > if (X86_MODRM_RM(v) == 4)
> > addr++; /* consume SiB */
> >
> > *imm = 0;
> > if (X86_MODRM_MOD(v) == 1)
> > *imm = *(u8 *)addr;
> > if (X86_MORRM_MOD(v) == 2)
> > *imm = *(u32 *)addr;
> >
> > // WARN on MOD(v)==3 ??
> >
> > return BUG_UD1;
> > }
>
> Thanks for the example! (I think it should use macros instead of
> open-coded "0x67", "0x0f", etc, but yeah.)
Yeah, I didn't feel like hunting down pre-existing defines for all of
them, but yeah.
> > Why does the thing emit the asop prefix at all through? afaict it
> > doesn't affect the immediate you want to get at. And if it does this
> > prefix, should we worry about other prefixes? Ideally we'd not accept
> > any prefixes.
>
> AFAICT it's because it's a small immediate? For an x86_64 build, this is
> how Clang is generating the UD1.
So the disp8 immediate comes from MOD==1, MOD==2 has a disp32. What the
prefix does is change the size of the memory being referenced from 32bit
to 16bit iirc, but since UD does not actually perform the load, this is
entirely superfluous afaict.
It might be good to figure out *why* clang thinks it needs this.
A REX prefix is far more likely to be useful (upper 8 destination
register for instance).
Anyway, it seems to basically boil down to needing a fairly complete
instruction decoder without being able the use the normal one :/
prev parent reply other threads:[~2024-06-28 18:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-25 3:24 [PATCH v3] x86/traps: Enable UBSAN traps on x86 Gatlin Newhouse
2024-06-25 6:45 ` Xin Li
2024-06-25 9:37 ` Peter Zijlstra
2024-06-26 19:07 ` Kees Cook
2024-06-28 18:04 ` Peter Zijlstra [this message]
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=20240628180441.GJ31592@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=arnd@arndb.de \
--cc=bhe@redhat.com \
--cc=bp@alien8.de \
--cc=changbin.du@huawei.com \
--cc=dave.hansen@linux.intel.com \
--cc=elver@google.com \
--cc=gatlin.newhouse@gmail.com \
--cc=hpa@zytor.com \
--cc=jgg@ziepe.ca \
--cc=justinstitt@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=kees@kernel.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=pengfei.xu@intel.com \
--cc=rick.p.edgecombe@intel.com \
--cc=rppt@kernel.org \
--cc=ryabinin.a.a@gmail.com \
--cc=tglx@linutronix.de \
--cc=ubizjak@gmail.com \
--cc=x86@kernel.org \
--cc=xin3.li@intel.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