Commit 5042d40a authored by Andy Lutomirski's avatar Andy Lutomirski Committed by Borislav Petkov
Browse files

x86/fault: Bypass no_context() for implicit kernel faults from usermode



Drop an indentation level and remove the last user_mode(regs) == true
caller of no_context() by directly OOPSing for implicit kernel faults
from usermode.

Signed-off-by: default avatarAndy Lutomirski <luto@kernel.org>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/6e3d1129494a8de1e59d28012286e3a292a2296e.1612924255.git.luto@kernel.org
parent 2cc624b0
Loading
Loading
Loading
Loading
+32 −27
Original line number Diff line number Diff line
@@ -826,9 +826,19 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
{
	struct task_struct *tsk = current;

	/* User mode accesses just cause a SIGSEGV */
	if (user_mode(regs) && (error_code & X86_PF_USER)) {
	if (!user_mode(regs)) {
		no_context(regs, error_code, address, pkey, si_code);
		return;
	}

	if (!(error_code & X86_PF_USER)) {
		/* Implicit user access to kernel memory -- just oops */
		page_fault_oops(regs, error_code, address);
		return;
	}

	/*
	 * User mode accesses just cause a SIGSEGV.
	 * It's possible to have interrupts off here:
	 */
	local_irq_enable();
@@ -859,11 +869,6 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
	force_sig_fault(SIGSEGV, si_code, (void __user *)address);

	local_irq_disable();

		return;
	}

	no_context(regs, error_code, address, SIGSEGV, si_code);
}

static noinline void