From patchwork Thu May 23 09:06:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 164951 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1913820ili; Thu, 23 May 2019 02:06:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4c+Ji8Gjg9JRN7o2rUvLT/wT62O0IS4JQB3YAAVRsyZm4RxJZgf/qFypKkp+6MI0UKT+i X-Received: by 2002:a65:554d:: with SMTP id t13mr95025670pgr.171.1558602405479; Thu, 23 May 2019 02:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558602405; cv=none; d=google.com; s=arc-20160816; b=ut+G+dNjOaTiEA/uT3IEc5CtieFaydrx/ceA5gHQxCPwOlzAz4Kt9n5qAf6qdTlUYv Hu7kFI+h/HA06lZXSFK7+9iGOWtOJ11YTpOi38ThDpGdQJgsAcdAO9tQjNnw+VArZCwJ mqOAupoxMDlDwCawi1W3TxmDAQr0wOwpH0vZonml6e4AGu94gXhgp5c4rMZLu3tiX6Xl IcjrLBZiZPRjwx2aUpSd1p49NnOctjFmUDrb4DS6PKKEK3ptT2j3cA+ZBoX8OVZyYv04 knuSC3s5ObkcXWjlIqHVDUJhms2Npp4RHZaF1Hs1embz6rSXVzBvHtqIm6w8N6dp7Pfu DvYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=3ZvwLZCDodsw6fzWUuXOmDQ6/ZwliopnGtXfOoCPfqA=; b=jBxQ4yBC/h2gkXLygxOUFC2yxyVWbTgwzBuhBJA0j+EahYA6uQ9f6FB922AQGvO39l b+/tw55bRstgqtJiqdbLHMzTtY2TVASC6Ilc4dWKs+V5mOOAyP1l6LpfucNRogU7QGXk WlSpzQtJxbfuBep/dSENoOgHE0FCfQmaiAPV4NbKWqilhp4KoZ3XoxscRrNbDQ4qc2T7 zBg0i4ZIrq5S7qNkySP0NjosV7ULTDc3Gl37D8VO22TLSxy6Pq25F5cpqss1SO7dISFl zlNDRlvxcActDg1Jk/puAZu2NllZL+2NzLCFfjsab6OwxiAtGizTbw9l8qPqOHT0WxNK nCTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si1821854pgp.592.2019.05.23.02.06.45; Thu, 23 May 2019 02:06:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730305AbfEWJGo (ORCPT + 30 others); Thu, 23 May 2019 05:06:44 -0400 Received: from foss.arm.com ([217.140.101.70]:40794 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729898AbfEWJGm (ORCPT ); Thu, 23 May 2019 05:06:42 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2102B165C; Thu, 23 May 2019 02:06:42 -0700 (PDT) Received: from usa.arm.com (e107155-lin.cambridge.arm.com [10.1.196.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0D7903F575; Thu, 23 May 2019 02:06:39 -0700 (PDT) From: Sudeep Holla To: x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Sudeep Holla , Catalin Marinas , Will Deacon , Oleg Nesterov , Richard Weinberger , jdike@addtoit.com, Steve Capper , Haibo Xu , Bin Lu Subject: [PATCH v4 4/4] arm64: ptrace: add support for syscall emulation Date: Thu, 23 May 2019 10:06:18 +0100 Message-Id: <20190523090618.13410-5-sudeep.holla@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190523090618.13410-1-sudeep.holla@arm.com> References: <20190523090618.13410-1-sudeep.holla@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add PTRACE_SYSEMU and PTRACE_SYSEMU_SINGLESTEP support on arm64. We don't need any special handling for PTRACE_SYSEMU_SINGLESTEP. It's quite difficult to generalize handling PTRACE_SYSEMU cross architectures and avoid calls to tracehook_report_syscall_entry twice. Different architecture have different mechanism to indicate NO_SYSCALL and trying to generalise adds more code for no gain. Cc: Catalin Marinas Cc: Will Deacon Signed-off-by: Sudeep Holla --- arch/arm64/include/asm/thread_info.h | 5 ++++- arch/arm64/kernel/ptrace.c | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h index eb3ef73e07cf..c285d1ce7186 100644 --- a/arch/arm64/include/asm/thread_info.h +++ b/arch/arm64/include/asm/thread_info.h @@ -75,6 +75,7 @@ void arch_release_task_struct(struct task_struct *tsk); * TIF_SYSCALL_TRACE - syscall trace active * TIF_SYSCALL_TRACEPOINT - syscall tracepoint for ftrace * TIF_SYSCALL_AUDIT - syscall auditing + * TIF_SYSCALL_EMU - syscall emulation active * TIF_SECOMP - syscall secure computing * TIF_SIGPENDING - signal pending * TIF_NEED_RESCHED - rescheduling necessary @@ -91,6 +92,7 @@ void arch_release_task_struct(struct task_struct *tsk); #define TIF_SYSCALL_AUDIT 9 #define TIF_SYSCALL_TRACEPOINT 10 #define TIF_SECCOMP 11 +#define TIF_SYSCALL_EMU 12 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */ #define TIF_FREEZE 19 #define TIF_RESTORE_SIGMASK 20 @@ -109,6 +111,7 @@ void arch_release_task_struct(struct task_struct *tsk); #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT) #define _TIF_SECCOMP (1 << TIF_SECCOMP) +#define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU) #define _TIF_UPROBE (1 << TIF_UPROBE) #define _TIF_FSCHECK (1 << TIF_FSCHECK) #define _TIF_32BIT (1 << TIF_32BIT) @@ -120,7 +123,7 @@ void arch_release_task_struct(struct task_struct *tsk); #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \ - _TIF_NOHZ) + _TIF_NOHZ | _TIF_SYSCALL_EMU) #define INIT_THREAD_INFO(tsk) \ { \ diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index b82e0a9b3da3..9353355cb91a 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -1819,8 +1819,12 @@ static void tracehook_report_syscall(struct pt_regs *regs, int syscall_trace_enter(struct pt_regs *regs) { - if (test_thread_flag(TIF_SYSCALL_TRACE)) + if (test_thread_flag(TIF_SYSCALL_TRACE) || + test_thread_flag(TIF_SYSCALL_EMU)) { tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER); + if (!in_syscall(regs) || test_thread_flag(TIF_SYSCALL_EMU)) + return -1; + } /* Do the secure computing after ptrace; failures should be fast. */ if (secure_computing(NULL) == -1)