Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3080450ybt; Sat, 4 Jul 2020 05:51:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysBojWM+AfIk0Aporrle/LjYm1FyUyfBletmQJjV9G/kCMTH2FoHaqOrqR0TSkziXVxa6H X-Received: by 2002:a50:da44:: with SMTP id a4mr40375630edk.379.1593867101995; Sat, 04 Jul 2020 05:51:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593867101; cv=none; d=google.com; s=arc-20160816; b=acWZTdtnzD2y/6/tQzJFXWIQtybz2P2mWFFNW8SjNPCBSeIOfAXg+DAx8Ao411zup3 5/LX3GVIiS6mY0zAT7XaUi5Rjxy9nPHU98NO8p8eVIxsJtQuXHQKLTQIlVrP5bspDNFO YoNGvmqcy+vIkN10pQR7Qltg0mTuY0vgJXz2i/Rdz2BTu4rmv2LMM0yRgywZc50OBKu0 2xvpDmSZUblEoAZDsI4cYZ8oGJqq6+e37/FfG1VXATpj8DLeVPcN1ibLiyhMkLsATZ1A /zwLc8YxmytkXWv/ks9fh/9EqIZNUIi6MApsS/WAxwfE2sPA186LFc+MA5VpuLkc1o1G Pa6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=3vpcyVJ7OK5lB86teQmL1+DTn7ip8RaZT5k6NP3s3uo=; b=nmw7QUUtGcBxm4qkhaUYTihZ8Fx9Ptg5NZ6l/eyv5psGe8COLB2YsFkkPLQn02f8sK 4BtBI/EC5Z5Zv+HiGZcG5uNEsX3e35C3D03bQMazR9hi+nk3uJprbVoT/6wKEsSBX/41 v0rt9Rma4DW1JRsHtEofKHvKBTeZYAyPI1VzIkPupbyml6C8mJRaakgRRpx6ymqj1B/J BqkiHupm7htAZY/rholoLzKvWL9vI4+rV9yFtrRwc6dujjAzoJPJHFMZ8/PSnrUcuNCt 8A/BRrNxl9hOOXX2nONuDEZZ+MoSJ8bBn8ak4whZHSlbUXr7BPljX0NzXPKRetgV030Q Z58Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LUGt9Y9D; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds2si13070376ejc.114.2020.07.04.05.51.19; Sat, 04 Jul 2020 05:51:41 -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=@kernel.org header.s=default header.b=LUGt9Y9D; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726936AbgGDMuc (ORCPT + 99 others); Sat, 4 Jul 2020 08:50:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:35856 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726738AbgGDMuc (ORCPT ); Sat, 4 Jul 2020 08:50:32 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B57B520885; Sat, 4 Jul 2020 12:50:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593867031; bh=4XhuUQN3QNCuKbrbw9fG4qJ8DQkgRuvV3izCuziKVKk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LUGt9Y9D6tcO8lMDE/M9d56KUenZO8441sgpi2TquZUVjP0tEFiaqrdquhx3pPwKq K9YMs4T+uMlwEPCsUhuY55oNm/YeoLz3dXPifFGIpXrwY28T7srYgIPli2uXgza+E7 HCiIt3c2+93EtM+qPAF9IvfUEAtQthLksOjyvUSQ= Date: Sat, 4 Jul 2020 13:50:27 +0100 From: Will Deacon To: Keno Fischer Cc: Linux Kernel Mailing List , Oleg Nesterov , Kees Cook , Andy Lutomirski , Will Drewry Subject: Re: ptrace: seccomp: Return value when the call was already invalid Message-ID: <20200704125027.GB21185@willie-the-truck> References: <20200703083914.GA18516@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 03, 2020 at 04:27:37PM -0400, Keno Fischer wrote: > > > Now, if we have a seccomp filter that simply does > > > SECCOMP_RET_TRACE, and a ptracer that simply > > > does PTRACE_CONT > > > > Ok, so this means that we're _skipping_ the system call, right? > > If the system call were positive this would result in the system call > being executed. The notion of "skipping" the syscall is a bit odd in > this situation. Having the ptracer set the syscallno to -1 is generally > accepted as the way to do it, but what happens if the syscallno is > already -1 or negative is underspecified. Ok. I think it would be sensible for us to have the same behaviour for all negative system calls though. > > > then the assert will fire/fail on arm64, but not on x86_64. > > > > It feels weird to me that skipping the system call has any effect on the > > tracee registers... > > I think the correct way to frame it is to ask whether the behavior > matches that of the tracee in absence of the ptracer. I would argue > that if the ptracer doesn't explicitly modify register contents, then > the tracee shouldn't observe any behavior difference. That's a useful way of thinking about it and is still the case after this patch. The difference now is that x0 isn't zapped in the case where a syscall(-1) is skipped. > > > Interestingly, arm64 does do something different > > > if the syscall is -1 rather than -10, where early > > > in the ptrace stop it does. > > > ``` > > > /* set default errno for user-issued syscall(-1) */ > > > if (scno == NO_SYSCALL) > > > regs->regs[0] = -ENOSYS; > > > > ... so I think this should be fixed too. How about the diff below? > > I think the patch behavior is better overall, but I'm not sure it's ideal. > I think the biggest question is what the behavior should be here and > if we want a behavioral difference between *the syscall was -1 at entry* > and *the syscall was -1 because the ptracer wanted to skip the syscall*. > I think there is a bit of a semantic disconnect because "skipping" the > syscall is not really an operation that the ptracer has at its disposal > (unless it's using SYSEMU of course). The only thing it can do is set > the syscall to -1. However, arguably that already has semantics > (of returning -ENOSYS), so it's not at all clear to me that we should > deviate from that. Unfortunately, none of this is currently consistent > across architectures, so I think before we go changing arm64, we > should decide what we'd like to happen in theory and then see > what we can do to improve the situation without being too breaking. I just object to treating a user-issued -1 differently to any other negative system call. With this patch, they're all treated the same, which is to say that they return -ENOSYS normally, but when skipped by a tracer (e.g. by setting the syscall number to -1 or because of a seccomp failure), then x0 is preserved. This means that, with this patch, skipping syscall(-1) behaves the same way as skipping syscall(-2) with mainline today. Will