From patchwork Sat Jan 21 10:23:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13111056 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 45938C38A23 for ; Sat, 21 Jan 2023 10:23:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbjAUKXa (ORCPT ); Sat, 21 Jan 2023 05:23:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229687AbjAUKXX (ORCPT ); Sat, 21 Jan 2023 05:23:23 -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 B0C39126C6; Sat, 21 Jan 2023 02:23:22 -0800 (PST) Received: by mail-qt1-x844.google.com with SMTP id fd15so6112903qtb.9; Sat, 21 Jan 2023 02:23:22 -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=N2PwPl7aiBtLRfod/1/P10zXinkoVfpONWDKG314+LCXXre9Hi3O/jwhon7JMDhPmT Be2kdTw3IyV5fwVX+aKADrPGpzoirv8ZPSCLy36JbdzKLTUdAZ9GRA3TUJx8R5HcFwHz Rnmaats9Xsy2pDnKjp7KPjpRqZPW56jkaNZc4aQ4a4LL1hdPcWmCJow78aezGyZkJQiL N9DPXitk8uJv/lETkpSb0Fv251WaM3NG5A4JdIwLw3CThPyvyhgUCBiZsiRSBni4CwMU nvji5f3XnuiqKD4iswu7WDPhqsG68ea6fQKVQhI5mTeUnEXsA10WQ4KiTD9A7D1E+ALo 3O1g== 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=y720X9IRwwYLRgmFO66sub41nL97zb2ZquxiT3gg9OBEN3clMmWGiQm4HGndZLNhpN DmjgwbjBN15NlWM9hLALNySQFAPZF/Fy3MULlsV9G982Pbrx58hKg9qJ+4Y+I+EM96J4 m3iWoNewvHh7ocz1RnOqSHQYVc+Ww6VGCgoWerfrOzrc6m/Axtcz9MSeujXkdVjGfXGb rqL53tMDYk5V2hE029GS5LsPM998bELlkhtV8yRUGDy+ila+LYjFqOetJicvg0D7H6tb YKt3K/cXkBUSAFCf2OJe+bJvbVLbd9hYXZqvcyzqAeJYY/NcrIQcidr4DLqd+de/ruRL 6EBg== X-Gm-Message-State: AFqh2kq3NA6QO/uZzUMMdGkANxLp5phulXHvNAGZw+7bgAU5RmpGhUku L+PoN9m+ufKfAZ9lj2seMqKNu2L2MrRs X-Google-Smtp-Source: AMrXdXvoxvzx8N405bqrTZNfSFLLnWhxPYcHLo8caWW2pKaDjvgoiSvmxJGfqH7wvP1O7BUxdm8zrQ== X-Received: by 2002:ac8:6e83:0:b0:3b6:3406:81cb with SMTP id c3-20020ac86e83000000b003b6340681cbmr25939497qtv.14.1674296601743; Sat, 21 Jan 2023 02:23:21 -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 y2-20020a05620a44c200b006e42a8e9f9bsm14128630qkp.121.2023.01.21.02.23.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Jan 2023 02:23:21 -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 v4 1/3] ptrace,syscall_user_dispatch: Implement Syscall User Dispatch Suspension Date: Sat, 21 Jan 2023 05:23:14 -0500 Message-Id: <20230121102316.331935-2-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230121102316.331935-1-gregory.price@memverge.com> References: <20230121102316.331935-1-gregory.price@memverge.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 Sat Jan 21 10:23:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13111057 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 A2A76C5320B for ; Sat, 21 Jan 2023 10:23:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229752AbjAUKXb (ORCPT ); Sat, 21 Jan 2023 05:23:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229697AbjAUKXZ (ORCPT ); Sat, 21 Jan 2023 05:23:25 -0500 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5006846D74; Sat, 21 Jan 2023 02:23:24 -0800 (PST) Received: by mail-qt1-x842.google.com with SMTP id h24so2186928qta.12; Sat, 21 Jan 2023 02:23:24 -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=ACObeGmvp/0Nnei4QCSvOb8xescxKyeceEFZIuDD2Fc=; b=MvgOXV4a9b8FFR7E4w2hZdj30Z7Om2ZS7Br9wR9ZecVYL0MBWrr3ZF/16KQF1f6vCZ w23Rx/4Tndk44FpOoUlbZBivV1wBCqWpzj+E6/MS/lywaipbEcUncSWuXXkBxfXYvcQy r7v2HiJnWour4ErFmxvtX0jggEevVsdIEgesXbK+G/e8eJB6yW72LWAK4TYJPwIweo01 AY2ShvdvDwyeJV+MbTk2zYJ+zTX2gEN3hXiM51a3D6E/yNUJxrBcrWWDcPUxdqxDC/HH r/sUIuu/8QJd1A2tDXOoq3ml6CWvY68DWhbDmB3WEUEA/gaPJWgHpy33kWGxCktu7VAw VWkQ== 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=ACObeGmvp/0Nnei4QCSvOb8xescxKyeceEFZIuDD2Fc=; b=cIh6Zb/FQyK+2yq7G9o37q7iGzBpPlIe8sVe7Gb5qVJUOSMbIBL9l0Pqz/la7+Bgh8 17ZMO5f+h02L/snYb8EkaggbelbTHwFNnG7gHrAMyi6yfmJj3W0W09EgZaFCw/WRdXNn j4VGEkKS5aJMKxeQfbV6U2SXBsk1pw04Gl6ncQ5mTjqk3zUBuj1BIoMGCvv3y/SuY8UP zU3RjbKoX277Bp9ODTZO8dn2j0gypqRn4ilhKa4NAzTeXSPsxACVzSs6nOs1DCOeHj8Q Q4c0oYAb5+Dp4mJSJ0P5fxIIXzOr7KXsanAf1f+0dS32Bv0Z6P5SJEmLrmUGGt7LXs2D 8ZQg== X-Gm-Message-State: AFqh2kqzRhdmixUTEqexrCuWq5d4S9S0chRPFQrKEeTxjs1rxQK9hIl2 foV1XoecOakw/P1CqcQHfsU+vDWzYsLm X-Google-Smtp-Source: AMrXdXsGXw83Ni91md2ApeibRl6pO81Y36UffPwEt335DPhivm/9X3h+XjnIgYI9k5wTzoGnIXhlXw== X-Received: by 2002:a05:622a:22a5:b0:3b4:a6ac:770c with SMTP id ay37-20020a05622a22a500b003b4a6ac770cmr25548530qtb.45.1674296603337; Sat, 21 Jan 2023 02:23:23 -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 y2-20020a05620a44c200b006e42a8e9f9bsm14128630qkp.121.2023.01.21.02.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Jan 2023 02:23:23 -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 v4 2/3] fs/proc/array: Add Syscall User Dispatch to proc status Date: Sat, 21 Jan 2023 05:23:15 -0500 Message-Id: <20230121102316.331935-3-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230121102316.331935-1-gregory.price@memverge.com> References: <20230121102316.331935-1-gregory.price@memverge.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Report the value of test_syscall_work(SYSCALL_USER_DISPATCH)) in proc/status. This provides an indicator to userland checkpoint/resume software that it must 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..2275ac153c4c 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", + test_syscall_work(SYSCALL_USER_DISPATCH)); +} + 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 Sat Jan 21 10:23:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 13111058 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 7F924C004D4 for ; Sat, 21 Jan 2023 10:23:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229738AbjAUKXe (ORCPT ); Sat, 21 Jan 2023 05:23:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229699AbjAUKX1 (ORCPT ); Sat, 21 Jan 2023 05:23:27 -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 BFE8B45BF0; Sat, 21 Jan 2023 02:23:25 -0800 (PST) Received: by mail-qt1-x844.google.com with SMTP id j9so6140417qtv.4; Sat, 21 Jan 2023 02:23:25 -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=Y60BRocz38pQeT9LNHp+OoXGPTE5kAuDg3kXW+KKqMXkJ1wrdemi6j2so6grTKGJJt VaODOSwRAlmo2HB09dnLSkc5SPPADWxIayCQSspbs+j1KVBDMOAyAVeLiDswzBtRJdXl +9aDwn1LEoARBcTXYFikMtdcnEzRMDGHqZQ75lsTYpuP/7WFbLby/0UDh+P+4QBzGnf7 l+POgSQDt1hgmlJFZLgcNrsx8iGxg2FJXw6p9NoZ385ZWpjRlVOWyc6ndulKsFDXBUUg ywRJq8es34UChKZYhajU64YCNZEiFlHAGih4QkYX1KVSNWwmg8XPW2KtfHfwS5jP8xAn 69LQ== 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=S3IJXAGO7xcrPm2/t0ncdws6wkMyua7qFX6VP1k9yqOj0cMcFWd7aSMmZ0V5Zs5CQo e3fyPJrQrer4jriO4WrXfBkXPKbZ2x2hKGd+UuuZ1sl40Vk0HpUZ1mr6yNZUzPRBtFl8 fc+nU0duZsgy1xI4ZI2sCYAHPNyIqJv7Pb4WeO8ck1NTa0BMk+R3MUSQePl9aw9g61ih I3mwExd/xDWaOHSTBzc6CnogypPvQAFU0BCDT0oUDjzzHYKJk416ZvcsOmWc2LgMIYNv VZtlSDX5sXUPQZBsoOrVMxJ1JeWl7wJYkH1GK1Wiu7dMn7Bztap0SE1TlI9nC6STNF63 QUGA== X-Gm-Message-State: AFqh2kqQRVtTLFhloxL/KPMTnpm4BzNGkN0DoPO+bXwALCGcx531S7eY +8Ooaos3T+QR4iT0mVnWG9HsBR52G/Rf X-Google-Smtp-Source: AMrXdXuHQGEmCLoJYFISVqUDA492mFQpJoWc32U8Y4YOlLVLoy7qj3BAkQvnUl7dGluAVfy6aJpeiQ== X-Received: by 2002:ac8:59ca:0:b0:3b6:6669:dd28 with SMTP id f10-20020ac859ca000000b003b66669dd28mr27405204qtf.18.1674296604839; Sat, 21 Jan 2023 02:23:24 -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 y2-20020a05620a44c200b006e42a8e9f9bsm14128630qkp.121.2023.01.21.02.23.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Jan 2023 02:23:24 -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 v4 3/3] ptrace,syscall_user_dispatch: add a getter/setter for sud configuration Date: Sat, 21 Jan 2023 05:23:16 -0500 Message-Id: <20230121102316.331935-4-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230121102316.331935-1-gregory.price@memverge.com> References: <20230121102316.331935-1-gregory.price@memverge.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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; }