From patchwork Thu Nov 12 06:48:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 11899183 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D36571391 for ; Thu, 12 Nov 2020 06:44:35 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 85D78208FE for ; Thu, 12 Nov 2020 06:44:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="glf/XL4I" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85D78208FE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=ozz+t86Lt90pLjbxfSWJnEf8ssXydvfdJ89Lv7HBL+4=; b=glf/XL4IrtQwGjqfCQ4hP1tDnM noLPaXz8BPwAMaxaLeuGB1gWOMnbFfTw9yVS9EayalW9XJA5fpCYcA6o+LftKc3oyClE4W/1uJJeO XpFl9+lZdzNjsi6oHg0CkA9WrnhHIL1wR+kU9fRB6r24i9UFE1lMz+ER9LwFfxJq/FpKK6T3lfvy2 Ip9QTVi/Hh0ItXRXn8XPanTFEv6gMK7OevPkEtmGhrULewr7EJuLZwo6THDeHrxSt36fWPVlF/sEY /Hr0eDEPqKGk/jO1mhk+C/niCWGI2ZMqMvddDRGv1ltmb3BYJIwEO/ispMV8h+yfR3Xm8oPhxT76B qZPOPmMQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kd6L2-0002gI-Un; Thu, 12 Nov 2020 06:44:09 +0000 Received: from szxga04-in.huawei.com ([45.249.212.190]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kd6Kz-0002fS-4p for linux-riscv@lists.infradead.org; Thu, 12 Nov 2020 06:44:06 +0000 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CWsWR0qCbzkj6r; Thu, 12 Nov 2020 14:43:47 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Thu, 12 Nov 2020 14:43:49 +0800 From: Kefeng Wang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Subject: [PATCH] riscv: Fix W+X mapping warning Date: Thu, 12 Nov 2020 14:48:55 +0800 Message-ID: <20201112064855.99578-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201112_014405_501541_D3979237 X-CRM114-Status: UNSURE ( 9.17 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.190 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [45.249.212.190 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kefeng Wang , Zong Li Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org When boot with DEBUG_WX triggers the WX warning, riscv/mm: Found insecure W+X mapping at address ffffffe000000000/0xffffffe000000000 WARNING: CPU: 1 PID: 1 at arch/riscv/mm/ptdump.c:236 note_page+0x248/0x25a ... Checked W+X mappings: failed, 512 W+X pages found The kernel_page_tables shows first 2M(kernel image) is with W attribute, Use _start instead of text_start in mark_rodata_ro(). Before, 0xffffffe000000000-0xffffffe000200000 0x0000000080200000 2M PMD D A . . X W R V 0xffffffe000200000-0xffffffe000a00000 0x0000000080400000 8M PMD D A . . X . R V 0xffffffe000a00000-0xffffffe001000000 0x0000000080c00000 6M PMD D A . . . . R V 0xffffffe001000000-0xffffffe17fe00000 0x0000000081200000 6126M PMD D A . . . W R V After, 0xffffffe000000000-0xffffffe000a00000 0x0000000080200000 10M PMD D A . . X . R V 0xffffffe000a00000-0xffffffe001000000 0x0000000080c00000 6M PMD D A . . . . R V 0xffffffe001000000-0xffffffe17fe00000 0x0000000081200000 6126M PMD D A . . . W R V Signed-off-by: Kefeng Wang --- arch/riscv/mm/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 1d330bde9cf1..d739a46d9fc4 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -624,13 +624,13 @@ static inline void setup_vm_final(void) #ifdef CONFIG_STRICT_KERNEL_RWX void mark_rodata_ro(void) { - unsigned long text_start = (unsigned long)_text; + unsigned long start = (unsigned long)_start; unsigned long text_end = (unsigned long)_etext; unsigned long rodata_start = (unsigned long)__start_rodata; unsigned long data_start = (unsigned long)_data; unsigned long max_low = (unsigned long)(__va(PFN_PHYS(max_low_pfn))); - set_memory_ro(text_start, (text_end - text_start) >> PAGE_SHIFT); + set_memory_ro(start, (text_end - start) >> PAGE_SHIFT); set_memory_ro(rodata_start, (data_start - rodata_start) >> PAGE_SHIFT); set_memory_nx(rodata_start, (data_start - rodata_start) >> PAGE_SHIFT); set_memory_nx(data_start, (max_low - data_start) >> PAGE_SHIFT);