[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wgpOqujY210W9-KJPEfD42W_bvUdLwF-PAvyxJQ92tzDg@mail.gmail.com>
Date: Tue, 2 May 2023 18:17:15 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Dave Hansen <dave.hansen@...el.com>
Cc: "Kirill A. Shutemov" <kirill@...temov.name>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
linux-kernel@...r.kernel.org, kirill.shutemov@...ux.intel.com,
Peter Zijlstra <peterz@...radead.org>
Subject: Re: [GIT PULL] x86/mm for 6.4
On Tue, May 2, 2023 at 5:53 PM Dave Hansen <dave.hansen@...el.com> wrote:
>
> The fallout seems limited to (probably) perf and tracing poking at user
> stack frames. But, yes, it definitely looks broken there.
So I ended up doing more cleanups - moving the 64-bit specific code to
'uaccess_64.h' etc.
And in the process I found another broken
thing:__untagged_addr_remote() is very very buggy.
The reason?
long sign = addr >> 63;
that does *not* do at all what '__untagged_addr()' does, because while
'sign' is a signed long, 'addr' is an *unsigned* long.
So the actual shift ends up being done as an unsigned shift, and then
just the result is assigned to a signed variable.
End result? 'sign' ends up being 0 for user space (intentional) or 1
for kernel space (not intentional)..
It's not 0 or ~0 as the __untagged_addr() is, wh9ch uses a signed
shift in the inline asm ('sar')
That said, while this is all horribly buggy, I'm not actually 100%
sure that we care too much about untagging kernel addresses. So it's
an error case that doesn't get marked as an error.
So I guess in *practice* the horribly buggy code is actually just a
small harmless bug, and causes anybody who passes in an invalid
(kernel) address look like a possibly valid user address after all.
HOWEVER.
Why does it do that "shift-by-63" game there, instead of making
tlbstate_untag_mask just have bit #63 always set?
Untagging a kernel address is not a sensible operation, so the only
thing you want is to *keep* a kernel address as a bad address. You
don't have to actually keep it a *valid* kernel address, it just
should not become a (possibly valid) user address after untagging.
Hmmm? Am I missing something?
Linus
Powered by blists - more mailing lists