From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA416C433B4 for ; Fri, 16 Apr 2021 16:01:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E781611ED for ; Fri, 16 Apr 2021 16:01:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239164AbhDPQBi (ORCPT ); Fri, 16 Apr 2021 12:01:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:34544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239252AbhDPQBM (ORCPT ); Fri, 16 Apr 2021 12:01:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4241A6113D; Fri, 16 Apr 2021 16:00:42 +0000 (UTC) Date: Fri, 16 Apr 2021 18:00:38 +0200 From: Christian Brauner To: Al Viro Cc: Greg KH , Xie Yongji , hch@infradead.org, arve@android.com, tkjos@android.com, maco@android.com, joel@joelfernandes.org, hridya@google.com, surenb@google.com, sargun@sargun.me, keescook@chromium.org, jasowang@redhat.com, devel@driverdev.osuosl.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 2/2] binder: Use receive_fd() to receive file from another process Message-ID: <20210416160038.ojbhqf73dkrl4dk6@wittgenstein> References: <20210401090932.121-3-xieyongji@bytedance.com> <20210401104034.52qaaoea27htkpbh@wittgenstein> <20210416134252.v3zfjp36tpk33tqz@wittgenstein> <20210416151310.nqkxfwocm32lnqfq@wittgenstein> <20210416155815.ayjpnx37dv3a4jos@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210416155815.ayjpnx37dv3a4jos@wittgenstein> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Fri, Apr 16, 2021 at 05:58:25PM +0200, Christian Brauner wrote: > On Fri, Apr 16, 2021 at 03:35:59PM +0000, Al Viro wrote: > > On Fri, Apr 16, 2021 at 05:13:10PM +0200, Christian Brauner wrote: > > > > > My point here was more that the _file_ has already been opened _before_ > > > that call to io_uring_add_task_file(). But any potential non-trivial > > > side-effects of opening that file that you correctly pointed out in an > > > earlier mail has already happened by that time. > > > > The file comes from io_uring_get_file(), the entire thing is within the > > io_ring_ctx constructor and the only side effect there is ->ring_sock > > creation. And that stays until the io_ring_ctx is freed. I'm _not_ > > saying I like io_uring style in general, BTW - in particular, > > ->ring_sock->file handling is a kludge (as is too much of interation > > with AF_UNIX machinery there). But from side effects POV we are fine > > there. > > > > > Granted there are more > > > obvious examples, e.g. the binder stuff. > > > > > > int fd = get_unused_fd_flags(O_CLOEXEC); > > > > > > if (fd < 0) { > > > binder_debug(BINDER_DEBUG_TRANSACTION, > > > "failed fd fixup txn %d fd %d\n", > > > t->debug_id, fd); > > > ret = -ENOMEM; > > > break; > > > } > > > binder_debug(BINDER_DEBUG_TRANSACTION, > > > "fd fixup txn %d fd %d\n", > > > t->debug_id, fd); > > > trace_binder_transaction_fd_recv(t, fd, fixup->offset); > > > fd_install(fd, fixup->file); > > > fixup->file = NULL; > > > if (binder_alloc_copy_to_buffer(&proc->alloc, t->buffer, > > > fixup->offset, &fd, > > > sizeof(u32))) { > > > ret = -EINVAL; > > > break; > > > } > > > > ... and it's actually broken, since this > > /* All copies must be 32-bit aligned and 32-bit size */ > > if (!check_buffer(alloc, buffer, buffer_offset, bytes)) > > return -EINVAL; > > in binder_alloc_copy_to_buffer() should've been done *before* > > fd_install(). If anything, it's an example of the situation when > > fd_receive() would be wrong... > > They could probably refactor this but I'm not sure why they'd bother. If > they fail processing any of those files they end up aborting the > whole transaction. > (And the original code didn't check the error code btw.) (dma_buf_fd() seems like another good candidate. But again, I don't have any plans to shove this down anyone's throat.)