Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp979748ybz; Fri, 1 May 2020 12:04:30 -0700 (PDT) X-Google-Smtp-Source: APiQypL8eEm8O0pI9YLBbS999g2F1rmWLJHpyf8Pew9jmNf9n1RAqvkg1jimILEWZmZNb/H2RexD X-Received: by 2002:a50:99c4:: with SMTP id n4mr4949453edb.187.1588359870735; Fri, 01 May 2020 12:04:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588359870; cv=none; d=google.com; s=arc-20160816; b=mFFmv7DQbgMnl1yRrWdIgOvNf4OlmLa/SXDriC02YlVl4GtrQ5QfW+IwxZC/Gz5Pmg BC+tWoXx87TrQmh/ghHI9ziDz7XBHzWqwQJlRzyNgY7LTkqclovGH0tguMXk2bvX40dt PNOLIxZrki90Ygmx4rcA24+3ZOAgcGthtdc6GllpvxpgQDJw2qr/mVCypwkgS+F4d9fu zyJ49vhRISRWT2qznxcftGGn1zwhbxTvgLnF843Y5XZbrR0xKSHKrZxfBbzaf7EWizUU enEVSzEYdnh+RF2eAPRlVRgnRboIcO3h/avLWwRv/Q80WHOoNNPpzpG6SbZhGswh5n1U r19A== 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=TlylstnpHUvvy2kXZXWi+CjnHUB1LYs2pIMYnjjWD74=; b=OXqnlQWefhvnEfbQqEjehKycEXaCPZZTExR5F08v827SPYdYvrXdhFjFHmprAybfc9 DtkWcuzGIBV+Xa3oKwoYLcQZY4Eev6GEKRaQUthAYGXyp1rMeoDtLfGk5PBRrHzybHeG pbqJO4NVwK5ak2zPdY+juVUlISqO7gpnqHEua+6zqu9nDcXOm2BcRYpbu53Mc4zNeUQs FMCPt4xPIlqpBjL0K+iQc6Fo1C5mSDTIu62qteAkmwDjBSx5LZU/xZm6NxpqaljCq/fE GF2whO5OV5TNAmdESncaW2+xweY0duIKt6R3BLquFFbwmLGrreObtNx4tOOnbzgzgawM 7FJQ== 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 w13si2455758ejj.231.2020.05.01.12.03.58; Fri, 01 May 2020 12:04:30 -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 S1730381AbgEATAV (ORCPT + 99 others); Fri, 1 May 2020 15:00:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729766AbgEATAV (ORCPT ); Fri, 1 May 2020 15:00:21 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E10DC061A0C; Fri, 1 May 2020 12:00:21 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jUatW-00G8Kl-V5; Fri, 01 May 2020 19:00:19 +0000 Date: Fri, 1 May 2020 20:00:18 +0100 From: Al Viro To: Jens Axboe Cc: linux-fsdevel , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v3b] eventfd: convert to f_op->read_iter() Message-ID: <20200501190018.GN23230@ZenIV.linux.org.uk> References: <97a28bdb-284a-c215-c04d-288bcef66376@kernel.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <97a28bdb-284a-c215-c04d-288bcef66376@kernel.dk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 01, 2020 at 11:54:01AM -0600, Jens Axboe wrote: > @@ -427,8 +424,17 @@ static int do_eventfd(unsigned int count, int flags) > > fd = anon_inode_getfd("[eventfd]", &eventfd_fops, ctx, > O_RDWR | (flags & EFD_SHARED_FCNTL_FLAGS)); > - if (fd < 0) > + if (fd < 0) { > eventfd_free_ctx(ctx); > + } else { > + struct file *file; > + > + file = fget(fd); > + if (file) { > + file->f_mode |= FMODE_NOWAIT; > + fput(file); > + } No. The one and only thing you can do to return value of anon_inode_getfd() is to return the fscker to userland. You *CAN* *NOT* assume that descriptor table is still pointing to whatever you've just created. As soon as it's in descriptor table, it's out of your hands. And frankly, if you are playing with descriptors, you should be very well aware of that. Descriptor tables are fundamentally shared objects; they *can* be accessed and modified by other threads, right behind your back. *IF* you are going to play with ->f_mode, you must use get_unused_fd_flags(), anon_inode_getfile(), modify ->f_mode of the result and use fd_install() to put it into descriptor table. With put_unused_fd() as cleanup in case of allocation failure.