Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1160524ybj; Thu, 7 May 2020 16:33:28 -0700 (PDT) X-Google-Smtp-Source: APiQypLucQ21JghstJl9R1evf6bwYKqdj7qFNzfWgx8Wv8MH+DiQ1sVYMNGAO9VX6sj3qznKeixu X-Received: by 2002:a17:907:20b5:: with SMTP id pw21mr13869538ejb.227.1588894408571; Thu, 07 May 2020 16:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588894408; cv=none; d=google.com; s=arc-20160816; b=yhRV2jvvtU0fb7/JNgn9ycAqofmJuWP4BGKWYvF759WxEIZfN3B7J2vQQYtuM7dKMX BG9JmQeLqktU8bUyeJfY0WryAIxc9qLf5CGRq3FU++csLNcMuf8hSAlNtL2E3wIIMsvR jSRlaNJkGCK7fSuytANxxlLoBpIDph+gA+6/Di0njKnJ1sU8tALlQ2g4dm8Vyl1wxU4a dIack0P21CSsT59JyrQxBdZ194cpkeEvkK6sw1594H6cCqM427jDUDjMX+aQLWSwm5QO EdsuPk4L+fwQ9r8pYdUeea+587Sd6/M0OSrf6EWylYU4uiEQ/ZF/0tlDaicK7w7kSA9h PW1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=16yVuN0mAAOpiXPyt0abSGgUR0qDFqoLv6e08ntlceg=; b=w3HpjIBUGBQYhPzAgvZboBnEPuLME6PNKi/Lv9x6IJ1PEk6vT5RNjBUmLOBQqgGTUW 1zhahQqgv0wmT6Og2qespslKgCP9gpH1xvQqsCGQuuHeZHJTDxh3zbb/hg6Jse1sa6qn R1N1cmbKaIrtW5WtGv5AX+C62PDDgoqVN183KxYLw/fm2bTQEEqyxytJAudaWabRp+Tq TrWHJvapppy4vTVPk1vrS+FDQe0WSR1683O+9uJqvDuB1oVffEGevy2KRxyAcSvum0BI OMvJRyMRyphktU6ffYqo92n25u155wVhEkO7zP50yVLUdjDN9eeL+wX0mU/Q4JhY1WNf eVRg== ARC-Authentication-Results: i=1; mx.google.com; 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 j17si4099660edq.404.2020.05.07.16.33.05; Thu, 07 May 2020 16:33:28 -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; 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 S1726690AbgEGXbh (ORCPT + 99 others); Thu, 7 May 2020 19:31:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726445AbgEGXbg (ORCPT ); Thu, 7 May 2020 19:31:36 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A10CC05BD43; Thu, 7 May 2020 16:31:36 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jWpzI-003Ikq-FG; Thu, 07 May 2020 23:31:32 +0000 Date: Fri, 8 May 2020 00:31:32 +0100 From: Al Viro To: Jens Axboe Cc: Max Kellermann , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] fs/io_uring: fix O_PATH fds in openat, openat2, statx Message-ID: <20200507233132.GJ23230@ZenIV.linux.org.uk> References: <20200507185725.15840-1-mk@cm4all.com> <20200507190131.GF23230@ZenIV.linux.org.uk> <4cac0e53-656c-50f0-3766-ae3cc6c0310a@kernel.dk> <20200507192903.GG23230@ZenIV.linux.org.uk> <8e3c88cc-027b-4f90-b4f8-a20d11d35c4b@kernel.dk> <20200507220637.GH23230@ZenIV.linux.org.uk> <283c8edb-fea2-5192-f1d6-3cc57815b1e2@kernel.dk> <20200507224447.GI23230@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 07, 2020 at 05:03:17PM -0600, Jens Axboe wrote: > On 5/7/20 4:44 PM, Al Viro wrote: > > On Thu, May 07, 2020 at 04:25:24PM -0600, Jens Axboe wrote: > > > >> static int io_close(struct io_kiocb *req, bool force_nonblock) > >> { > >> + struct files_struct *files = current->files; > >> int ret; > >> > >> req->close.put_file = NULL; > >> - ret = __close_fd_get_file(req->close.fd, &req->close.put_file); > >> + spin_lock(&files->file_lock); > >> + if (req->file->f_op == &io_uring_fops || > >> + req->close.fd == req->ctx->ring_fd) { > >> + spin_unlock(&files->file_lock); > >> + return -EBADF; > >> + } > >> + > >> + ret = __close_fd_get_file_locked(files, req->close.fd, > >> + &req->close.put_file); > > > > Pointless. By that point req->file might have nothing in common with > > anything in any descriptor table. > > How about the below then? Stop using req->file, defer the lookup until > we're in the handler instead. Not sure the 'fd' check makes sense > at this point, but at least we should be consistent in terms of > once we lookup the file and check the f_op. Actually, what _is_ the reason for that check? Note, BTW, that if the file in question happens to be an AF_UNIX socket, closing it will close all references held in SCM_RIGHTS datagrams sitting in its queue, which might very well include io_uring files. IOW, if tries to avoid something really unpleasant, it's not enough. And if it doesn't, then what is it for?