From patchwork Wed Jan 18 20:10:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 645287 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBBEDC32793 for ; Wed, 18 Jan 2023 20:11:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229767AbjARULI (ORCPT ); Wed, 18 Jan 2023 15:11:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229669AbjARULH (ORCPT ); Wed, 18 Jan 2023 15:11:07 -0500 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6400C3FF21; Wed, 18 Jan 2023 12:11:06 -0800 (PST) Received: by mail-il1-x144.google.com with SMTP id w2so111100ilg.1; Wed, 18 Jan 2023 12:11:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uOiR9hsOKHJTrMtW7FkV/+C4vzLu86o1/FGgQL4ndGw=; b=MP9MEFJx6JPcYQCK2rCpJH9emHNoPNuzy1oUsEJThem9bp6OoZKipVzp+ImVWaKMXZ 1P9ja1sdvtRnLsStiPveQvrz95vpW01qjj9jq4ko2ADB4/Bz+cnx+Nq084G1FwFZ8xcT ZXLR0zjeV+ekRcDRl+0xXlNxuESL7xHQJXiMH+JTfQ+MWzBfXbitsapN0yD3r9WgVO7l JJXPmeWA3tohIMc7/Jqq4wtSkq4SUB+yWIU0XQ5aJOiUFZtkEyYuegCO8rRJugIQae4h jxoMWvUDCbVbGrsEYGSluWELCqr7dHwawOQjBJkfkBMNYCfYAER2ETj9kweF4OFXnupb +Fnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uOiR9hsOKHJTrMtW7FkV/+C4vzLu86o1/FGgQL4ndGw=; b=EGcG1qLkfaEnOsCZMrLYvpytRrZnz08BwBCraxEWe/kicBm61rTEFRx1+IEN+TJ4mO 1abCICvts3yrzjt2zpGiqUKHnjgKvZ/J7hWb2I0/ckLNhLvTWIc+cNPHxdw1XCs2Rj3m T1j66/BPLQm8+Pzb6Nitn/RUtPA4hnOH70mSldK6UdXlMXZYpQVvwg+SZL1cZ8FRGNGr NZU9btjNhQ4Ys3vsEffK0Dzs2XUwuCNHL0/NHlTXCU3HSGoXh2dydkZ6NxpnGWUrg8uQ BwAitSGGIlJxIDvxusad9L3fd50fxW4zy+aJOxlGe5eJkujWhDnQFJX9//v0ENxhQx/+ Fs6Q== X-Gm-Message-State: AFqh2kqvC6IYzjQX+4Zgz03RH2o5ZJPTDBIro+w0wNY4ONxM0iQhTCcZ B47oob4tycPSu6CTGoS8A3hb9FDf0vsZ X-Google-Smtp-Source: AMrXdXuV8/yEJAdwese/wVzl4a1ZLYcALHuWn2qnkhWlb2o9Q9QsRzofUbqpleJ5rGD4dRf3Jv0Auw== X-Received: by 2002:a92:d07:0:b0:30e:dfcf:3b76 with SMTP id 7-20020a920d07000000b0030edfcf3b76mr6499328iln.15.1674072665701; Wed, 18 Jan 2023 12:11:05 -0800 (PST) Received: from fedora.mshome.net ([104.184.156.161]) by smtp.gmail.com with ESMTPSA id i5-20020a92c945000000b0030bfbc121a1sm10299998ilq.79.2023.01.18.12.11.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 12:11:05 -0800 (PST) From: Gregory Price X-Google-Original-From: Gregory Price To: linux-kernel@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, krisman@collabora.com, tglx@linutronix.de, luto@kernel.org, oleg@redhat.com, peterz@infradead.org, ebiederm@xmission.com, akpm@linux-foundation.org, adobriyan@gmail.com, corbet@lwn.net, shuah@kernel.org, Gregory Price Subject: [PATCH 1/3] ptrace,syscall_user_dispatch: Implement Syscall User Dispatch Suspension Date: Wed, 18 Jan 2023 15:10:53 -0500 Message-Id: <20230118201055.147228-2-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118201055.147228-1-gregory.price@memverge.com> References: <20230118201055.147228-1-gregory.price@memverge.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Adds PTRACE_O_SUSPEND_SYSCALL_USER_DISPATCH to ptrace options, and modify Syscall User Dispatch to suspend interception when enabled. This is modeled after the SUSPEND_SECCOMP feature, which suspends SECCOMP interposition. Without doing this, software like CRIU will inject system calls into a process and be intercepted by Syscall User Dispatch, either causing a crash (due to blocked signals) or the delivery of those signals to a ptracer (not the intended behavior). Since Syscall User Dispatch is not a privileged feature, a check for permissions is not required, however attempting to set this option when CONFIG_CHECKPOINT_RESTORE it not supported should be disallowed, as its intended use is checkpoint/resume. Signed-off-by: Gregory Price --- include/linux/ptrace.h | 2 ++ include/uapi/linux/ptrace.h | 6 +++++- kernel/entry/syscall_user_dispatch.c | 5 +++++ kernel/ptrace.c | 5 +++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h index eaaef3ffec22..461ae5c99d57 100644 --- a/include/linux/ptrace.h +++ b/include/linux/ptrace.h @@ -45,6 +45,8 @@ extern int ptrace_access_vm(struct task_struct *tsk, unsigned long addr, #define PT_EXITKILL (PTRACE_O_EXITKILL << PT_OPT_FLAG_SHIFT) #define PT_SUSPEND_SECCOMP (PTRACE_O_SUSPEND_SECCOMP << PT_OPT_FLAG_SHIFT) +#define PT_SUSPEND_SYSCALL_USER_DISPATCH \ + (PTRACE_O_SUSPEND_SYSCALL_USER_DISPATCH << PT_OPT_FLAG_SHIFT) extern long arch_ptrace(struct task_struct *child, long request, unsigned long addr, unsigned long data); diff --git a/include/uapi/linux/ptrace.h b/include/uapi/linux/ptrace.h index 195ae64a8c87..ba9e3f19a22c 100644 --- a/include/uapi/linux/ptrace.h +++ b/include/uapi/linux/ptrace.h @@ -146,9 +146,13 @@ struct ptrace_rseq_configuration { /* eventless options */ #define PTRACE_O_EXITKILL (1 << 20) #define PTRACE_O_SUSPEND_SECCOMP (1 << 21) +#define PTRACE_O_SUSPEND_SYSCALL_USER_DISPATCH (1 << 22) #define PTRACE_O_MASK (\ - 0x000000ff | PTRACE_O_EXITKILL | PTRACE_O_SUSPEND_SECCOMP) + 0x000000ff | \ + PTRACE_O_EXITKILL | \ + PTRACE_O_SUSPEND_SECCOMP | \ + PTRACE_O_SUSPEND_SYSCALL_USER_DISPATCH) #include diff --git a/kernel/entry/syscall_user_dispatch.c b/kernel/entry/syscall_user_dispatch.c index 0b6379adff6b..7607f4598dd8 100644 --- a/kernel/entry/syscall_user_dispatch.c +++ b/kernel/entry/syscall_user_dispatch.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -36,6 +37,10 @@ bool syscall_user_dispatch(struct pt_regs *regs) struct syscall_user_dispatch *sd = ¤t->syscall_dispatch; char state; + if (IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) && + unlikely(current->ptrace & PT_SUSPEND_SYSCALL_USER_DISPATCH)) + return false; + if (likely(instruction_pointer(regs) - sd->offset < sd->len)) return false; diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 54482193e1ed..a6ad815bd4be 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -370,6 +370,11 @@ static int check_ptrace_options(unsigned long data) if (data & ~(unsigned long)PTRACE_O_MASK) return -EINVAL; + if (unlikely(data & PTRACE_O_SUSPEND_SYSCALL_USER_DISPATCH)) { + if (!IS_ENABLED(CONFIG_CHECKPOINT_RESTART)) + return -EINVAL; + } + if (unlikely(data & PTRACE_O_SUSPEND_SECCOMP)) { if (!IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) || !IS_ENABLED(CONFIG_SECCOMP)) From patchwork Wed Jan 18 20:10:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 643915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74FBDC38147 for ; Wed, 18 Jan 2023 20:11:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbjARULU (ORCPT ); Wed, 18 Jan 2023 15:11:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbjARULM (ORCPT ); Wed, 18 Jan 2023 15:11:12 -0500 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80F865DC15; Wed, 18 Jan 2023 12:11:10 -0800 (PST) Received: by mail-il1-x142.google.com with SMTP id o15so81895ill.11; Wed, 18 Jan 2023 12:11:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fqgqlvxl2/AjHmd8bF7KdCJg7y96KUb9pTAZ52R5/2g=; b=bdrvtx5ZNhgIk9MmhFukQ/LPkMhBhfAROXqqep7fDgGl3OA8JifOfMctbfukQx85JG 07Jfp9smBT8tMrHecHqxzm1W5SqERHQekZm6Am19mR/lb7pai0hkqsQXkL8cPjfqnPD6 j2gR6LVkL89vjpWKYGGjfDt7cSemJgE5/vORS9PEpLXQJCkwqemjGVAHRyzPVEtapADa 5MSRaZ28BuVhOZIGctLicIlYVz0oBmZlsctPpKfFYVIJGvqETPofsTc4yNaPl3isfpYo puDeV9j19qqVYnoRT9o7Ezhq1ucG1hDr6Ngn56nPtTLzaFk7MlsERx37m/1TdFuJhC/2 NGXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fqgqlvxl2/AjHmd8bF7KdCJg7y96KUb9pTAZ52R5/2g=; b=2FI4EOuiZhMN+nhw8i9X62jC7qFKGb0K4Utz5SVhIVvkSLwxbnZz2kvjGWeoOMZgkU Tj8fkRj9PfBXxJjileOrSOTSrSQOWRgFuYMqNttkdV3Db6fw/bVqjyzORQelWwZHmR/B kkfuHIy4boOob83Dn+Gw/bVaxUHL4uXYqg4cTMKXEJI2/2w4X3JU5q+fr6BzZwCevgGw Mpu8TJVdk27MY8i12fE1nl9wdlbdhNp1kKvqTVPa7rdw51MAdRUMa6AS7W2s7fn4Lmd0 vHRcaG136o/FJGlhwF9W06gh+sDAO9LbohHLMHwRWIQ0FUUj78ihyBOrLlqA7f8ctUBa y9/A== X-Gm-Message-State: AFqh2koXDOImSWx8dJZs2l61WyXyHiisFyagA5VD+skAgVylB4cJ/SCG fCvY6TPbja3uK2B49ntgCX4BdPYR7+kq X-Google-Smtp-Source: AMrXdXs65z3mHMdccDSgpcyzyox+lwVkGOM8Ivj9ALWa7rq82jvgbCrnDGVjJrWFMLOuPbugow67oA== X-Received: by 2002:a05:6e02:2186:b0:30f:3704:3e18 with SMTP id j6-20020a056e02218600b0030f37043e18mr2022430ila.25.1674072669393; Wed, 18 Jan 2023 12:11:09 -0800 (PST) Received: from fedora.mshome.net ([104.184.156.161]) by smtp.gmail.com with ESMTPSA id i5-20020a92c945000000b0030bfbc121a1sm10299998ilq.79.2023.01.18.12.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 12:11:09 -0800 (PST) From: Gregory Price X-Google-Original-From: Gregory Price To: linux-kernel@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, krisman@collabora.com, tglx@linutronix.de, luto@kernel.org, oleg@redhat.com, peterz@infradead.org, ebiederm@xmission.com, akpm@linux-foundation.org, adobriyan@gmail.com, corbet@lwn.net, shuah@kernel.org, Gregory Price Subject: [PATCH 2/3] fs/proc/array: Add Syscall User Dispatch to proc status Date: Wed, 18 Jan 2023 15:10:54 -0500 Message-Id: <20230118201055.147228-3-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118201055.147228-1-gregory.price@memverge.com> References: <20230118201055.147228-1-gregory.price@memverge.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org If a dispatch selector has been configured for Syscall User Dispatch, report Syscall User Dispath as configured in proc/status. This provides an indicator to userland checkpoint/restart software that it much manage special signal conditions (similar to SECCOMP) Signed-off-by: Gregory Price --- fs/proc/array.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/proc/array.c b/fs/proc/array.c index 49283b8103c7..c85cdb4c137c 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -428,6 +428,13 @@ static inline void task_thp_status(struct seq_file *m, struct mm_struct *mm) seq_printf(m, "THP_enabled:\t%d\n", thp_enabled); } +static inline void task_syscall_user_dispatch(struct seq_file *m, + struct task_struct *p) +{ + seq_put_decimal_ull(m, "\nSyscall_user_dispatch:\t", + (p->syscall_dispatch.selector != NULL)); +} + int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task) { @@ -451,6 +458,7 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, task_cpus_allowed(m, task); cpuset_task_status_allowed(m, task); task_context_switch_counts(m, task); + task_syscall_user_dispatch(m, task); return 0; } From patchwork Wed Jan 18 20:10:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 645286 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01C6DC32793 for ; Wed, 18 Jan 2023 20:11:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229969AbjARUL2 (ORCPT ); Wed, 18 Jan 2023 15:11:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbjARULU (ORCPT ); Wed, 18 Jan 2023 15:11:20 -0500 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B59EA5DC26; Wed, 18 Jan 2023 12:11:13 -0800 (PST) Received: by mail-il1-x142.google.com with SMTP id m7so94659ilh.7; Wed, 18 Jan 2023 12:11:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YIxZYj7eSsuia8WbIjlSg4jlVWCI9wmpVpaDv9bWJuY=; b=b/AJv+Yz0q1aHUoMexookxY52jz6rwrer8JQEwBvKM1OA3S8B1iAt/vGbraek60Efa 4bN+I1rpbmNvvFi4xek9qblY+FR8M7LVJGAu5UU0mJA+blgMSkr9P9oSzaXOWEvlPRNR SJwWaWuU6S971nI/1hrRhp0UhDpHN66C3wleauxdWY54REHxx9dC67Adihyeo3hzxmRR jbcVfYulxn7lou8AD8k/pL/DgklVSsLK7yGdUUvjvzhlPHZeZfiiEhENL4K0dTadp3/5 6F0dVURwDmnIGZzhJR1wpeeZ2ZeJYanVT23L6jefBkdLHea0/Y7xC+LdtGIqR/QCb0Yp lOdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YIxZYj7eSsuia8WbIjlSg4jlVWCI9wmpVpaDv9bWJuY=; b=8RZrDZcdRf+aJG8bpSoj3dAzSM5YttHvzEKVLLAj/GXklIY4PGZL2ZFaGKs8247rRt 3b8YWU+PGCOh+azdD2/DK5OqRfxv1hWRY6OP6xJ/Djz75NwLE56ZiCjoZW3kishEb27/ DZ/TKK2tc71NQ+SH3KdqIxBZAoAMP41cr44E1KOOoJD8qei9B8Z90kL6eoVtWLin/P4N X8HvM4z47R1IqKuXlUDCRif6Pa5BFyz3OeMS6kY56tPxWnvxX4R0R3uiaUnqZhBis3ZC iAA2HYYdEJQ3IwtS9b/AAJzZMfpxRJj3hVMtqSj+MQJbQ8aJgIBLYamTmZ7qzfWZ8qgb npug== X-Gm-Message-State: AFqh2koo/s49ViH/LjfRTlQdSnFwhN0tliP9+1eRvMqENQWj9t7ibTBM TlY1TBLKVMcvXOJpDr5WcI+d2i49cNvg X-Google-Smtp-Source: AMrXdXtwjaApDMB3XWr6gQZuBYEYUyZxG/xCEfNGBICQm7WT6cfXjB6YYAnLEpX8nXAPEcRN1aSQiQ== X-Received: by 2002:a92:7a0c:0:b0:30e:ecd7:d3fa with SMTP id v12-20020a927a0c000000b0030eecd7d3famr7499313ilc.12.1674072672995; Wed, 18 Jan 2023 12:11:12 -0800 (PST) Received: from fedora.mshome.net ([104.184.156.161]) by smtp.gmail.com with ESMTPSA id i5-20020a92c945000000b0030bfbc121a1sm10299998ilq.79.2023.01.18.12.11.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 12:11:12 -0800 (PST) From: Gregory Price X-Google-Original-From: Gregory Price To: linux-kernel@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, krisman@collabora.com, tglx@linutronix.de, luto@kernel.org, oleg@redhat.com, peterz@infradead.org, ebiederm@xmission.com, akpm@linux-foundation.org, adobriyan@gmail.com, corbet@lwn.net, shuah@kernel.org, Gregory Price Subject: [PATCH 3/3] ptrace, syscall_user_dispatch: add a getter/setter for sud configuration Date: Wed, 18 Jan 2023 15:10:55 -0500 Message-Id: <20230118201055.147228-4-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118201055.147228-1-gregory.price@memverge.com> References: <20230118201055.147228-1-gregory.price@memverge.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org This patch implements ptrace getter and setter interface for syscall syscall user dispatch configuration info. Presently, these settings are write-only via prctl, making it impossible to implement transparent checkpoint. This is modeled after a similar interface for SECCOMP, which can have its configuration dumped by ptrace for software like CRIU. Signed-off-by: Gregory Price --- .../admin-guide/syscall-user-dispatch.rst | 5 +- include/linux/syscall_user_dispatch.h | 19 +++++++ include/uapi/linux/ptrace.h | 10 ++++ kernel/entry/syscall_user_dispatch.c | 49 +++++++++++++++++++ kernel/ptrace.c | 9 ++++ 5 files changed, 91 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/syscall-user-dispatch.rst b/Documentation/admin-guide/syscall-user-dispatch.rst index 60314953c728..a23ae21a1d5b 100644 --- a/Documentation/admin-guide/syscall-user-dispatch.rst +++ b/Documentation/admin-guide/syscall-user-dispatch.rst @@ -43,7 +43,10 @@ doesn't rely on any of the syscall ABI to make the filtering. It uses only the syscall dispatcher address and the userspace key. As the ABI of these intercepted syscalls is unknown to Linux, these -syscalls are not instrumentable via ptrace or the syscall tracepoints. +syscalls are not instrumentable via ptrace or the syscall tracepoints, +however an interfaces to suspend, checkpoint, and restore syscall user +dispatch configuration has been added to ptrace to assist userland +checkpoint/restart software. Interface --------- diff --git a/include/linux/syscall_user_dispatch.h b/include/linux/syscall_user_dispatch.h index a0ae443fb7df..dbf384b7a26e 100644 --- a/include/linux/syscall_user_dispatch.h +++ b/include/linux/syscall_user_dispatch.h @@ -22,6 +22,13 @@ int set_syscall_user_dispatch(unsigned long mode, unsigned long offset, #define clear_syscall_work_syscall_user_dispatch(tsk) \ clear_task_syscall_work(tsk, SYSCALL_USER_DISPATCH) +int syscall_user_dispatch_get_config(struct task_struct *task, unsigned long size, + void __user *data); + +int syscall_user_dispatch_set_config(struct task_struct *task, unsigned long size, + void __user *data); + + #else struct syscall_user_dispatch {}; @@ -35,6 +42,18 @@ static inline void clear_syscall_work_syscall_user_dispatch(struct task_struct * { } +int syscall_user_dispatch_get_config(struct task_struct *task, unsigned long size, + void __user *data) +{ + return -EINVAL; +} + +int syscall_user_dispatch_set_config(struct task_struct *task, unsigned long size, + void __user *data) +{ + return -EINVAL; +} + #endif /* CONFIG_GENERIC_ENTRY */ #endif /* _SYSCALL_USER_DISPATCH_H */ diff --git a/include/uapi/linux/ptrace.h b/include/uapi/linux/ptrace.h index ba9e3f19a22c..8b93c78189b5 100644 --- a/include/uapi/linux/ptrace.h +++ b/include/uapi/linux/ptrace.h @@ -112,6 +112,16 @@ struct ptrace_rseq_configuration { __u32 pad; }; +#define PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG 0x4210 +#define PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG 0x4211 +struct syscall_user_dispatch_config { + __u64 mode; + __s8 *selector; + __u64 offset; + __u64 len; + __u8 on_dispatch; +}; + /* * These values are stored in task->ptrace_message * by ptrace_stop to describe the current syscall-stop. diff --git a/kernel/entry/syscall_user_dispatch.c b/kernel/entry/syscall_user_dispatch.c index 7607f4598dd8..ae4f9a4b96ac 100644 --- a/kernel/entry/syscall_user_dispatch.c +++ b/kernel/entry/syscall_user_dispatch.c @@ -111,3 +111,52 @@ int set_syscall_user_dispatch(unsigned long mode, unsigned long offset, return 0; } + +int syscall_user_dispatch_get_config(struct task_struct *task, unsigned long size, + void __user *data) +{ + struct syscall_user_dispatch *sd = &task->syscall_dispatch; + struct syscall_user_dispatch_config config; + + if (size != sizeof(struct syscall_user_dispatch_config)) + return -EINVAL; + + if (sd->selector) { + config.mode = PR_SYS_DISPATCH_ON; + config.offset = sd->offset; + config.len = sd->len; + config.selector = sd->selector; + config.on_dispatch = sd->on_dispatch; + } else { + config.mode = PR_SYS_DISPATCH_OFF; + config.offset = 0; + config.len = 0; + config.selector = NULL; + config.on_dispatch = false; + } + if (copy_to_user(data, &config, sizeof(config))) + return -EFAULT; + + return 0; +} + +int syscall_user_dispatch_set_config(struct task_struct *task, unsigned long size, + void __user *data) +{ + struct syscall_user_dispatch_config config; + int ret; + + if (size != sizeof(struct syscall_user_dispatch_config)) + return -EINVAL; + + if (copy_from_user(&config, data, sizeof(config))) + return -EFAULT; + + ret = set_syscall_user_dispatch(config.mode, config.offset, config.len, + config.selector); + if (ret) + return ret; + + task->syscall_dispatch.on_dispatch = config.on_dispatch; + return 0; +} diff --git a/kernel/ptrace.c b/kernel/ptrace.c index a6ad815bd4be..0b210a1450e7 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -32,6 +32,7 @@ #include #include #include +#include #include /* for syscall_get_* */ @@ -1264,6 +1265,14 @@ int ptrace_request(struct task_struct *child, long request, break; #endif + case PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG: + ret = syscall_user_dispatch_set_config(child, addr, datavp); + break; + + case PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG: + ret = syscall_user_dispatch_get_config(child, addr, datavp); + break; + default: break; }