linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs/vfs: Release allocated dentry on failure in do_last()
@ 2017-12-07  2:46 穆阿浩(姜弋)
  2017-12-07  5:30 ` Matthew Wilcox
  2017-12-07 12:39 ` Al Viro
  0 siblings, 2 replies; 5+ messages in thread
From: 穆阿浩(姜弋) @ 2017-12-07  2:46 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: viro, 渡波,
	穆阿浩(姜弋),
	张礼广(乱石)

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().

   # rm /dev/sdtest
   # dd if=/dev/urandom of=/dev/sdtest bs=4k count=1 oflag=direct
     <-EINVAL is returned>
   # ls /dev/sdtest
     <File is still existing>

This fixes the issue by releasing the dentry, thus the inode on failure
in do_last(). With this applied, the file (/dev/sdtest) isn't seen
in this scenario.

Reported-by: YouYou <youyou.wy.huang@foxconn.com>
Signed-off-by: Gavin Shan <dubo.sgw@alibaba-inc.com>
Signed-off-by: Liguang Zhang <liguang.zlg@alibaba-inc.com>
Signed-off-by: Ahao Mu <ahao.mah@alibaba-inc.com>
---
 fs/namei.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/namei.c b/fs/namei.c
index 9cc91fb..607c357 100644
--- a/fs/namei.c
+++ 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)
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-12-08  3:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-07  2:46 [PATCH] fs/vfs: Release allocated dentry on failure in do_last() 穆阿浩(姜弋)
2017-12-07  5:30 ` Matthew Wilcox
2017-12-08  3:14   ` 渡波
2017-12-07 12:39 ` Al Viro
2017-12-08  3:11   ` 渡波

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).