Re: [PATCH v2] x86/mm: fix kern_addr_valid to cope with existing but not present entries

From: Mike Rapoport
Date: Wed Sep 08 2021 - 07:22:46 EST


On Wed, Sep 08, 2021 at 12:52:45PM +0200, Borislav Petkov wrote:
> On Wed, Sep 08, 2021 at 12:35:21PM +0200, Borislav Petkov wrote:
> > So I did stare at this for a while, trying to make sense of it and David
> > Hildenbrand asked for a Fixes: tag in v1 review and from doing a bit of
> > git archeology I think it should be:
> >
> > c40a56a7818c ("x86/mm/init: Remove freed kernel image areas from alias mapping")
> >
> > because that thing added the clearing of the Present bit for the high
> > kernel image mapping of those areas.
> >
> > Right?

Yes, in a sense.
As the only user of kern_addr_valid() is kcore and it only uses this check
for high kernel mappings, there should be no problem before 4.19.

But...


> Hmm, but that commit is in v4.19. Mike has added
>
> Cc: <stable@xxxxxxxxxxxxxxx> # 4.4+
>
> Mike, why 4.4 and newer?

kern_addr_valid() wrongly uses pxy_none() rather than pxy_present() because
according to 9a14aefc1d28 ("x86: cpa, fix lookup_address") there could be
cases when page table entries exist but they are not valid.
So a call to kern_addr_valid() for an address in the direct map would oops.

I've stopped digging at 9a14aefc1d28 (which is in v2.6.26) and added the
oldest stable we still support (4.4).

I agree that before 4.19 it's more of a theoretical bug, but you know,
things happen...

> Hmmm.

--
Sincerely yours,
Mike.