Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp504643rdh; Wed, 14 Feb 2024 03:36:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV5wW6lvsbswZ9gGgbGGqIGY0xttMTftNEdLhXs8WDRNwF5gwbUWLyRta0GUJS/Vm40cXyT8cZFEryrYHEP28e86dfLCleGiyaiLAuAOA== X-Google-Smtp-Source: AGHT+IFfThnUI3OzLSKSVvx0voNyc/qL2ujhsa1KBEW7CJRjnNWLWxWc7TyxJWH947SaUahX4mwY X-Received: by 2002:a17:906:6bcd:b0:a3c:1d36:62c9 with SMTP id t13-20020a1709066bcd00b00a3c1d3662c9mr1560680ejs.73.1707910564896; Wed, 14 Feb 2024 03:36:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707910564; cv=pass; d=google.com; s=arc-20160816; b=hN0P63zYYXhymvyq2oojchCGf1xhpT39VecgxHhelkizvQbciZ7qLcji3Ys7tcJygW gNqXx8oNuooqgCEwK66hF3qgYtCXlhHa/9z2yFFO+QMUE/vSu6xTp+X+3HHwWaIoDb5Q LyA2cEp1Inc4BgnW/wXRYnlTTzi+ca7bLtM3+6qBgbMYzC+3CSkiVjVRrl8d6wL6wOtx kWeDsBLKE2kRMoD67der8y51jvXIZpdF6WTbl3dz7spGEWTRY3E9+ngkMqVrqd1ltcHV +jf2yvOlGpVUn+NhVfFO+SjRuZGyPxQTg12bRosfR+BJ1U6T89lb3tbUqkyAcXm0xOtx X9Qw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=3dBrLBs4VKhU1qw9hvKr2PfTYo7cgYffGT9wuQftxYA=; fh=564Q5PI8voPPGjPArh/M1/5ITA2t3gtK3ve0y8nwnTg=; b=RGK1U9t2uQVlLsIo+/bpGhJ/eYUoew1rYEPN+4K8QG1Q41YQL19Pp97dXgrGSoQSSd B/MGOymhB45xs2RWWjxM3jz0wmjE5UB+Kn13F2FY94yNMRuDjTcBAHgZvZRMd6JOftAC oaoFAj02uOmuf12StFc7yxGNSruEu0BKhU+5jnaS+P2aqT+jDrWNsQriH1Fg27OyPNDq Qo9kZ5HiHG+zvxmCM+PAP18b22dgI+TSWv6DuWZM1OqCmhep3m1RSa392Ce6jxfEdgW2 85o7U1Tcz1jti4X1LAghOZofkMdgbqwZAh+dbKK6/EBL4uhtyrtbi2AE3ugXqtO0xEqp 2dgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-65137-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65137-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVSw18VpFGkdw6fI5fyoyoWJNzUHucQpH0Yef/0lblvzhh8+BFEOajbkj3/TxP76QEaFL3rJgMIkj9jR5mPTXWFTXa0BaQP7/iYUZln8A== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u13-20020a170906c40d00b00a3d48b892d6si484775ejz.66.2024.02.14.03.36.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 03:36:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65137-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-65137-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65137-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A35111F217B8 for ; Wed, 14 Feb 2024 11:36:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B8B019BA2; Wed, 14 Feb 2024 11:35:55 +0000 (UTC) Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB8CA19475; Wed, 14 Feb 2024 11:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=14.137.139.154 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707910554; cv=none; b=AjuwRN5nU4tf20dRE77ZbYzRvpzifN6Bb40btlMs0nkx6VblCI61h9cxcFEWeR5UPbcAHiS7XdZZbGlNc2uPN3Ki0m7G1MCqzYIxMQIP9OqjEfNfJiO3fYBNGBd/mWsltEPYJXznx9mhCPmyYgWmxa+cB8bv6MF1rAs8V4uVDsA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707910554; c=relaxed/simple; bh=eSoQbLlaL9f781kXxig0KToQ/eN3Fw1j108K7hbPQKU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=nhcpVSycnODbY/2W2h3ae4+7qoLr/YPelh0AUrw+48wnmn7KafbsSOi3TlB+aKs/EJSGWB+4j/CR2Q6ZievcTqCwL41ifNiKs1rQiVD7p9cDdU36LYAt7MxqVdyeTJPvhUfcyv+pd3gxvEfCAWLKptFSsnwkCk9YrzxJCjpYEEo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=14.137.139.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.18.186.29]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4TZbHb0dXxz9y62N; Wed, 14 Feb 2024 19:16:43 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.47]) by mail.maildlp.com (Postfix) with ESMTP id 18AF81405F3; Wed, 14 Feb 2024 19:35:40 +0800 (CST) Received: from huaweicloud.com (unknown [10.45.156.69]) by APP1 (Coremail) with SMTP id LxC2BwAHshp7pcxlDJx9Ag--.51624S2; Wed, 14 Feb 2024 12:35:39 +0100 (CET) From: Petr Tesarik To: Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , Andy Lutomirski , Oleg Nesterov , Peter Zijlstra , Xin Li , Arnd Bergmann , Andrew Morton , Rick Edgecombe , Kees Cook , "Masami Hiramatsu (Google)" , Pengfei Xu , Josh Poimboeuf , Ze Gao , "Kirill A. Shutemov" , Kai Huang , David Woodhouse , Brian Gerst , Jason Gunthorpe , Joerg Roedel , "Mike Rapoport (IBM)" , Tina Zhang , Jacob Pan , linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-kernel@vger.kernel.org (open list) Cc: Roberto Sassu , petr@tesarici.cz, Petr Tesarik Subject: [PATCH v1 0/8] x86_64 SandBox Mode arch hooks Date: Wed, 14 Feb 2024 12:35:08 +0100 Message-Id: <20240214113516.2307-1-petrtesarik@huaweicloud.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-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Jr 0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JU-yCJUUUUU= X-CM-SenderInfo: hshw23xhvd2x3n6k3tpzhluzxrxghudrp/ From: Petr Tesarik This patch series implements x86_64 arch hooks for the generic SandBox Mode infrastructure. SandBox Mode on x86_64 is implemented as follows: * The target function runs with CPL 3 (same as user mode) within its own virtual address space. * Interrupt entry/exit paths are modified to let the interrupt handlers always run with kernel CR3 and restore sandbox CR3 when returning to sandbox mode. * To avoid undesirable user mode processing (FPU state, signals, etc.), the value of pt_regs->cs is temporarily adjusted to make it look like coming from kernel mode. * On a CPU fault, execution stops immediately, returning -EFAULT to the caller. Petr Tesarik (8): sbm: x86: page table arch hooks sbm: x86: execute target function on sandbox mode stack sbm: x86: map system data structures into the sandbox sbm: x86: allocate and map an exception stack sbm: x86: handle sandbox mode faults sbm: x86: switch to sandbox mode pages in arch_sbm_exec() sbm: documentation of the x86-64 SandBox Mode implementation sbm: x86: lazy TLB flushing Documentation/security/sandbox-mode.rst | 25 ++ arch/x86/Kconfig | 1 + arch/x86/entry/entry_64.S | 123 ++++++ arch/x86/include/asm/page_64_types.h | 1 + arch/x86/include/asm/ptrace.h | 21 + arch/x86/include/asm/sbm.h | 83 ++++ arch/x86/include/asm/segment.h | 7 + arch/x86/include/asm/thread_info.h | 3 + arch/x86/kernel/Makefile | 2 + arch/x86/kernel/asm-offsets.c | 10 + arch/x86/kernel/sbm/Makefile | 16 + arch/x86/kernel/sbm/call_64.S | 95 +++++ arch/x86/kernel/sbm/core.c | 499 ++++++++++++++++++++++++ arch/x86/kernel/traps.c | 14 +- arch/x86/mm/fault.c | 6 + 15 files changed, 905 insertions(+), 1 deletion(-) create mode 100644 arch/x86/include/asm/sbm.h create mode 100644 arch/x86/kernel/sbm/Makefile create mode 100644 arch/x86/kernel/sbm/call_64.S create mode 100644 arch/x86/kernel/sbm/core.c -- 2.34.1