Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp384574ybb; Wed, 8 Apr 2020 01:36:43 -0700 (PDT) X-Google-Smtp-Source: APiQypL7fJ/z9qj/92vEuC8OCrGBATw73q3j8gpN2e8ujk24BfMYXlkuRA6THBGQVmM2+P0opjjo X-Received: by 2002:a4a:c315:: with SMTP id c21mr5103994ooq.13.1586335003175; Wed, 08 Apr 2020 01:36:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586335003; cv=none; d=google.com; s=arc-20160816; b=WwQ7ZW0LuiBnx8bLTlH3QVPlQc8w5rncYm9PPXE/K4gsYLmici+xa4UZ/TnNQoXA2c cjLIQU43X/uIPkNe25FRa3y+Jbq5+7Cpqp/ZEdghYoNjGOOQmxaWeoccLSjhb9FQ9xQM k5HwkbPFipNZUMo9S6QWF44Zxfm4+Vl+hlwctW8YFtKM1JgxMRs44eHScfFI3VQ8sovx p/HEYznPz3Ru5avSpD7GXW5pG4IQB9xTn2twP8PSdIXeSUrfSjXYpz5fDrVx3rJp2DSO qr/5m5bq45jTFChRAWsNJH2rVUUDbt1PWa0dyHLyuD9RH0gWFtVHUwaHCQ6oXP2q9CH6 rdxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=R5l9yaDnHPviFSInTMtO+H9cjGUVnhLTSkCrNG5sx0k=; b=L4wmwQeavTRbK6zJOSSQXlKaOnEATrPE6/ZJx8E2Tk3d/O+IIz+uQx+9sKdGigfF0a 578kMjzUXs2WtuVovCEY9kpAoCOss0jSy5XnNQjW2LocxABKMUqkhXu/+4z3hoNC8xNr TSZG+X/w5gzHwAwEgyUeYL/1CX8Y+4nj1f+ZCBUa1p05+JXLjn3f39D4u43ItOQY2VZw iMLO0ETdDaekpp9zr9o8gP4Ii7bedI/Fs13zsN3vK5LrJJQCf4JxDAb4cTIE16IcNfUU Dd1bNYU1Q6A5AOXcJBGbQ17qkeH1I85TcMpQ2X8vntiL1FOhn6vGo8nOhPBQasScTiAf IdiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=hsIE8Vof; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s139si2160753oih.7.2020.04.08.01.36.16; Wed, 08 Apr 2020 01:36:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=hsIE8Vof; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726910AbgDHH5K (ORCPT + 99 others); Wed, 8 Apr 2020 03:57:10 -0400 Received: from mail-pj1-f65.google.com ([209.85.216.65]:55179 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726650AbgDHH5K (ORCPT ); Wed, 8 Apr 2020 03:57:10 -0400 Received: by mail-pj1-f65.google.com with SMTP id np9so842712pjb.4 for ; Wed, 08 Apr 2020 00:57:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=R5l9yaDnHPviFSInTMtO+H9cjGUVnhLTSkCrNG5sx0k=; b=hsIE8Vof28DJJncFl3vY8jPdw0T1oKCjs5IiYyxl69aiOHSiFTj0bX1wenWPJ3kJRJ iIj07JLR0wgA6ZytV1SzqwxkatW3ZHpuqQIIFgLjLm9YXf1otQUmRJfab1OAWw59S6p2 RgWZljcud7M27JOTSdcvfdaQd+QNYcK78ifndNxpxIe7UmfEP2abrFi0CblVWumtA3Fe bxHimMyQBCPLy92QZtfcnT6uyM6JDpXPllxJlmdPPfzmrKECAIIsIFelasO0muZUKILY TA0QJ0589Dv1hXf2bIXA4h4y3D99sHzzLVQa4oS+//ptAKKDuPF7i7l9DbG2rMNzjz7C jTyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=R5l9yaDnHPviFSInTMtO+H9cjGUVnhLTSkCrNG5sx0k=; b=S92SAaF67DGcpiRNDS3FezNfnCHLNpN3HRRHknj5Nt3nF4QTCYVMkgRkewZ7h/oQaU 7x5N0q2wI8ZGwjK9H8iBDV9/tQgAbD+FubC67r0UDK55a49dhNVM5OUAdLPN4QLd8UWB jC6rU/sn+MB3ShNAosIbnGkS2vTL3RTN2dQM5uK8TbwZcRPMbETjJYw/EbUFdARTmOp0 b6sOYspoYm0ztv0kK6GwLCJsOUKA20R9tnSmTgBRxmlWIrP64+YEODB23k9Of+n80WDV 0KDcnZFIMrYUWdPXxqcNsRTPWWn2CVTA01ZSw0OeF1qRqnvvYZn6QH372TT4775gzvh9 QJhA== X-Gm-Message-State: AGi0PuZnreaaUMrvbiQ/D84UlltKb5gzqCHfs6x6w/SE1bc/yLr5UpoV JcesrzvZoZ/9QAnZ2Zwrb4Y1gQ== X-Received: by 2002:a17:902:8e84:: with SMTP id bg4mr5738299plb.50.1586332629297; Wed, 08 Apr 2020 00:57:09 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id d85sm485599pfd.157.2020.04.08.00.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2020 00:57:08 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, mhiramat@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Zong Li Subject: [PATCH v5 0/9] Support strict kernel memory permissions for security Date: Wed, 8 Apr 2020 15:56:55 +0800 Message-Id: X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The main purpose of this patch series is changing the kernel mapping permission , make sure that code is not writeable, data is not executable, and read-only data is neither writable nor executable. This patch series also supports the relevant implementations such as ARCH_HAS_SET_MEMORY, ARCH_HAS_SET_DIRECT_MAP, ARCH_SUPPORTS_DEBUG_PAGEALLOC and DEBUG_WX. Changes in v5: - Add lockdep_assert_held and more comments for text_mutex. Changes in v4: - Use NOKPROBE_SYMBOL instead of __kprobe annotation - Use text_mutex instead of patch_lock - Remove 'riscv_' prefix of function name Changes in v3: - Fix build error on nommu configuration. We already support nommu on RISC-V, so we should consider nommu case and test not only rv32/64, but also nommu. Changes in v2: - Use _data to specify the start of data section with write permission. - Change ftrace patch text implementaion. - Separate DEBUG_WX patch to another patchset. Zong Li (9): riscv: add macro to get instruction length riscv: introduce interfaces to patch kernel code riscv: patch code by fixmap mapping riscv: add ARCH_HAS_SET_MEMORY support riscv: add ARCH_HAS_SET_DIRECT_MAP support riscv: add ARCH_SUPPORTS_DEBUG_PAGEALLOC support riscv: move exception table immediately after RO_DATA riscv: add alignment for text, rodata and data sections riscv: add STRICT_KERNEL_RWX support arch/riscv/Kconfig | 6 + arch/riscv/include/asm/bug.h | 8 ++ arch/riscv/include/asm/fixmap.h | 2 + arch/riscv/include/asm/patch.h | 12 ++ arch/riscv/include/asm/set_memory.h | 48 +++++++ arch/riscv/kernel/Makefile | 4 +- arch/riscv/kernel/ftrace.c | 26 ++-- arch/riscv/kernel/patch.c | 128 +++++++++++++++++++ arch/riscv/kernel/traps.c | 3 +- arch/riscv/kernel/vmlinux.lds.S | 11 +- arch/riscv/mm/Makefile | 2 +- arch/riscv/mm/init.c | 44 +++++++ arch/riscv/mm/pageattr.c | 187 ++++++++++++++++++++++++++++ 13 files changed, 466 insertions(+), 15 deletions(-) create mode 100644 arch/riscv/include/asm/patch.h create mode 100644 arch/riscv/include/asm/set_memory.h create mode 100644 arch/riscv/kernel/patch.c create mode 100644 arch/riscv/mm/pageattr.c -- 2.26.0