From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bombadil.infradead.org ([65.50.211.133]:40987 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750767AbdLGFaF (ORCPT ); Thu, 7 Dec 2017 00:30:05 -0500 Date: Wed, 6 Dec 2017 21:30:03 -0800 From: Matthew Wilcox To: =?utf-8?B?56mG6Zi/5rWpKOWnnOW8iyk=?= Cc: linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, =?utf-8?B?5rih5rOi?= , =?utf-8?B?5byg56S85bm/KOS5seefsyk=?= Subject: Re: [PATCH] fs/vfs: Release allocated dentry on failure in do_last() Message-ID: <20171207053003.GA2739@bombadil.infradead.org> References: <1512614782-46982-1-git-send-email-ahao.mah@alibaba-inc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1512614782-46982-1-git-send-email-ahao.mah@alibaba-inc.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Thu, Dec 07, 2017 at 10:46:22AM +0800, 穆阿浩(姜弋) wrote: > This issue is found when creating /dev/sdtest with flags (O_CREAT | > O_DIRECT). The file still can be retrieved even after system reports > failure (-EINVAL) for it. Reporting error on creating the file is > correct behaviour because either devtmpfs or tmpfs doesn't support > O_DIRECT for regular file. However, it's incorrect that the file is > still existing. The cause is the newly allocated dentry and inode > aren't released on failure in do_last(). Previously reported: https://www.spinics.net/lists/linux-fsdevel/msg89317.html https://www.spinics.net/lists/linux-fsdevel/msg113680.html http://lkml.iu.edu/hypermail/linux/kernel/1609.0/04556.html > +++ b/fs/namei.c > @@ -3382,6 +3382,8 @@ static int do_last(struct nameidata *nd, > *opened |= FILE_OPENED; > opened: > error = open_check_o_direct(file); > + if (error && (*opened & FILE_OPENED)) > + dput(path.dentry); > if (!error) > error = ima_file_check(file, op->acc_mode, *opened); > if (!error && will_truncate) Umm ... I think it's too late. This will work well enough for in-memory filesystems, but if you have a real filesystem, there's no call back to the filesystem to remove the directory entry, right?