Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp623524pxv; Thu, 15 Jul 2021 11:48:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzM0iE52gStnVXDPZGvWf2Vu7vIUqGB0ta/5q9Ng7YHtuOqerNE6q/j9LDtYq3Aw8El0/uI X-Received: by 2002:a05:6638:1507:: with SMTP id b7mr5193092jat.23.1626374926588; Thu, 15 Jul 2021 11:48:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626374926; cv=none; d=google.com; s=arc-20160816; b=pqzAH9n1Y3lEqstvkVvJmAV2dw2088be1H44/bQuoST0iazFM1hhv5IzqFvao+ccu2 COq5gp4fo5sxG25s/aMpV3rxxwT2f+IUx+Jdc5SQmR79HDHzHUqI6pDjjV/o7IyM/pOj iRbU+fJ1Hg9ouU+zYYVYVbPXeVfYzo9e+WeVw0r5aoCQnuFgTLxHtmJvzkYc0tzNFTL5 W8X45Xmb5UM9qCuMolvl/BDQk5hp1Qs67y5sdONU9Z97pzBsZSWFzqsMHJLkOP+NJvp/ 4uX4ctLzglUwqRz8zyrtmw6rEcXHWHqksCtxFFr3zLLOOCR3KeXW8D2yiXomhS5sMvmd B6Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dmx9VeUYdUmApl+NIjhITNwKvgCh7XO5mfFLxyCI7us=; b=fW4qwklZO8RwwkSgcPwHCBOjzi4e7vO7DgjnqrXUtIbj69KNIKKsDZOUpLsZZSnTbV lPyREljaX4/28qN9ubQW6M3L5BXWlfSCrW3RIGX5UaqbenlI/vsfIzU54oO5y6DSK9M3 3bQ/hccK9AijHeTy5VrWHN/uVkcCFdRh1D1M7ya5Go7sElyc6LV8Qc910RSWoU0s5uFE cy1AtTqTs4qkqklkVScqis9juKndfb4f1GTXIcAgJG1jKCJ/kjbLWvYeMFFEm3TAH28I OA2cAr5ClPII6Seo66KnwTJKkNeFTpYWdZO29Z5Ye7zAKVaNC7M70OmaKEQmHPQvmJxF zK6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=e5hvPNOK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z9si7712759ilu.28.2021.07.15.11.48.34; Thu, 15 Jul 2021 11:48:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=e5hvPNOK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238823AbhGOSus (ORCPT + 99 others); Thu, 15 Jul 2021 14:50:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:50488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231909AbhGOSsL (ORCPT ); Thu, 15 Jul 2021 14:48:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A4053613DC; Thu, 15 Jul 2021 18:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626374717; bh=rRgGUBtC8e5iWP6z2UuSrbfBofkMNhqD5H2aRwgKGOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e5hvPNOK+3C7DDzS51GpdNAFGnPyMY19nuEhRVduP5KvHxXH2PIueuNlnmV+I0qm6 q7QnRtu+M5YvMs/UcTud6gt/LFIALRWdIjqXlAUYKg5W9Y46+HrVNBGwIxuxIfL1bN H6BHx+SCU95MOA5WrwlRCfq7woIESXOuuaB6iA3U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe Leroy , Nicholas Piggin , Michael Ellerman Subject: [PATCH 5.4 075/122] powerpc/mm: Fix lockup on kernel exec fault Date: Thu, 15 Jul 2021 20:38:42 +0200 Message-Id: <20210715182509.668484209@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182448.393443551@linuxfoundation.org> References: <20210715182448.393443551@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe Leroy commit cd5d5e602f502895e47e18cd46804d6d7014e65c upstream. The powerpc kernel is not prepared to handle exec faults from kernel. Especially, the function is_exec_fault() will return 'false' when an exec fault is taken by kernel, because the check is based on reading current->thread.regs->trap which contains the trap from user. For instance, when provoking a LKDTM EXEC_USERSPACE test, current->thread.regs->trap is set to SYSCALL trap (0xc00), and the fault taken by the kernel is not seen as an exec fault by set_access_flags_filter(). Commit d7df2443cd5f ("powerpc/mm: Fix spurious segfaults on radix with autonuma") made it clear and handled it properly. But later on commit d3ca587404b3 ("powerpc/mm: Fix reporting of kernel execute faults") removed that handling, introducing test based on error_code. And here is the problem, because on the 603 all upper bits of SRR1 get cleared when the TLB instruction miss handler bails out to ISI. Until commit cbd7e6ca0210 ("powerpc/fault: Avoid heavy search_exception_tables() verification"), an exec fault from kernel at a userspace address was indirectly caught by the lack of entry for that address in the exception tables. But after that commit the kernel mainly relies on KUAP or on core mm handling to catch wrong user accesses. Here the access is not wrong, so mm handles it. It is a minor fault because PAGE_EXEC is not set, set_access_flags_filter() should set PAGE_EXEC and voila. But as is_exec_fault() returns false as explained in the beginning, set_access_flags_filter() bails out without setting PAGE_EXEC flag, which leads to a forever minor exec fault. As the kernel is not prepared to handle such exec faults, the thing to do is to fire in bad_kernel_fault() for any exec fault taken by the kernel, as it was prior to commit d3ca587404b3. Fixes: d3ca587404b3 ("powerpc/mm: Fix reporting of kernel execute faults") Cc: stable@vger.kernel.org # v4.14+ Signed-off-by: Christophe Leroy Acked-by: Nicholas Piggin Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/024bb05105050f704743a0083fe3548702be5706.1625138205.git.christophe.leroy@csgroup.eu Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/mm/fault.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -204,9 +204,7 @@ static bool bad_kernel_fault(struct pt_r { int is_exec = TRAP(regs) == 0x400; - /* NX faults set DSISR_PROTFAULT on the 8xx, DSISR_NOEXEC_OR_G on others */ - if (is_exec && (error_code & (DSISR_NOEXEC_OR_G | DSISR_KEYFAULT | - DSISR_PROTFAULT))) { + if (is_exec) { pr_crit_ratelimited("kernel tried to execute %s page (%lx) - exploit attempt? (uid: %d)\n", address >= TASK_SIZE ? "exec-protected" : "user", address,