From patchwork Mon Jan 23 03:29:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 645849 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 E5158C05027 for ; Mon, 23 Jan 2023 03:29:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230344AbjAWD3t (ORCPT ); Sun, 22 Jan 2023 22:29:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230218AbjAWD3s (ORCPT ); Sun, 22 Jan 2023 22:29:48 -0500 Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 518851448D; Sun, 22 Jan 2023 19:29:47 -0800 (PST) Received: by mail-qv1-xf41.google.com with SMTP id m12so8249937qvt.9; Sun, 22 Jan 2023 19:29:47 -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=t73OUm5Hu/QTQLymf1aW1FtTfvw+wRC90VtlrO5K74Q=; b=WGKWbEYOo9UNFp3L/a3NKixLfWE+0ncnDpKuXfN9JKyevPebhgZWNUlX7pbqhdYHXE qE+oqbxTbhaswbTsTg7b0PgF2qXiYbvKjkEv74JEY+XLAU2xVUecZcfSOakbGgRuGlG+ crb9tGvofio/vIdwhlc0Z5oHgAvICkMKBZOPylRUSCmWuYYuXUjad2mpi0K96KXM7TFP 9jaKCWwRB6Z9yxrP6fEpPKGXGZQdDyoxcOhVVOBU1F3jTU/Bz8VTaf7jqurirgZi7aNG DnY+2mgK1ramuGBMtrMlMuJgHY8xqWJDrPaR89yIqIYQ12K5latbgRczyYwlcWPYxIzS iRnA== 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=t73OUm5Hu/QTQLymf1aW1FtTfvw+wRC90VtlrO5K74Q=; b=YcnZVlLVt0H5wzSugDZfDTREeoWhRPJEAp60uU69XUz4Z3HCPX3SzDqrwkhASKp3g2 s6iISo4FKNW/ujYlDD5DaoP1qIG4FHRePrM3SDBAeJqONpiZknfR1wm6fTY3/NbbCd8K Ib/zEv/F1FJTE/I40qDS4hZdfdM9xZpGDPU5n2mVC13d9+7acON36sNwfdbyeqhhVYLV F9n7uYVVhlNy/xE2Vqp0aeGds4h95u0wt901VZ29CfOLPCj9ZLdzmbDEBwBks3eey7IB kAFrazIjWS/h/XhvqRkmZ+ddjL4ZnHcRHFB/+a3zwOeY/a1I4dkYyoOq4xSPVCOhgfzR Mqew== X-Gm-Message-State: AFqh2ko/7DBvUEgIzdLdiLosUE3b/uA9I7vkSKvX8eOvII76hteJU4gs S3KNE+v/4saAIL47qxo9CfN7PcWasxUJ X-Google-Smtp-Source: AMrXdXte9SMsFqsZi7hqhWj5hZAQ7nVL5+zqDe+impIbrgxQJyHDayZr89T+YAFIjsoR1HlHQFVq1Q== X-Received: by 2002:a0c:9c8a:0:b0:531:b7b1:c31e with SMTP id i10-20020a0c9c8a000000b00531b7b1c31emr33058343qvf.38.1674444586336; Sun, 22 Jan 2023 19:29:46 -0800 (PST) Received: from fedora.mshome.net (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id u3-20020ae9c003000000b0070928ee3933sm4875492qkk.75.2023.01.22.19.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jan 2023 19:29:46 -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 v5 1/3] ptrace,syscall_user_dispatch: Implement Syscall User Dispatch Suspension Date: Sun, 22 Jan 2023 22:29:40 -0500 Message-Id: <20230123032942.18263-2-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230123032942.18263-1-gregory.price@memverge.com> References: <20230123032942.18263-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 Acked-by: Peter Zijlstra (Intel) --- include/linux/ptrace.h | 2 ++ include/uapi/linux/ptrace.h | 6 +++++- kernel/entry/syscall_user_dispatch.c | 5 +++++ kernel/ptrace.c | 4 ++++ 4 files changed, 16 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..b5ec75164805 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..a348b68d07a2 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -370,6 +370,10 @@ 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) && + (!IS_ENABLED(CONFIG_CHECKPOINT_RESTORE))) + return -EINVAL; + if (unlikely(data & PTRACE_O_SUSPEND_SECCOMP)) { if (!IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) || !IS_ENABLED(CONFIG_SECCOMP)) From patchwork Mon Jan 23 03:29:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 646850 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 E4990C05027 for ; Mon, 23 Jan 2023 03:29:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230371AbjAWD3v (ORCPT ); Sun, 22 Jan 2023 22:29:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230259AbjAWD3t (ORCPT ); Sun, 22 Jan 2023 22:29:49 -0500 Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99AB91448C; Sun, 22 Jan 2023 19:29:48 -0800 (PST) Received: by mail-qv1-xf43.google.com with SMTP id h10so8255889qvq.7; Sun, 22 Jan 2023 19:29:48 -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=KtHmWIx6vulvHYGAYeWjtOeo6VWNy9zzuy5Mzq72830=; b=PZQBT6bC8aW98pEFkJmpao9JeJdKadz3kb+CggprRR9jSRvc/oMoUXNkUPrGkuBYI6 9dzsbtFAxL69hMA0dK2+riMqSMS5BZe6fuq3BLm6oyJ4C1wROgRidgz+5xG9JS2LbOai 8YI+Hg36U+GGcW7y8NGqaQZ61YolfG056HSVh5VsnBRZc6UDJOcnA1KqAXTo4FiIGUMG YWMu0JG/zRBH0fVXXUfWcSC+4cBCqthoEULK5jMVSdoOiXzxFIlFv4tuF5QmKyDz5XZX KC9pAf3I/nZc0buiABx2tXiBcHd8mucMBJbXQ72snu3tZR5h6iFy7r3KyNca8Rf1soyZ CY2A== 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=KtHmWIx6vulvHYGAYeWjtOeo6VWNy9zzuy5Mzq72830=; b=fVvn3MO27+DhHeJpa2Pv7GYpH9ZGJrkxHdGxp1UAUkZoBSvbAcZ3g7G6eVnGQChCyC OCEhr7uPNizXCw+Q2+hFmFtSc45i3g2B2Y3t/RN07cK+26oGMU5qPdweTK/4PVBTRatx tAw65eNfIjJbkY7CF8JfuQzdYtkxkhBwhyGSo/MtnH8/i1VaRYp7FkKztIeDsY19FqxK dPYUJZgn4PnUE99nFFEoiYxavilOxBO4JcDcY5XKA6R5oE9HZ1oaKnWsX3U0U+ZL8UDt XJXJa3UE6NbLGWoRRnkIvgvnRcfFdZvV1raKHUla7ofuZ2mYTAjhmvTfDK6L/6ro22LT 3u8Q== X-Gm-Message-State: AFqh2kpn0IOJfd8r5ba043AY1QoHruA6EYFtw1lxRX0xS7GbwYpB78yw Rtw+Z7AG3PX/NNzkpq0VJ341MnhMKACO X-Google-Smtp-Source: AMrXdXvec9nTcHOybVyNL6D93K3etzV56PtBd8VTNbTmvvePmf3CI55bNbuMeIRRCtxa46vSVjaIAg== X-Received: by 2002:a05:6214:5cc6:b0:535:2539:f6f5 with SMTP id lk6-20020a0562145cc600b005352539f6f5mr32375957qvb.19.1674444587670; Sun, 22 Jan 2023 19:29:47 -0800 (PST) Received: from fedora.mshome.net (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id u3-20020ae9c003000000b0070928ee3933sm4875492qkk.75.2023.01.22.19.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jan 2023 19:29:47 -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: Sun, 22 Jan 2023 22:29:41 -0500 Message-Id: <20230123032942.18263-3-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230123032942.18263-1-gregory.price@memverge.com> References: <20230123032942.18263-1-gregory.price@memverge.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Report the value of test_syscall_work(SYSCALL_USER_DISPATCH)) in proc/status if GENERIC_ENTRY is enabled or the arch has implemented it. This provides an indicator to userland checkpoint/restore software that it must manage special signal conditions (similar to SECCOMP) Signed-off-by: Gregory Price --- fs/proc/array.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/proc/array.c b/fs/proc/array.c index 49283b8103c7..d4e4ee2409c6 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -428,6 +428,15 @@ 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) +{ +#if defined(CONFIG_GENERIC_ENTRY) || defined(TIF_SYSCALL_USER_DISPATCH) + seq_put_decimal_ull(m, "\nSyscall_user_dispatch:\t", + test_task_syscall_work(p, SYSCALL_USER_DISPATCH)); +#endif +} + int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task) { @@ -451,6 +460,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 Mon Jan 23 03:29:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 645848 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 0027BC54EAA for ; Mon, 23 Jan 2023 03:29:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231134AbjAWD3w (ORCPT ); Sun, 22 Jan 2023 22:29:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbjAWD3v (ORCPT ); Sun, 22 Jan 2023 22:29:51 -0500 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBD691448C; Sun, 22 Jan 2023 19:29:49 -0800 (PST) Received: by mail-qt1-x844.google.com with SMTP id q15so8855101qtn.0; Sun, 22 Jan 2023 19:29:49 -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=RgFqur+BidWWWQr7r2LPXldx8oTQot1Qp1tXD/WiXfY=; b=aXerHjM3OC9ndo5Q3C5+pmGodhG7mKJqaptfNyYdWWWNcNr4xq/0TBLKrBw5ESXsgZ jg84s/XqTxsrimKQi0dUWE78pQbysFgKHvIkoQkwwff/xN76aFA2SM7zUsEt97NLRGvf hhnz3cghJZJQvr+AksoDwjCC2lOLQLSSGAf/7uRXI4l2WUslQtp5QsTVBvvV52iug8TU ryvrH8sHHbxl0zCVCIqaouo/8L35n4O/DeTswGU1OwQInxypnrt1x4or34qZioeLfc3i NJXBo2Oux6Mz2B1Ccn1Qw642J2aj/HxdBjwc0Hau6IAKbl7BM31NqCs8yztb65Nkpok6 jQVw== 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=RgFqur+BidWWWQr7r2LPXldx8oTQot1Qp1tXD/WiXfY=; b=1N1AmouTS2P/Ul2ZF52QjOZRqXnCa1rpvbc7zinl5djgdnEXIGOjFk/zD5z//G+jJd KjhpF5Absle7w5IroNsCqkUdbdYwxf0v3m9ZN6y2s8WzPBjpNXYsy0tYye2PQGLfdj4D 1xi13/UHArm28QASeC1U2mLlkBwZBNUSm6AuQOF2Vmk5rUtwkRcbR0Fid+eI7LEj2nGU K6LH4sAti6x5A+D27YkBdmMglkjAxmbkkUQi2rCxGXsDUjmxL5It04OlN8lb82+OHFvI 49r+XLeVgFuJEd2+YzsuriM9QPuQKwGI+FMOoxVY3ZJV0e8Cwvs1xCg8yxrAQDJSxSAd zEOQ== X-Gm-Message-State: AFqh2krUsPNcHkEYj+oTer4u7yUxirbfsTI9paN74JUaat8FucR/Uj/b WYGfprHtk+P0fgSaLa2D0QvMzlP5eM1I X-Google-Smtp-Source: AMrXdXsv+aWdy/Yy/TfkjcpMJTXw3AoOi9BYBga3ld1DyGO8OiG2pQKxViozE8ZYQgu/PcnPGfj7lQ== X-Received: by 2002:ac8:668d:0:b0:3b6:32ef:2dda with SMTP id d13-20020ac8668d000000b003b632ef2ddamr31948335qtp.34.1674444588905; Sun, 22 Jan 2023 19:29:48 -0800 (PST) Received: from fedora.mshome.net (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id u3-20020ae9c003000000b0070928ee3933sm4875492qkk.75.2023.01.22.19.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jan 2023 19:29:48 -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: Sun, 22 Jan 2023 22:29:42 -0500 Message-Id: <20230123032942.18263-4-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230123032942.18263-1-gregory.price@memverge.com> References: <20230123032942.18263-1-gregory.price@memverge.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Implement ptrace getter/setter interface for syscall user dispatch. Presently, these settings are write-only via prctl, making it impossible to implement transparent checkpoint (coordination with the software is required). 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 | 46 +++++++++++++++++++ kernel/ptrace.c | 9 ++++ 5 files changed, 88 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..9e1bd0d87c1e 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 * { } +static inline int syscall_user_dispatch_get_config(struct task_struct *task, unsigned long size, + void __user *data) +{ + return -EINVAL; +} + +static inline 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 b5ec75164805..a303c8de59af 100644 --- a/kernel/entry/syscall_user_dispatch.c +++ b/kernel/entry/syscall_user_dispatch.c @@ -111,3 +111,49 @@ 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 (test_syscall_work(SYSCALL_USER_DISPATCH)) + config.mode = PR_SYS_DISPATCH_ON; + else + config.mode = PR_SYS_DISPATCH_OFF; + + config.offset = sd->offset; + config.len = sd->len; + config.selector = sd->selector; + config.on_dispatch = sd->on_dispatch; + + 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 a348b68d07a2..76de46e080e2 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -32,6 +32,7 @@ #include #include #include +#include #include /* for syscall_get_* */ @@ -1263,6 +1264,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; }