From patchwork Thu Nov 20 05:13:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 41217 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1327820CBB for ; Thu, 20 Nov 2014 05:13:20 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id p9sf420545lbv.5 for ; Wed, 19 Nov 2014 21:13:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:references:in-reply-to:content-type :content-transfer-encoding:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=Y7DL6Fi+cZywSn527sY3yHoXgPyNhuGlX9htrPxOkDw=; b=XSBYV6nM76gWyvgIRp0OEMwYpHiAg1rRq2/XXF4a2OVBl0WvSvvSeMlmjafkl5YEUq xVh2vkMF6exbTLxEYM1TTyRaTd4MIuPFJ9VwlRhQvJmE+8wSHn+vfOY9DuSgy3NeV/D6 EVJ2HBitDrRzRlsXGAY2eUte28XlcD1rjLjYUn7aUniP1ZSOSmMMxeiCRIg8bNdoO4Ua 2bs1J2/NUfXbZIjLQR65a3rQcQ04puoyb/nYen1vjBODu3tCX0s8UZSYHjZunKUPiVqU bjlRml+kmtIzIStdqrxvXA8PfoclOS/lJG0GNbMEn3neBjzD7RBffRgCqx2ZnzRX5YEn qBDA== X-Gm-Message-State: ALoCoQkQ3s1hQtlkip4HnZgnfPQzLnTd0V6MDIe7TlV7lzkigUqGRCZvYMDn3Ihfc0p9qbwXX1O+ X-Received: by 10.194.176.106 with SMTP id ch10mr987413wjc.6.1416460398666; Wed, 19 Nov 2014 21:13:18 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.200 with SMTP id 8ls19478law.102.gmail; Wed, 19 Nov 2014 21:13:18 -0800 (PST) X-Received: by 10.152.42.172 with SMTP id p12mr45767524lal.11.1416460398381; Wed, 19 Nov 2014 21:13:18 -0800 (PST) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id x7si36797lag.84.2014.11.19.21.13.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Nov 2014 21:13:18 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by mail-la0-f53.google.com with SMTP id pn19so1828251lab.12 for ; Wed, 19 Nov 2014 21:13:18 -0800 (PST) X-Received: by 10.112.184.70 with SMTP id es6mr80080lbc.85.1416460398185; Wed, 19 Nov 2014 21:13:18 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp208443lbc; Wed, 19 Nov 2014 21:13:17 -0800 (PST) X-Received: by 10.70.48.38 with SMTP id i6mr53209862pdn.74.1416460396491; Wed, 19 Nov 2014 21:13:16 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sz2si1751855pac.44.2014.11.19.21.13.15 for ; Wed, 19 Nov 2014 21:13:16 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751466AbaKTFNO (ORCPT + 26 others); Thu, 20 Nov 2014 00:13:14 -0500 Received: from mail-pd0-f173.google.com ([209.85.192.173]:63649 "EHLO mail-pd0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750752AbaKTFNN (ORCPT ); Thu, 20 Nov 2014 00:13:13 -0500 Received: by mail-pd0-f173.google.com with SMTP id ft15so2328625pdb.18 for ; Wed, 19 Nov 2014 21:13:12 -0800 (PST) X-Received: by 10.66.248.104 with SMTP id yl8mr52805655pac.2.1416460392453; Wed, 19 Nov 2014 21:13:12 -0800 (PST) Received: from [192.168.1.157] (KD182249097096.au-net.ne.jp. [182.249.97.96]) by mx.google.com with ESMTPSA id aq1sm803357pbd.29.2014.11.19.21.13.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Nov 2014 21:13:11 -0800 (PST) Message-ID: <546D7860.2010300@linaro.org> Date: Thu, 20 Nov 2014 14:13:04 +0900 From: AKASHI Takahiro User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Will Deacon CC: "keescook@chromium.org" , Catalin Marinas , "dsaxena@linaro.org" , "arndb@arndb.de" , "linux-arm-kernel@lists.infradead.org" , "linaro-kernel@lists.linaro.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v8 2/6] arm64: ptrace: allow tracer to skip a system call References: <1416273038-15590-1-git-send-email-takahiro.akashi@linaro.org> <1416273038-15590-3-git-send-email-takahiro.akashi@linaro.org> <20141118140425.GM18842@arm.com> <546C58DB.5080204@linaro.org> <20141119190601.GM15985@arm.com> In-Reply-To: <20141119190601.GM15985@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: takahiro.akashi@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On 11/20/2014 04:06 AM, Will Deacon wrote: > On Wed, Nov 19, 2014 at 08:46:19AM +0000, AKASHI Takahiro wrote: >> On 11/18/2014 11:04 PM, Will Deacon wrote: >>> On Tue, Nov 18, 2014 at 01:10:34AM +0000, AKASHI Takahiro wrote: >>>> >>>> + if (((int)regs->syscallno == -1) && (orig_syscallno == -1)) { >>>> + /* >>>> + * user-issued syscall(-1): >>>> + * RESTRICTION: We always return ENOSYS whatever value is >>>> + * stored in x0 (a return value) at this point. >>>> + * Normally, with ptrace off, syscall(-1) returns -ENOSYS. >>>> + * With ptrace on, however, if a tracer didn't pay any >>>> + * attention to user-issued syscall(-1) and just let it go >>>> + * without a hack here, it would return a value in x0 as in >>>> + * other system call cases. This means that this system call >>>> + * might succeed and see any bogus return value. >>>> + * This should be definitely avoided. >>>> + */ >>>> + regs->regs[0] = -ENOSYS; >>>> + } >>> >>> I'm still really uncomfortable with this, and it doesn't seem to match what >>> arch/arm/ does either. >> >> Yeah, I know but >> as I mentioned before, syscall(-1) will be signaled on arm, and so we don't >> have to care about a return value :) > > What does x86 do? On x86, syscall(-1) returns -ENOSYS if not traced, and we can change a return value if traced. >>> Doesn't it also prevent a tracer from skipping syscall(-1)? >> >> Syscall(-1) will return -ENOSYS whether or not a syscallno is explicitly >> replaced with -1 by a tracer, and, in this sense, it is *skipped*. > > Ok, but now userspace sees -ENOSYS for a skipped system call in that case, > whereas it would usually see whatever the trace put in x0, right? Yes. If you don't really like this behavior, how about this patch instead of my [2/6] patch? With this change, I believe, syscall(-1) returns -ENOSYS by default whether traced or not, and still you can change a return value when tracing. (But a drawback here is that a tracer will see -ENOSYS in x0 even at syscall entry for syscall(-1).) -Takahiro AKASHI > Will > --- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 726b910..1ef57d0 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -668,8 +668,15 @@ ENDPROC(el0_svc) * switches, and waiting for our parent to respond. */ __sys_trace: + cmp w8, #-1 // default errno for invalid + b.ne 1f // system call + mov x0, #-ENOSYS + str x0, [sp, #S_X0] +1: mov x0, sp bl syscall_trace_enter + cmp w0, #-1 // skip the syscall? + b.eq __sys_trace_return_skipped adr lr, __sys_trace_return // return address uxtw scno, w0 // syscall number (possibly new) mov x1, sp // pointer to regs @@ -684,6 +691,7 @@ __sys_trace: __sys_trace_return: str x0, [sp] // save returned x0 +__sys_trace_return_skipped: mov x0, sp bl syscall_trace_exit b ret_to_user