Re: [PATCH 1/4] x86: entry.S: tidy up several suboptimal insns

Ingo Molnar
2015-02-25T09:39:51Z

* H. Peter Anvin <hpa@zytor.com> wrote:

> > So could we just zap the high 32 bits of RAX early in
> > the entry code, and then from that point on we could
> > both use 32-bit ops and won't have to remember the
> > possibility either?
>
> We do that, [...]

Ok, indeed, so in ia32_sysenter_target() we have:

movl %eax, %eax

> [...] but people keep "optimizing" the zero extend away.
> [...]

Possibly because there's not a single comment near that
code explaining the importance of that line. But nobody
will get a change past me with such a warning next to the
line.

> [...] We have had this cause a wide-open security hole
> twice already. So the extra REX prefix is a cheap cost
> to avoid this happen again.

But since we already zap the high bits, there's no point in
doing 64-bit compares...

Just make sure the high zero bit clearing is there and is
never removed.

So in that sense the changes are correct, even in the
security robustness sense.

Furthermore, with the masking suggestion I made in the
previous mail it's moot as we can solve both problems:
64-bit uses of RAX will become correct as well, and it
will be a bit faster as well.

Hm?

Thanks,

Ingo