Skip to content

Commit

Permalink
cxl: Fix DAR check & use REGION_ID instead of opencoding
Browse files Browse the repository at this point in the history
commit 3b1dbfa upstream.

The current code will set _PAGE_USER to the access flags for any
fault address, because the ~ operation will be true for all address we
take a fault on. But setting _PAGE_USER also means that the fault will
be handled only if the page table have _PAGE_USER set. Hence there is
no security hole with the current code.

Now if it is an user space access, then the change in this patch really
don't have an impact because we have (!ctx->kernel) set true
and we take the if condition true.

Now kernel context created fault on an address in the kernel range
will result in a fault loop because we will not insert the
hash pte due to access and pte permission mismatch. This patch fix
the above issue.

Fixes: f204e0b ("cxl: Driver code for powernv PCIe based cards for userspace access")
Reviewed-by: Andrew Donnellan <[email protected]>
Acked-by: Ian Munsie <[email protected]>
Signed-off-by: Aneesh Kumar K.V <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Lee Jones <[email protected]>
Change-Id: I5d3befde00053339f66db312fae6233ed55f2027
  • Loading branch information
kvaneesh authored and Lee Jones committed May 30, 2020
1 parent cc5484b commit 0c87729
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/misc/cxl/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static void cxl_handle_page_fault(struct cxl_context *ctx,
access = _PAGE_PRESENT;
if (dsisr & CXL_PSL_DSISR_An_S)
access |= _PAGE_RW;
if ((!ctx->kernel) || ~(dar & (1ULL << 63)))
if ((!ctx->kernel) || (REGION_ID(dar) == USER_REGION_ID))
access |= _PAGE_USER;
local_irq_save(flags);
hash_page_mm(mm, dar, access, 0x300);
Expand Down

0 comments on commit 0c87729

Please sign in to comment.