Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp815814ybh; Tue, 21 Jul 2020 08:32:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwH8jUKNPlAo7Iv7xVdkYpUc+UOAgeHQbx3LBerpXhlb0BxfzAobenR798XJS9Jm/UfCKSx X-Received: by 2002:a17:906:3009:: with SMTP id 9mr25181347ejz.220.1595345565569; Tue, 21 Jul 2020 08:32:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595345565; cv=none; d=google.com; s=arc-20160816; b=p0j/T40yUQcj1nhWua1uPS6ofUpi3DS6uR27dRoFwglhq7AFPecKRJt50ti70a4GEP 1Es05onqZ3LvMOIqzWd+2eeBDgD2wcnOxYaqmcdMmoPHI+NKxwnBp0/RGP2b4WorJkEr pzS14KShz98dXXG/F3W6hnh/3ZYSy4gSpYjUKuvVNIyIqOg6j5srQEoWUtwzpZs/vNqP w7Mni+g/N9jfNxk7pzSOTc/Bks6gq/enVV+uSx9pnffzxZjqWMva3tQwUNort4fnwBYs +wOtgbyKek3JVQRobXdYisVDe5J8WTZcSfAcQ4DTZ9DyhBxKKpy/LG83L6argW3GACwr JGjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=fHBXXvobeCMI6ndgKtMZ3erxdMcJPIdl8aMUBZkOTPQ=; b=VNL9fMDceWpdTxXHTqRLpLJBPw+z1iEytf05WiUzwCLzwPiEPfTSy5CT+rnVPWAlQN 9PUMoJXaL+DJbezyR8heHcazYJGqLDJ5JcaL9QzS7/ROhOqB3F0q/YXnOW/l937yKiEY Y9B0IKz2pgVjl4b43qkcg6vmoX4JWqk7RbUMK9v+q9C5aDnFGbozeVHhYTTMS+WRl5IK oHGJpAnZ8qv5sOmgkdFjjUofLeQkn1wta6Yl4bmvlUl/D7xZxClqETzCNwz4KCyGcyfi FusLqp88/hriN6zdvLwlIQEwYKd7I4htYvJeK7D/zpwPhWO8FnrXzGlGQ6VEE6BwgDGG xQDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=FjGoLNE3; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qo11si12905780ejb.566.2020.07.21.08.32.20; Tue, 21 Jul 2020 08:32:45 -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-dk.20150623.gappssmtp.com header.s=20150623 header.b=FjGoLNE3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726654AbgGUPb7 (ORCPT + 99 others); Tue, 21 Jul 2020 11:31:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728391AbgGUPb6 (ORCPT ); Tue, 21 Jul 2020 11:31:58 -0400 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59B65C0619DA for ; Tue, 21 Jul 2020 08:31:58 -0700 (PDT) Received: by mail-il1-x142.google.com with SMTP id t18so16757599ilh.2 for ; Tue, 21 Jul 2020 08:31:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=fHBXXvobeCMI6ndgKtMZ3erxdMcJPIdl8aMUBZkOTPQ=; b=FjGoLNE3u7Lnj6Y4gzoT0kgYXHm5TPhi7odJEJ19IH/bXifIJkm9g9cRYI1n9gNuSu q8PssjRLHeidmWFf4uLpcuAYGmRmaf89V572BB2JHkU1x19AUKNTC+k2xOn6qyRI9n0C qmt5Am2rGnwheI/zqG93vJNWkUiYQqwIo0DFKcDPZrvGsrwwC0EEwGut5OC5+QkAoPOX BI6Zfk31k5IlcnMFpxsqIjhd1aDaR8T90B0zI79dBIwKvQX13ndd1DCNVRjdlGQj0Vd+ vDdcbnaBPAIYK0k1jvm+zwdwTjBqn675UdeHBWGIZ+Ey9zJ+n2NfmxiGLL3ZMmSJdVeP K3Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=fHBXXvobeCMI6ndgKtMZ3erxdMcJPIdl8aMUBZkOTPQ=; b=Tunt49qFUeZfC2U4dcblO/WfECH4OTDQijblOJgYtMpqVhM5NUokicsidVcmYwvhjD zlK5j3s8c1Ov7lSudPXXVVic7e5M6EfCVHIC/g7W/xVAfDKoQRRIE9GswBr9EzQO4lJR jq/zAeDGEyt5avvo9XKGhxC3i2v+9cLAFYCsJrXvkCks5kmD2E9+lK2PWvy/kgkp6JjI x5fme0fM/1/0i4vrJu1jb7Lla5eirduvi1soiSoSRcBK62E7bB733/T++tZG0M+OYBGv 1sC78xP8YfTcBGQJ9/j9PB6AMonTyXLKA22AXiPSZOrDCklKUKw3Cn8Nxr45SzXfJoZA kJTQ== X-Gm-Message-State: AOAM531y+jRAya1kM50HIyP/J08AfzAt6mn2yqo29LIJaVReLA0UwjTx DtTs9BIRBRmlgCpMHhIzKe0tLA== X-Received: by 2002:a05:6e02:e05:: with SMTP id a5mr26782990ilk.92.1595345517510; Tue, 21 Jul 2020 08:31:57 -0700 (PDT) Received: from [192.168.1.58] ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id c3sm10507002ilj.31.2020.07.21.08.31.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Jul 2020 08:31:56 -0700 (PDT) Subject: Re: strace of io_uring events? To: Andy Lutomirski , Stefano Garzarella , Christoph Hellwig Cc: Kees Cook , Pavel Begunkov , Miklos Szeredi , Matthew Wilcox , Jann Horn , Christian Brauner , strace-devel@lists.strace.io, io-uring@vger.kernel.org, Linux API , Linux FS Devel , LKML , Michael Kerrisk , Stefan Hajnoczi References: <20200715171130.GG12769@casper.infradead.org> <7c09f6af-653f-db3f-2378-02dca2bc07f7@gmail.com> <48cc7eea-5b28-a584-a66c-4eed3fac5e76@gmail.com> <202007151511.2AA7718@keescook> <20200716131404.bnzsaarooumrp3kx@steredhat> <202007160751.ED56C55@keescook> <20200717080157.ezxapv7pscbqykhl@steredhat.lan> From: Jens Axboe Message-ID: <39a3378a-f8f3-6706-98c8-be7017e64ddb@kernel.dk> Date: Tue, 21 Jul 2020 09:31:54 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/21/20 9:27 AM, Andy Lutomirski wrote: > On Fri, Jul 17, 2020 at 1:02 AM Stefano Garzarella wrote: >> >> On Thu, Jul 16, 2020 at 08:12:35AM -0700, Kees Cook wrote: >>> On Thu, Jul 16, 2020 at 03:14:04PM +0200, Stefano Garzarella wrote: > >>> access (IIUC) is possible without actually calling any of the io_uring >>> syscalls. Is that correct? A process would receive an fd (via SCM_RIGHTS, >>> pidfd_getfd, or soon seccomp addfd), and then call mmap() on it to gain >>> access to the SQ and CQ, and off it goes? (The only glitch I see is >>> waking up the worker thread?) >> >> It is true only if the io_uring istance is created with SQPOLL flag (not the >> default behaviour and it requires CAP_SYS_ADMIN). In this case the >> kthread is created and you can also set an higher idle time for it, so >> also the waking up syscall can be avoided. > > I stared at the io_uring code for a while, and I'm wondering if we're > approaching this the wrong way. It seems to me that most of the > complications here come from the fact that io_uring SQEs don't clearly > belong to any particular security principle. (We have struct creds, > but we don't really have a task or mm.) But I'm also not convinced > that io_uring actually supports cross-mm submission except by accident > -- as it stands, unless a user is very careful to only submit SQEs > that don't use user pointers, the results will be unpredictable. How so? > Perhaps we can get away with this: > > diff --git a/fs/io_uring.c b/fs/io_uring.c > index 74bc4a04befa..92266f869174 100644 > --- a/fs/io_uring.c > +++ b/fs/io_uring.c > @@ -7660,6 +7660,20 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, > fd, u32, to_submit, > if (!percpu_ref_tryget(&ctx->refs)) > goto out_fput; > > + if (unlikely(current->mm != ctx->sqo_mm)) { > + /* > + * The mm used to process SQEs will be current->mm or > + * ctx->sqo_mm depending on which submission path is used. > + * It's also unclear who is responsible for an SQE submitted > + * out-of-process from a security and auditing perspective. > + * > + * Until a real usecase emerges and there are clear semantics > + * for out-of-process submission, disallow it. > + */ > + ret = -EACCES; > + goto out; > + } > + > /* > * For SQ polling, the thread will do all submissions and completions. > * Just return the requested submit count, and wake the thread if That'll break postgres that already uses this, also see: commit 73e08e711d9c1d79fae01daed4b0e1fee5f8a275 Author: Jens Axboe Date: Sun Jan 26 09:53:12 2020 -0700 Revert "io_uring: only allow submit from owning task" So no, we can't do that. -- Jens Axboe