Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp812829ybh; Tue, 21 Jul 2020 08:29:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz42V9D/6CT2vmiaC2kxyqMugIyviLSjXvB4O3h1MPDVUzLygl5CPScMUrkh20LyCsSTxuW X-Received: by 2002:a17:906:cf91:: with SMTP id um17mr1493939ejb.168.1595345356313; Tue, 21 Jul 2020 08:29:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595345356; cv=none; d=google.com; s=arc-20160816; b=ZPmYEhHt4VGsoPZGFSZH89NecKzzR3QIm+xQSaapPKe5jvLBTud9M4TTuUwsqkJlov aPNgBjmOVwTlPwwRSgVf4fwyCd/bTc6eM5T2CuV5KboPA+fbSvyLZBmgKDhla9zia5Y5 mIidfcxQVFraYmqZp781tPvod8VQURjVGe374VoAitE/9f7QNxD9bxw8VcAJQF6qKAZK mSNqQd+MtjZq2sFLHKqGDevB4iaScO2lP670gf7Kr3YKaHKdCuLkO/KZwABUlddD72WE J+F3bk32USwt73sbqKJJKYHeIUVrW1APErtOPH+32W00j+ZWD1OKFtXpk3woE9qEpzFC Sb+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=5xxmOQgo+estZbjpC1HpW7vCzag/Is4XR6PgpDblQAg=; b=iHi3OhWNySuCRMRhxtvvFpF421dX4Tp4ejGYgocDZsPctT4JMBHtgv/J7GWKm5fSBl To3TkyW+7qdSVt/Rdv8fzsEz+VqW7ubozSYSHCuPZXiXdqvNQW9WAHpjz2UJCm4WkwrX tNxCBE06bWnQFyLPIhjsJnAz0jWtOUEPThq3QYEKnkuKChMbSFw9agLr2FhubvHCcyvB 40vGENOlOnzUP6plZ4fZrn88Gz5rMJcI6Ai1lFwhLapDxfKo0Sr09ZxorhAC6QZGb7nW qzvafercHqqFZjDYQNX5i5fSWxVSM/RzNQr8HYeDIio01g4PPa1OWWM/+lojztX30Wjc xiHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j0qRLvgm; 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 c95si17331943edf.304.2020.07.21.08.28.53; Tue, 21 Jul 2020 08:29:16 -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=j0qRLvgm; 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 S1728755AbgGUP1u (ORCPT + 99 others); Tue, 21 Jul 2020 11:27:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:56564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729045AbgGUP1t (ORCPT ); Tue, 21 Jul 2020 11:27:49 -0400 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E153C22C9E for ; Tue, 21 Jul 2020 15:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595345269; bh=dL7Jw9KmKIYfCmIThtzQuCIzVWDKDKywulNrdIg2buI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=j0qRLvgmYQ9iXUqJ4f4hiZXX+OC7ujiyWP5EZtQyEfF4iDeAt6CeXmdA0V1+otFGZ ePL1Enpmwdgg1XrlRvW3NTB4VJCiZ1CoYTXOS46oM3P/dYP/h46vNrhyvd6fFuYtck gxufNMXrr7yOktk0HDH9GFzFZXNYolk0wn50WmuA= Received: by mail-wr1-f41.google.com with SMTP id a14so6769004wra.5 for ; Tue, 21 Jul 2020 08:27:48 -0700 (PDT) X-Gm-Message-State: AOAM532S9UMMzkBUH0Mj6m9nA6wUE+36N1lGHwquOugEW71ebBWYwsCA IILKiMSsSoHAnEGy0gIYaS9viJYpwFg3R54ZcmISTg== X-Received: by 2002:a5d:5273:: with SMTP id l19mr17785233wrc.257.1595345267417; Tue, 21 Jul 2020 08:27:47 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: <20200717080157.ezxapv7pscbqykhl@steredhat.lan> From: Andy Lutomirski Date: Tue, 21 Jul 2020 08:27:34 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: strace of io_uring events? To: Stefano Garzarella , Jens Axboe , 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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 If we can do that, then we could bind seccomp-like io_uring filters to an mm, and we get obvious semantics that ought to cover most of the bases. Jens, Christoph? Stefano, what's your intended usecase for your restriction patchset?