From patchwork Thu Feb 28 18:32:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 159425 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp987728oce; Thu, 28 Feb 2019 10:32:38 -0800 (PST) X-Google-Smtp-Source: APXvYqya/x7ulRrgY/bY3iDHwItUWMmh/qMQlFjHIBLr9a8XQjrXadXvMitgKLlsKS9aCuxjhy5z X-Received: by 2002:a63:545:: with SMTP id 66mr555563pgf.102.1551378758425; Thu, 28 Feb 2019 10:32:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378758; cv=none; d=google.com; s=arc-20160816; b=SBBgc5ZJSTXox+RB7UpqloiSFt/tcw+nSmUm6pyIUYBSUvGJEK5bazFGzcDLrFVTr8 1XXy9GiT+Y1f+/T2DIC9fUC0KRipaAUX8VQ5TNQoFwm3mv5NDIe2+pW8QXJcxlMLWxoq q+HUKhMKI2IOU9maEPsKqRfkeQ13GPo9TpszA4Yo98M2qQ5GsOhNOmsXsBwI3bcLNUbp p+9AoWDJeep097uYxJuatcrhUjaH6DmjX3/qcywYnun7xUqiWTYiDfEYDNKTZhAJqVUG jcy3NUSmpexEwqJeZ5FBX9+fntEGkpnryrmHEIu36CgH1Y0+rMLUToYn4aLd6nl1Y2d/ 50mQ== 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=at6N6ssaZjC6lmdVgXImiNAFkkaVQHY4gTvRWworWOs=; b=y8ruQGjcJsSJOT3/f4u1d3CQfjW/31fKRq50SQs/MaQMVuo2aFQUAwpm+mad8rF1ih EuksU02/Omz+UCdAJVamcPev8PPr3Hr5ZbRVXSPXKktGFVJf+iWePzNRg1jSjdEP1bBt xF4uor/hccw/513o8gsQCaOqGVc6uCtLRyxdzh2GQb+v5C91iVsB9EuUcXZZ7TJiHedM keK7vi8xr3D7MNJ7P610vrRMASyi5XeEKDaFE0ZILZmOwMQcXX26pDxpy2cK7uBT8FDt 2b4nrOyU2uwvlznFUMt9Y30HNLxDD30zYrdr3qbEcCmrxAPmC+xP0y0Xf6y8h6/cWqls 1Y2g== 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 l8si17657951plt.88.2019.02.28.10.32.38; Thu, 28 Feb 2019 10:32:38 -0800 (PST) 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 S2387558AbfB1Sch (ORCPT + 31 others); Thu, 28 Feb 2019 13:32:37 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:52884 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732645AbfB1Scf (ORCPT ); Thu, 28 Feb 2019 13:32:35 -0500 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 C37C81684; Thu, 28 Feb 2019 10:32:34 -0800 (PST) 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 F38093F5C1; Thu, 28 Feb 2019 10:32:31 -0800 (PST) From: Sudeep Holla To: x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Sudeep Holla , Catalin Marinas , Will Deacon , Oleg Nesterov , Paul Mackerras , Michael Ellerman , Thomas Gleixner , Ingo Molnar , Richard Weinberger , jdike@addtoit.com, Steve Capper , Haibo Xu , Bin Lu Subject: [PATCH 2/6] ptrace: introduce ptrace_syscall_enter to consolidate PTRACE_SYSEMU handling Date: Thu, 28 Feb 2019 18:32:16 +0000 Message-Id: <20190228183220.15626-3-sudeep.holla@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190228183220.15626-1-sudeep.holla@arm.com> References: <20190228183220.15626-1-sudeep.holla@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently each architecture handles PTRACE_SYSEMU in very similar way. It's completely arch independent and can be handled in the code helping to consolidate PTRACE_SYSEMU handling. Let's introduce a hook 'ptrace_syscall_enter' that arch specific syscall entry code can call. Cc: Oleg Nesterov Signed-off-by: Sudeep Holla --- include/linux/ptrace.h | 1 + kernel/ptrace.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) -- 2.17.1 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h index edb9b040c94c..e30f51e3363e 100644 --- a/include/linux/ptrace.h +++ b/include/linux/ptrace.h @@ -407,6 +407,7 @@ static inline void user_single_step_report(struct pt_regs *regs) #define current_user_stack_pointer() user_stack_pointer(current_pt_regs()) #endif +extern long ptrace_syscall_enter(struct pt_regs *regs); extern int task_current_syscall(struct task_struct *target, long *callno, unsigned long args[6], unsigned int maxargs, unsigned long *sp, unsigned long *pc); diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 4fa3b7f4c3c7..6724eaf98e79 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -29,6 +29,7 @@ #include #include #include +#include /* * Access another process' address space via ptrace. @@ -557,6 +558,21 @@ static int ptrace_detach(struct task_struct *child, unsigned int data) return 0; } +/* + * Hook to check and report for PTRACE_SYSEMU, can be called from arch + * arch syscall entry code + */ +long ptrace_syscall_enter(struct pt_regs *regs) +{ +#ifdef TIF_SYSCALL_EMU + if (test_thread_flag(TIF_SYSCALL_EMU)) { + if (tracehook_report_syscall_entry(regs)); + return -1L; + } +#endif + return 0; +} + /* * Detach all tasks we were using ptrace on. Called with tasklist held * for writing.