Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp711969pxv; Thu, 15 Jul 2021 14:10:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx25DAf+Fu+goTYLD6hlaaUzLXaTvyB0lNIYhz0qoB9jvvBawa7VkPW8QHwTvTctmekZvFZ X-Received: by 2002:aa7:d801:: with SMTP id v1mr9722473edq.349.1626383405870; Thu, 15 Jul 2021 14:10:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626383405; cv=none; d=google.com; s=arc-20160816; b=DkeBuvGGaHLOoz+HuMoEChva0fDr16W8zC7YpI29rSWaCNR9S12/aKfR2kW8Y79//J RvtA+uRR5TJCsrbZ4P2wMScY4OTJgl7c+U63BV9eqdcN/RlA2XDFCVYFuqjR5elTN4pQ FFMtCoqCCSmkVj25EyI3nwMRZTf945Z/AI0qwSVfWDISJu5r85OXbWbjFuTa6PHRK+F+ crNP9prlng8KSxB91KglDgBfQudEo70zq/ZBEf/QsaF8vyVdndYfIsWXdHsrZe0Ypu9z CeCITwsK7GLsM/XOQB71yVcX6RuPj5kVwXwESHzoiXsqW2fMw49jhJSR1NZR12BWtVN5 RP5A== 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=ByLGvahZYYD5JwbLzY8JVxtfZvdfyMJc4Gz+KzfVeR4=; b=W6JUkaBUN/p3iluhVY3Z5JAv4fbEu2uccvnpAV6qq/AzK+c+SIX6bbVRotdENet7J8 Zcjqp9BGApfyv7pH7XPlYhtcPVUDTrMkDmHhJGpkQXEa/WnVdbplxfMT84kZfX5HSV5J FpBAZdkK7NpfMVDehcFfDJDy1Xe5vSOXnR2Y2bFfqY+3uSxgMbMcv6kSzzvtXem1PwFo /GVA3p/HbRzmqH6O4KWHxefteBwyBxTVz3rcclcfQXCueq5j+hk5uZJPfHL+MxT2nuJX dC6BydnY2OJtwCQe+3iVzWLrV6yqCuQ0tBD5hNkCAoCyWf4x6yvSZlXOtcrsoqLiC21g uanQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zeY8kVSU; 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 b2si8306920ejc.314.2021.07.15.14.09.43; Thu, 15 Jul 2021 14:10:05 -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=zeY8kVSU; 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 S242827AbhGOTV4 (ORCPT + 99 others); Thu, 15 Jul 2021 15:21:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:38832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231739AbhGOTFr (ORCPT ); Thu, 15 Jul 2021 15:05:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8D0B6613E4; Thu, 15 Jul 2021 19:02:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375727; bh=0sOnFi+karhKZZw+utkVlYFUSfkWjQ00NaCNBYgkLaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zeY8kVSUjno8AUJA5MHOVE0S8HlusrJ0u+mUBAZ1bR8qaLykbB9whZf90RUHEf2Oq BMwx1yaHE2KyTdlb2Ctda7S/tdzdEe7cRtNGmupOCuxwh8dyThG7yQotmrQbJGHJdz CGrjWMzyiUSDoyTOV9sJaYcjn+vDmZqtEgb8k3ck= 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.12 158/242] powerpc/mm: Fix lockup on kernel exec fault Date: Thu, 15 Jul 2021 20:38:40 +0200 Message-Id: <20210715182620.978044435@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@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 @@ -199,9 +199,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,