linux-hardened/arch
Aneesh Kumar K.V c179976cf4 powerpc/mm/hash: Fix get_region_id() for invalid addresses
Accesses by userspace to random addresses outside the user or kernel
address range will generate an SLB fault. When we handle that fault we
classify the effective address into several classes, eg. user, kernel
linear, kernel virtual etc.

For addresses that are completely outside of any valid range, we
should not insert an SLB entry at all, and instead immediately an
exception.

In the past this was handled in two ways. Firstly we would check the
top nibble of the address (using REGION_ID(ea)) and that would tell us
if the address was user (0), kernel linear (c), kernel virtual (d), or
vmemmap (f). If the address didn't match any of these it was invalid.

Then for each type of address we would do a secondary check. For the
user region we check against H_PGTABLE_RANGE, for kernel linear we
would mask the top nibble of the address and then check the address
against MAX_PHYSMEM_BITS.

As part of commit 0034d395f8 ("powerpc/mm/hash64: Map all the kernel
regions in the same 0xc range") we replaced REGION_ID() with
get_region_id() and changed the masking of the top nibble to only mask
the top two bits, which introduced a bug.

Addresses less than (4 << 60) are still handled correctly, they are
either less than (1 << 60) in which case they are subject to the
H_PGTABLE_RANGE check, or they are correctly checked against
MAX_PHYSMEM_BITS.

However addresses from (4 << 60) to ((0xc << 60) - 1), are incorrectly
treated as kernel linear addresses in get_region_id(). Then the top
two bits are cleared by EA_MASK in slb_allocate_kernel() and the
address is checked against MAX_PHYSMEM_BITS, which it passes due to
the masking. The end result is we incorrectly insert SLB entries for
those addresses.

That is not actually catastrophic, having inserted the SLB entry we
will then go on to take a page fault for the address and at that point
we detect the problem and report it as a bad fault.

Still we should not be inserting those entries, or treating them as
kernel linear addresses in the first place. So fix get_region_id() to
detect addresses in that range and return an invalid region id, which
we cause use to not insert an SLB entry and directly report an
exception.

Fixes: 0034d395f8 ("powerpc/mm/hash64: Map all the kernel regions in the same 0xc range")
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
[mpe: Drop change to EA_MASK for now, rewrite change log]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-05-17 22:57:40 +10:00
..
alpha Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2019-05-07 22:03:58 -07:00
arc audit/stable-5.2 PR 20190507 2019-05-07 19:06:04 -07:00
arm We have a couple new features and changes in the core clk framework this time 2019-05-09 14:50:09 -07:00
arm64 DMA mapping updates for 5.2 2019-05-09 08:40:55 -07:00
c6x audit/stable-5.2 PR 20190507 2019-05-07 19:06:04 -07:00
csky DMA mapping updates for 5.2 2019-05-09 08:40:55 -07:00
h8300 audit/stable-5.2 PR 20190507 2019-05-07 19:06:04 -07:00
hexagon audit/stable-5.2 PR 20190507 2019-05-07 19:06:04 -07:00
ia64 Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2019-05-07 22:03:58 -07:00
m68k audit/stable-5.2 PR 20190507 2019-05-07 19:06:04 -07:00
microblaze audit/stable-5.2 PR 20190507 2019-05-07 19:06:04 -07:00
mips We have a couple new features and changes in the core clk framework this time 2019-05-09 14:50:09 -07:00
nds32 audit/stable-5.2 PR 20190507 2019-05-07 19:06:04 -07:00
nios2 audit/stable-5.2 PR 20190507 2019-05-07 19:06:04 -07:00
openrisc audit/stable-5.2 PR 20190507 2019-05-07 19:06:04 -07:00
parisc Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2019-05-07 22:03:58 -07:00
powerpc powerpc/mm/hash: Fix get_region_id() for invalid addresses 2019-05-17 22:57:40 +10:00
riscv audit/stable-5.2 PR 20190507 2019-05-07 19:06:04 -07:00
s390 audit/stable-5.2 PR 20190507 2019-05-07 19:06:04 -07:00
sh Pin control changes for v5.2: 2019-05-08 10:23:54 -07:00
sparc sparc64: simplify reduce_memory() function 2019-05-09 14:26:17 -07:00
um Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2019-05-07 22:03:58 -07:00
unicore32 audit/stable-5.2 PR 20190507 2019-05-07 19:06:04 -07:00
x86 Merge branch 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security 2019-05-09 12:54:40 -07:00
xtensa Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2019-05-07 22:03:58 -07:00
.gitignore
Kconfig Merge branch 'x86-mm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2019-05-06 16:13:31 -07:00