From patchwork Fri Jan 20 14:43: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: 644846 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 E8F83C27C7C for ; Fri, 20 Jan 2023 14:45:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230522AbjATOpP (ORCPT ); Fri, 20 Jan 2023 09:45:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231154AbjATOpM (ORCPT ); Fri, 20 Jan 2023 09:45:12 -0500 Received: from mail-il1-x143.google.com (mail-il1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC817D0D8D; Fri, 20 Jan 2023 06:44:43 -0800 (PST) Received: by mail-il1-x143.google.com with SMTP id u8so2770748ilq.13; Fri, 20 Jan 2023 06:44:43 -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=Y4L1pQ0JM1hC2pJHglk8l3j+fJVDjADjEl6sXRJ77Xs=; b=WkrvGr7UQb8Qru2B3v0x5Ay72pxJQYUv6DeKNen0IezGFgdRcayY42tSeeLpsB6fo4 wO7PVmqxDKlhNMhpgMySgtT1W6mI9atfP+o9jBZAT7PaYq+MSCcfaAEG+zBtEh+ZK8hS 3NqgsPJ2mp+amhb7fLnp1b3zL5Sbe1aRATddLqf5BZC5178EYZ63cy9uqm807y0c2jke S/mlNesYvJIVnkw71blPkNHQRKcc/CMEyJu+k+ddVwWEY1SAiwbfihJ3bYareLGkjlwN 1sCSLzLnDdtFlmSF9XtqklE/F9i7iZtTolT466tH1PVc/iuct47xdg2XycyYknKpAly7 uLSw== 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=Y4L1pQ0JM1hC2pJHglk8l3j+fJVDjADjEl6sXRJ77Xs=; b=sZxxJJaFyZO4HJrj2fLR79xvkMnauDrTMK4nUAGuunZezgO3+8SeEOJKlN/J9e1BdZ euRLF8vo+vicw7yBbfYRsaYf0CQEUDZi2vYb3PCvAC4kMjETYo+Ki2lCmb/K7xLNzSK/ 0CsXnJAEJg8lzH+VMUaZid+IrSI9ondcX1DjH/CHlDohf+Auhx8vj0ibrB+hDZjDyXro VNUVJwHpaoXNeNxbDQ1YJ9Wuz0XMtj0kFjHhwvWSJ3P6OfgfrE+C254MpjuaX9UbVL9L iwueU4EWbR+3Rh20pBppYRmdJ1azy2+qtExgztQCpPAoBYqHZ62639Vcbg1Ezn37+V2N iv6A== X-Gm-Message-State: AFqh2kpWj2GSNNWtrBuTmRD5TmkObAH4udwF3YJHv2cBPjlOzqT6p8qf j/WRXeNH9AKcpJpii3diRq1En2NZC/ux X-Google-Smtp-Source: AMrXdXuTVKrotbzpNTgVhUT8ksOkhPVRLjQ2O1iU40UyKuopiGYvDqMz06qyac7d/RCk3MpXgtiG/A== X-Received: by 2002:a05:6e02:1544:b0:30e:f4d0:c092 with SMTP id j4-20020a056e02154400b0030ef4d0c092mr21505925ilu.3.1674225851136; Fri, 20 Jan 2023 06:44:11 -0800 (PST) Received: from fedora.mshome.net ([104.184.156.161]) by smtp.gmail.com with ESMTPSA id p185-20020a0229c2000000b003a7c47efde0sm1513852jap.11.2023.01.20.06.44.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 06:44:10 -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 v3 1/3] ptrace,syscall_user_dispatch: Implement Syscall User Dispatch Suspension Date: Fri, 20 Jan 2023 09:43:54 -0500 Message-Id: <20230120144356.40717-2-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230120144356.40717-1-gregory.price@memverge.com> References: <20230120144356.40717-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..99467ba5f55b 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_RESTART))) + return -EINVAL; + if (unlikely(data & PTRACE_O_SUSPEND_SECCOMP)) { if (!IS_ENABLED(CONFIG_CHECKPOINT_RESTORE) || !IS_ENABLED(CONFIG_SECCOMP)) From patchwork Fri Jan 20 14:43: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: 645281 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 64970C27C7C for ; Fri, 20 Jan 2023 14:45:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230498AbjATOpS (ORCPT ); Fri, 20 Jan 2023 09:45:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231165AbjATOpQ (ORCPT ); Fri, 20 Jan 2023 09:45:16 -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 94510D0DB6; Fri, 20 Jan 2023 06:44:48 -0800 (PST) Received: by mail-il1-x142.google.com with SMTP id f8so2795954ilj.5; Fri, 20 Jan 2023 06:44: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=fqgqlvxl2/AjHmd8bF7KdCJg7y96KUb9pTAZ52R5/2g=; b=LnkI5KpNCjol1eJRa1CeU/Ka3N1fJp1SFPwR8vNOaRqLIo56jlYqGRYpXaJlDi6Pzb f4dI/Qped/yuiW1YvWStBpb75NDAk1VgKzY4hjv0r3WIC/rHd6ZtILpTweCNIOehdyvx BiKQ3i5u2IZSxuhgB8IIkEvtgetqRSmNS5kB6nWjG+gfnvfJAVRkly/EZzT1EU3vkxET C9bYRZBG6kbkHa9GW0YR3bt1m2UpCOZV8eKICKy+3EAlZWwZ0MK9tM66c5dVcFQs6urC zYpA6AM94BfeJczIHlnlHVY/XYUpi5S63DzgQmwdmvYgn44khT4MjnjzmCqif8z+LPan 1rpQ== 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=2uUkoyQ8Gi3oEAPJWTQVrma4CTTIes3uEwBMTs6f27ih8+Ds5eWFA+P2dBwZm18xUb 5n+q573IxaP9tVurxu8xclgykb8tD/UeyXWBUur/GAXhR8VCy3i+4VLPqmVDR/OLLFqQ 5azKxMAyAMS+wqe9ZxiMyq5DF0Pqaqtz8YpbPKH2Jx76eOyVX97a+DjASW98993dvdDG jbsHLrH0cAnPHvTvEroAhAQTrkwJOgVvMPr1/LjFzFgQYnacqlQrgypZVKCz5GRvFiJC 23AbGSv1GQnU060ZkY3NC24Tf5R5RSQbCvtykNIl9cL6lXMDSIyXWMs+Kb8fmTpDArGF qrgA== X-Gm-Message-State: AFqh2kqS6ChHMQzMGH2VMZVc1483YyvBfWPbPbtDe1X4v1KQMTdLSLGe lGZBodfsJP8b0br/vaxDa+dlJqEOR/ZK X-Google-Smtp-Source: AMrXdXt3Yz1hmgZ+mVPQhzOA/jtz7/t+tye693usGwvJflFkDLvhnjzE+eu0rz2Jn2Tc4fSgi9TATQ== X-Received: by 2002:a92:da43:0:b0:30e:f171:660f with SMTP id p3-20020a92da43000000b0030ef171660fmr11011884ilq.31.1674225855361; Fri, 20 Jan 2023 06:44:15 -0800 (PST) Received: from fedora.mshome.net ([104.184.156.161]) by smtp.gmail.com with ESMTPSA id p185-20020a0229c2000000b003a7c47efde0sm1513852jap.11.2023.01.20.06.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 06:44:14 -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 v3 2/3] fs/proc/array: Add Syscall User Dispatch to proc status Date: Fri, 20 Jan 2023 09:43:55 -0500 Message-Id: <20230120144356.40717-3-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230120144356.40717-1-gregory.price@memverge.com> References: <20230120144356.40717-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 Fri Jan 20 14:43:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 644845 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 68211C05027 for ; Fri, 20 Jan 2023 14:45:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229944AbjATOpc (ORCPT ); Fri, 20 Jan 2023 09:45:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231127AbjATOp1 (ORCPT ); Fri, 20 Jan 2023 09:45:27 -0500 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70976D0DBF; Fri, 20 Jan 2023 06:44:50 -0800 (PST) Received: by mail-il1-x141.google.com with SMTP id r19so2415937ilt.7; Fri, 20 Jan 2023 06:44:50 -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=tm7r7/w+NTSuvZBNcrJh41bBRzvQQKHJ+pSw3+ziM6w=; b=d9hrNAP1hM3jAB/eHeVYlSgAOzwZ6HpHsmGPUB9k/S3hJoKV6ZKXsNpcifJyXeFd1Z hOsIOWnEERynuF11cD7WkoqawYUwuoJ3Oko5+nxiVlTcRTwod/Y08ApHYZdFv/69N3x6 v9MBqMTqSHJ1jRPWVVrgVfaEOoYQgpn8+CiNEXrPULJtiYwH2upRnZlgDQ92UYnRqacO +ArPEu/p4v6CemcpChZMdHYXi3DqWUQuNGIcZPbLWWwrSwplUDoRiKj4j8QQ124qvPLu PvHYP1wruhHnATYaw3JLcYo1hI5MkbSDeSHwBKldHWWmqB6xofNCZYq4ARwcL7lgLRcR bY6w== 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=tm7r7/w+NTSuvZBNcrJh41bBRzvQQKHJ+pSw3+ziM6w=; b=I4g8cT52z8iYarGDPCf2cZmXvKee43p8UWz7fVYW5+VHE5krzr3NlY/ITmtOdQfl9i kaIho/EXJHU66L6zuluzuDE1S0iu0kP9C0Q1/X9xd9iJJj6+387C1LcszMz/S2foANcg MzAmJybWTLzTDiqLIo6xjDevy86+ABhUDpMAJ1vyAERX8a2RTs0AMB2cqLcvbrbZhU3p 09iwsttRh8IR55Qr0Bl0Q92CifLLI9kvIej+7ttS0+QZpDpzfUqWbnF+15QcBoTwtN18 xsnQn6Ee+7dXKvFdM8x8x8dZo4CoalRa8jfYbLOENinM0WUPOquMDUEhziL1C6PDKSWa boxg== X-Gm-Message-State: AFqh2krutihkb46gButhchxjbK4IuRfLEDI4geddNpdLehRh/ac4A7VA LFYpmDORM7FQkbccN3fvG3BU/hzN89RA X-Google-Smtp-Source: AMrXdXvFwKixDS/TIXDil0+nxTTZXuD9Hv1Pb5U4CyB5pJAmfEvnE626Cy7OLk1Q8SFJUdjAiwK6TA== X-Received: by 2002:a92:2e09:0:b0:30f:1a48:b5ac with SMTP id v9-20020a922e09000000b0030f1a48b5acmr9475876ile.20.1674225859097; Fri, 20 Jan 2023 06:44:19 -0800 (PST) Received: from fedora.mshome.net ([104.184.156.161]) by smtp.gmail.com with ESMTPSA id p185-20020a0229c2000000b003a7c47efde0sm1513852jap.11.2023.01.20.06.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 06:44:18 -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 v3 3/3] ptrace, syscall_user_dispatch: add a getter/setter for sud configuration Date: Fri, 20 Jan 2023 09:43:56 -0500 Message-Id: <20230120144356.40717-4-gregory.price@memverge.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230120144356.40717-1-gregory.price@memverge.com> References: <20230120144356.40717-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 | 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..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..a3b24d498b39 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 99467ba5f55b..d1e9c0808905 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; }