Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2360603rwb; Mon, 19 Sep 2022 04:06:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7/meR/vNUbd/LS2UnaQR8xjh/DARYgpBOKY01qMp+8wp8umu9b1iNWWE8AGPeVnY2lEOoX X-Received: by 2002:a17:907:2da2:b0:77c:1599:b3ad with SMTP id gt34-20020a1709072da200b0077c1599b3admr11960560ejc.213.1663585596837; Mon, 19 Sep 2022 04:06:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663585596; cv=none; d=google.com; s=arc-20160816; b=J0s0Um8YHIkGS7w3HhsQIZIA8BbIYwM2SyJx5M3ux5yFyeGbaDSYYjQht2Y/GTi21L Xhmhzm+rhYPu/1ULQ8cC7JoKlLs/2AKBBNK2MVkLvnGgOVssBj/zq6zvf9kVZh98F8jU PzUYdkeQw0eu7mXNu7EQknwH3AYHuFbVRQUuADGnzW78AtuloSVAeDJcCGmUj4bAgIG/ wYsXtDNIGuBkoD92aBvZtxnsWzOBmrSrSfQpwRxVovQa0BiFjCQzj8m/pEce2A3vAxS3 CMMnK9jSiH1tMiYKt1u8ckEqTrylwSqjIavtwtH+T+THHfpqN30wJ7mZNB88hX5H6LTY O05g== 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 :message-id:date:subject:cc:to:from; bh=IddW3hkPc+5FMwF2om45zGwubxGTpdkb+niWIa4+0ws=; b=R11mHnp1HwKtpxS3uV1xOwxrkahqQhi2q1wGoM9fIwzQgv45FMDFU1sp9RmghTA71r 5XigeT8BU2tlJ5tf5/FQehe5DXkao5RO8FPvhEaz/C2M7dcQcl9a++ec7xeo7vXoqnIr C4GWWvgygMvddtKMTNGr1HUthzMH8FtQ755aZhl9kAsEFC7K712M5gUB3TwUcPsg5RU0 4RvAsGHXZpfv1rgU5ZclZmEeq7/nRsP+QEi0s5vjGciGIVzBbkqSpC8ztTRehdVsfn+1 VWLyqW4gRhM4GkrU7WVNGfUm/SqtKnU+wE2qnmdqdsqXc2NFcwXZvWvkKdmRxaGMKnFs puKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b67-20020a509f49000000b0044c28ad39f8si9105513edf.238.2022.09.19.04.06.11; Mon, 19 Sep 2022 04:06:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229986AbiISKrp (ORCPT + 99 others); Mon, 19 Sep 2022 06:47:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229997AbiISKrD (ORCPT ); Mon, 19 Sep 2022 06:47:03 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E31424F2C for ; Mon, 19 Sep 2022 03:35:00 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MWLb01f9NzpSxm; Mon, 19 Sep 2022 18:32:12 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 19 Sep 2022 18:34:58 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 19 Sep 2022 18:34:58 +0800 From: Kefeng Wang To: Russell King , CC: , Kefeng Wang Subject: [PATCH v2] ARM: mm: Provide better fault message for permission fault Date: Mon, 19 Sep 2022 18:38:45 +0800 Message-ID: <20220919103845.100809-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If there is a permission fault in __do_kernel_fault(), we only print the generic "paging request" message which don't show read, write or excute information, let's provide better fault message for them. Signed-off-by: Kefeng Wang --- v2: fix !CONFIG_MMU built arch/arm/mm/fault.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index 46cccd6bf705..387c87112d80 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -105,6 +105,19 @@ static inline bool is_write_fault(unsigned int fsr) return (fsr & FSR_WRITE) && !(fsr & FSR_CM); } +static inline bool is_permission_fault(unsigned int fsr) +{ + int fs = fsr_fs(fsr); +#ifdef CONFIG_ARM_LPAE + if ((fs & FS_PERM_NOLL_MASK) == FS_PERM_NOLL) + return true; +#else + if (fs == FS_L1_PERM || fs == FS_L2_PERM) + return true; +#endif + return false; +} + static void die_kernel_fault(const char *msg, struct mm_struct *mm, unsigned long addr, unsigned int fsr, struct pt_regs *regs) @@ -137,7 +150,14 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, /* * No handler, we'll have to terminate things with extreme prejudice. */ - if (addr < PAGE_SIZE) { + if (is_permission_fault(fsr)) { + if (fsr & FSR_WRITE) + msg = "write to read-only memory"; + else if (fsr & FSR_LNX_PF) + msg = "execute from non-executable memory"; + else + msg = "read from unreadable memory"; + } else if (addr < PAGE_SIZE) { msg = "NULL pointer dereference"; } else { if (kfence_handle_page_fault(addr, is_write_fault(fsr), regs)) @@ -204,19 +224,6 @@ void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs) #define VM_FAULT_BADMAP ((__force vm_fault_t)0x010000) #define VM_FAULT_BADACCESS ((__force vm_fault_t)0x020000) -static inline bool is_permission_fault(unsigned int fsr) -{ - int fs = fsr_fs(fsr); -#ifdef CONFIG_ARM_LPAE - if ((fs & FS_PERM_NOLL_MASK) == FS_PERM_NOLL) - return true; -#else - if (fs == FS_L1_PERM || fs == FS_L2_PERM) - return true; -#endif - return false; -} - static vm_fault_t __kprobes __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int flags, unsigned long vma_flags, struct pt_regs *regs) -- 2.35.3