Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2272801ybl; Sat, 14 Dec 2019 09:15:07 -0800 (PST) X-Google-Smtp-Source: APXvYqxbh3H5QXVIDqtqVl9cgK2oyBQCake9zYelBByh9mg6t3scJN2aqEeLVkTvhknPcCtfP2QL X-Received: by 2002:a9d:2028:: with SMTP id n37mr22461811ota.127.1576343707330; Sat, 14 Dec 2019 09:15:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576343707; cv=none; d=google.com; s=arc-20160816; b=waZrPvinqoUy2jC2xSpIu2UU/qPGmnP2Ydc9NhwaXNw39aKUIhQEeJlVbdr6bT7/mO +an/dkR78++kdvHaf+AUdyPzoWCVFq0VGs8T0MSucgVoZV/nnCNh11BGZEp0g3kOPLcg Vb5Pt2QjRT3e+/GEW/MpueCoZFSZmVYfMfvy0ZyDTEpLqOuoD+Zgt+dDXzM2gKOIe4SA 3osiNKb6PD5w0m4fAlysQOWVHICIDWPBgElgLAH5X0VLtrsqMAUc6oQX9OUZELTNDhSF M0Vy+jAgqW4E5lXYCMQfiGhBxn3lT6sArDmPJgZX6L2jmubqW+YcmjBxowRJ7gLpdCFA 9saA== 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=LfuFNZhwpZHLnF3djKVjiT3EXeRjqk5hTlCJtr0Ug00=; b=GOQe3KQALv5lPZftqpbKve5COQKVWyoJPJlP3yL7LE9ukUJFhIlSvHqsIkyqwer7vE Pkz6xEZJWKdm3o6wnuoVg0NAXfuz2Gq5uztNz8nyqMSeIbLSd2vMrOEMHKYKku9xLc0l 1Ulmc4xs0dw/tDeqHyRmzulqzeKuyzfgz43UccYEMR0tfAjBgfNWQZh0E1ya2AIxA3I6 VZSsfOC2DknEdSV/bVsN8VpuHNenfjI9eLWu662kP5Oq/SvA4inGdDp8lT5g34YPP0HH wu5/Sk52/CpUK/Ge6cNdW6cx1nLyuQgKCiQ0rLzR8jXhWdaUfmcSsZk7mPihAryDOq6S SXMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TlCmN7o1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v18si6902324otn.257.2019.12.14.09.14.42; Sat, 14 Dec 2019 09:15:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TlCmN7o1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726705AbfLNRMb (ORCPT + 99 others); Sat, 14 Dec 2019 12:12:31 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:42635 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726072AbfLNRMb (ORCPT ); Sat, 14 Dec 2019 12:12:31 -0500 Received: by mail-ot1-f65.google.com with SMTP id 66so3238443otd.9 for ; Sat, 14 Dec 2019 09:12:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LfuFNZhwpZHLnF3djKVjiT3EXeRjqk5hTlCJtr0Ug00=; b=TlCmN7o1+fMNUBHz9erkJfWUoUdU6UO2mLwWb8l2OezOxScfm59l9mw928OPcn/yBa Xhl+xxt7CRSQs9M26xhDkm0qpkDohbNZy5JaN5ECOL9h9XnMmCPoEBL1boRtojpbvgrc Ght8Wj+dD1eb0lSCrS3fpEAdVkxj2pV3eVXKkOg2ENf8l6nkaINwPxGpfnRGOwnquFZc pL+qz0HFXn0mlj4DE6458MEirDfF3fb7wxRjGscI3mH4+5qfrIvYwDZFGFMHTIVinPJ6 SeqqPws1nPIVuGyx08gfwwZCFxeSIBu8z58WeOa3KajNbYjPAgDuhFKblJLY/acUYb2P EJ5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LfuFNZhwpZHLnF3djKVjiT3EXeRjqk5hTlCJtr0Ug00=; b=PzsH/sl1Xn+VB75HE0MnY91me+LZL2cucdQSvzyfBgvpXLGRHAZLUE6vJC70kv3Bfi InSUFSIgnALe8N6ue+A57s864LqbJ92o1MCjKLmr0hVTttlll3kRgD8KVAwfV/qNUsQi ugZKF2CTOOnF61M7E2znQ5v/ydaHCTERPiWLuDXG7p1pbeR2wJJhrbRA1zKvan69Se9j I+JmtkDu0hM+aUcO6IBYQ8nyk980L78SJrBFQ6wG/mD7bObdcP3bjdcS5BxUVQW1s8yD UkHK6gYGWbHWHZMxjPSZ02R1NN9p4PRpxpA+C84fKsrZl01XI5VjE+NCtoK29N89ZyRA A9HA== X-Gm-Message-State: APjAAAUa9UBFUvpgu3KKCvdVB6pYwjTQ+bYWaAOO17/43kbyhjMW+PEZ N7SnxGS/sh5nXg/Uizrhlnfn6ErgkOFK7eH5VCLavw== X-Received: by 2002:a9d:4789:: with SMTP id b9mr22242455otf.110.1576343549895; Sat, 14 Dec 2019 09:12:29 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jann Horn Date: Sat, 14 Dec 2019 18:12:03 +0100 Message-ID: Subject: Re: [RFC PATCH] io_uring: add support for IORING_OP_IOCTL To: Pavel Begunkov Cc: Jens Axboe , io-uring , kernel list 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 Sat, Dec 14, 2019 at 4:30 PM Pavel Begunkov wrote: > This works almost like ioctl(2), except it doesn't support a bunch of > common opcodes, (e.g. FIOCLEX and FIBMAP, see ioctl.c), and goes > straight to a device specific implementation. > > The case in mind is dma-buf, drm and other ioctl-centric interfaces. > > Not-yet Signed-off-by: Pavel Begunkov > --- > > It clearly needs some testing first, though works fine with dma-buf, > but I'd like to discuss whether the use cases are convincing enough, > and is it ok to desert some ioctl opcodes. For the last point it's > fairly easy to add, maybe except three requiring fd (e.g. FIOCLEX) > > P.S. Probably, it won't benefit enough to consider using io_uring > in drm/mesa, but anyway. [...] > +static int io_ioctl(struct io_kiocb *req, > + struct io_kiocb **nxt, bool force_nonblock) > +{ > + const struct io_uring_sqe *sqe = req->sqe; > + unsigned int cmd = READ_ONCE(sqe->ioctl_cmd); > + unsigned long arg = READ_ONCE(sqe->ioctl_arg); > + int ret; > + > + if (!req->file) > + return -EBADF; > + if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL)) > + return -EINVAL; > + if (unlikely(sqe->ioprio || sqe->addr || sqe->buf_index > + || sqe->rw_flags)) > + return -EINVAL; > + if (force_nonblock) > + return -EAGAIN; > + > + ret = security_file_ioctl(req->file, cmd, arg); > + if (!ret) > + ret = (int)vfs_ioctl(req->file, cmd, arg); This isn't going to work. For several of the syscalls that were added, special care had to be taken to avoid bugs - like for RECVMSG, for the upcoming OPEN/CLOSE stuff, and so on. And in principle, ioctls handlers can do pretty much all of the things syscalls can do, and more. They can look at the caller's PID, they can open and close (well, technically that's slightly unsafe, but IIRC autofs does it anyway) things in the file descriptor table, they can give another process access to the calling process in some way, and so on. If you just allow calling arbitrary ioctls through io_uring, you will certainly get bugs, and probably security bugs, too. Therefore, I would prefer to see this not happen at all; and if you do have a usecase where you think the complexity is worth it, then I think you'll have to add new infrastructure that allows each file_operations instance to opt in to having specific ioctls called via this mechanism, or something like that, and ensure that each of the exposed ioctls only performs operations that are safe from uring worker context. Also, I'm not sure, but it might be a good idea to CC linux-api if you continue working on this.