Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp321640pxf; Wed, 17 Mar 2021 06:15:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWcjrYyzlfv3AZGiIv6RHhLJSXKtor2pmIXzn4OUVXi7YkplfOZDW75aQcVo8aOICgnLt5 X-Received: by 2002:a17:906:7d7:: with SMTP id m23mr35610645ejc.205.1615986948159; Wed, 17 Mar 2021 06:15:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615986948; cv=none; d=google.com; s=arc-20160816; b=dyTTyLel7JBYssym6Jd5FcEDVhxI7N801qwhF3kUKadmJXboc4UlJ+1TDzRwZZwwFc DL5PYPTwy1MnC01HTXJckgA1fsuJDIc8g7zhQIjeKP2knfGtvLoxvZzaUxpu/Zua7EEc On/8mu/qq4oKTPyvv8XmiWfyLDYNLYAZ4r+0z8WfzpbRAZy1RuDIzOB3+B0fTl9lZheC WaF7PSd5WJJFhSDNWg9C8qAfGQIRcKFVwBuIg/DUg76pg7ZqXbCJ5i+oVfneI1WRDbPN scFkqXvd6aEWqV8xhnfYJcGc5FHO5Ppr0BYImCh9GoGsMc6RCMadEFPPeXNtBv3naRs3 U1qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=1YApcwjDihhlakWewylW9wFlszybKBfhMe+HG10/Bbs=; b=WUK+ifN3kw3t8eMHJkomD8YxEc0gUTb3RHu8s9GzH2UfgiRDjdA4iz8eLyuBkugahD sMVaPMB0mKvotFS7pNpVToHzgXXAAtEbun4hkpqylLN/Gw8CfYSiAxePIj2Ip7nC+46D pDHzSr/1ZrrVg5gh7uhRzbxtXEtAmkTi1yAlSPdn08KGaEEXNfdp/jwZsXaLMHerosFc KVdYmJzhlZ0QcEGxBG895eKsGgpk5sfajUvYK1Ipe3CC0fzAgsRxINKalgM4ULLYQclp ItAGzlEBczDL5avOEYjGrLKve1gKSmJTCChNOJOGGODqB2zAKNyslgPe7K0ZbvljB9/5 7HKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=J4qRMBDP; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bf4si15647454edb.291.2021.03.17.06.15.18; Wed, 17 Mar 2021 06:15:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=J4qRMBDP; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230057AbhCQNOE (ORCPT + 99 others); Wed, 17 Mar 2021 09:14:04 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:50158 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229803AbhCQNNf (ORCPT ); Wed, 17 Mar 2021 09:13:35 -0400 Date: Wed, 17 Mar 2021 13:13:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1615986813; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1YApcwjDihhlakWewylW9wFlszybKBfhMe+HG10/Bbs=; b=J4qRMBDPpcIL0nGjtO/zSF1shHNpCGKc8Z9ly2vRGVjElc5r/YNbrcFvPajzLF8GvhEIsB XXVdja54QhTo0cUKQwTitWTi4Gw4VHJSaOUzv1MIkra7LAbyfx1Q1B2dKUONg1fuv8yymX a6lpGx5RjrK+reOznvznEX0EI7bSSZEsJ7KsVoV3wxEeAgP4GaEW69kj3TKG4mpPsbh3d8 VfdfNhLB2DBHxOP7yu6/io3T3spXqm3ZjwF8g5pmNDqct2aFgHYZ5yiOl8ShYvt9gAbPuI yuLKebx7ALdc+CoNXEwzIkO1HYO71jyC2UEcpHbHah0qRAtfoJ95BiXWOfK1QQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1615986813; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1YApcwjDihhlakWewylW9wFlszybKBfhMe+HG10/Bbs=; b=bCJdHS+IAqCowhPNJ3hvo3sfKFRKosIWl+l/ZKdoGlpQOWnfJJqsIWgQPJcrNvn23mXbXb F/Pv7V0z/gREESAQ== From: "tip-bot2 for Piotr Figiel" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] rseq, ptrace: Add PTRACE_GET_RSEQ_CONFIGURATION request Cc: Piotr Figiel , "Peter Zijlstra (Intel)" , Michal Miroslaw , Mathieu Desnoyers , Oleg Nesterov , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210226135156.1081606-1-figiel@google.com> References: <20210226135156.1081606-1-figiel@google.com> MIME-Version: 1.0 Message-ID: <161598681294.398.14135404653803937904.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: 2c406d3f436db1deea55ec44cc4c3c0861c3c185 Gitweb: https://git.kernel.org/tip/2c406d3f436db1deea55ec44cc4c3c0861c3c185 Author: Piotr Figiel AuthorDate: Fri, 26 Feb 2021 14:51:56 +01:00 Committer: Peter Zijlstra CommitterDate: Wed, 17 Mar 2021 14:05:40 +01:00 rseq, ptrace: Add PTRACE_GET_RSEQ_CONFIGURATION request For userspace checkpoint and restore (C/R) a way of getting process state containing RSEQ configuration is needed. There are two ways this information is going to be used: - to re-enable RSEQ for threads which had it enabled before C/R - to detect if a thread was in a critical section during C/R Since C/R preserves TLS memory and addresses RSEQ ABI will be restored using the address registered before C/R. Detection whether the thread is in a critical section during C/R is needed to enforce behavior of RSEQ abort during C/R. Attaching with ptrace() before registers are dumped itself doesn't cause RSEQ abort. Restoring the instruction pointer within the critical section is problematic because rseq_cs may get cleared before the control is passed to the migrated application code leading to RSEQ invariants not being preserved. C/R code will use RSEQ ABI address to find the abort handler to which the instruction pointer needs to be set. To achieve above goals expose the RSEQ ABI address and the signature value with the new ptrace request PTRACE_GET_RSEQ_CONFIGURATION. This new ptrace request can also be used by debuggers so they are aware of stops within restartable sequences in progress. Signed-off-by: Piotr Figiel Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Michal Miroslaw Reviewed-by: Mathieu Desnoyers Acked-by: Oleg Nesterov Link: https://lkml.kernel.org/r/20210226135156.1081606-1-figiel@google.com --- include/uapi/linux/ptrace.h | 10 ++++++++++ kernel/ptrace.c | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/uapi/linux/ptrace.h b/include/uapi/linux/ptrace.h index 83ee45f..3747bf8 100644 --- a/include/uapi/linux/ptrace.h +++ b/include/uapi/linux/ptrace.h @@ -102,6 +102,16 @@ struct ptrace_syscall_info { }; }; +#define PTRACE_GET_RSEQ_CONFIGURATION 0x420f + +struct ptrace_rseq_configuration { + __u64 rseq_abi_pointer; + __u32 rseq_abi_size; + __u32 signature; + __u32 flags; + __u32 pad; +}; + /* * These values are stored in task->ptrace_message * by tracehook_report_syscall_* to describe the current syscall-stop. diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 821cf17..c71270a 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -31,6 +31,7 @@ #include #include #include +#include #include /* for syscall_get_* */ @@ -779,6 +780,24 @@ static int ptrace_peek_siginfo(struct task_struct *child, return ret; } +#ifdef CONFIG_RSEQ +static long ptrace_get_rseq_configuration(struct task_struct *task, + unsigned long size, void __user *data) +{ + struct ptrace_rseq_configuration conf = { + .rseq_abi_pointer = (u64)(uintptr_t)task->rseq, + .rseq_abi_size = sizeof(*task->rseq), + .signature = task->rseq_sig, + .flags = 0, + }; + + size = min_t(unsigned long, size, sizeof(conf)); + if (copy_to_user(data, &conf, size)) + return -EFAULT; + return sizeof(conf); +} +#endif + #ifdef PTRACE_SINGLESTEP #define is_singlestep(request) ((request) == PTRACE_SINGLESTEP) #else @@ -1222,6 +1241,12 @@ int ptrace_request(struct task_struct *child, long request, ret = seccomp_get_metadata(child, addr, datavp); break; +#ifdef CONFIG_RSEQ + case PTRACE_GET_RSEQ_CONFIGURATION: + ret = ptrace_get_rseq_configuration(child, addr, datavp); + break; +#endif + default: break; }