From patchwork Fri Nov 7 07:47:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 5250691 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 41D35C11AC for ; Fri, 7 Nov 2014 07:50:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 326FF20149 for ; Fri, 7 Nov 2014 07:50:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 192E020145 for ; Fri, 7 Nov 2014 07:50:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XmeHO-0007WU-UN; Fri, 07 Nov 2014 07:48:22 +0000 Received: from mail-pd0-f177.google.com ([209.85.192.177]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XmeHK-0007RK-I5 for linux-arm-kernel@lists.infradead.org; Fri, 07 Nov 2014 07:48:19 +0000 Received: by mail-pd0-f177.google.com with SMTP id v10so2819436pde.36 for ; Thu, 06 Nov 2014 23:47:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=gJJu858whEKNIyb2W5ViAdP+qsYzkeDezq8hVtWk9+s=; b=kE9+en2XpnUKEjXyC5qPhaO6TKL+S8kjI/mL1piLv4FFLdkJc+7fzPhCjsv4/BkKMG y2A8Ni/CLQLsStt7Xs9IZTk0fEApJwBwR1BKEpSuOIe/tsPodFr6W/tgBgqxVrTP+S/0 1YWohnf5jJk6VpEVUmtSKBK3Fq3OzCijexx4eJTNGER+G136663QXBZLmjGXTQl7HKAq Txh65AR3dMjGZa1Xn05T9HvSL/J35gtcXjnXDtQqZOT61wXZoBekJQWA7bPF62xBuS7I Og6f+AKLtNXlmGoU3RqunlFMnDOjx7YciVDwbksGaOw6v787bwH7N5XlKE93TCHdeQ7g BZVQ== X-Gm-Message-State: ALoCoQlM3tqQsQ1B4IlYeixfWjcLVgAY6Xn1lJzOdP+RqzLO+4DK+fjcNt8kGVHFBbFBslVbdI7r X-Received: by 10.66.246.196 with SMTP id xy4mr10425396pac.29.1415346476278; Thu, 06 Nov 2014 23:47:56 -0800 (PST) Received: from localhost.localdomain (KD182249089020.au-net.ne.jp. [182.249.89.20]) by mx.google.com with ESMTPSA id gy5sm7835407pbc.68.2014.11.06.23.47.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 06 Nov 2014 23:47:55 -0800 (PST) From: AKASHI Takahiro To: roland@hack.frob.com, oleg@redhat.com Subject: [RFC] ptrace: add generic SET_SYSCALL request Date: Fri, 7 Nov 2014 16:47:23 +0900 Message-Id: <1415346443-28915-1-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141106_234818_653229_1E60F52A X-CRM114-Status: GOOD ( 12.20 ) X-Spam-Score: -0.7 (/) Cc: linaro-kernel@lists.linaro.org, linux@arm.linux.org.uk, keescook@chromium.org, will.deacon@arm.com, linux-kernel@vger.kernel.org, AKASHI Takahiro , dsaxena@linaro.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds a new generic ptrace request, PTRACE_SET_SYSCALL. It can be used to change a system call number as follows: ret = ptrace(pid, PTRACE_SET_SYSCALL, null, new_syscall_no); 'new_syscall_no' can be -1 to skip this system call, you need to modify a register's value, in arch-specific way, as return value though. Please note that we can't define PTRACE_SET_SYSCALL macro in uapi/linux/ptrace.h partly because its value on arm, 23, is used as another request on sparc. This patch also contains an example of change on arch side, arm. Only syscall_set_nr() is required to be defined in asm/syscall.h. Currently only arm has this request, while arm64 would also have it once my patch series of seccomp for arm64 is merged. It will also be usable for most of other arches. See the discussions in lak-ml: http://lists.infradead.org/pipermail/linux-arm-kernel/2014-November/300167.html Signed-off-by: AKASHI Takahiro --- arch/arm/include/asm/syscall.h | 7 +++++++ arch/arm/kernel/ptrace.c | 5 ----- kernel/ptrace.c | 6 ++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index e86c985..3e1d9c0 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -24,6 +24,13 @@ static inline int syscall_get_nr(struct task_struct *task, return task_thread_info(task)->syscall; } +static inline int syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, int syscall) +{ + task_thread_info(task)->syscall = syscall; + return 0; +} + static inline void syscall_rollback(struct task_struct *task, struct pt_regs *regs) { diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c index ef9119f..908bae8 100644 --- a/arch/arm/kernel/ptrace.c +++ b/arch/arm/kernel/ptrace.c @@ -853,11 +853,6 @@ long arch_ptrace(struct task_struct *child, long request, datap); break; - case PTRACE_SET_SYSCALL: - task_thread_info(child)->syscall = data; - ret = 0; - break; - #ifdef CONFIG_CRUNCH case PTRACE_GETCRUNCHREGS: ret = ptrace_getcrunchregs(child, datap); diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 54e7522..d7048fa 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -1001,6 +1001,12 @@ int ptrace_request(struct task_struct *child, long request, break; } #endif + +#ifdef PTRACE_SET_SYSCALL + case PTRACE_SET_SYSCALL: + ret = syscall_set_nr(child, task_pt_regs(child), data); + break; +#endif default: break; }