Skip to contentSkip to conversation

ramfs: skip mknod if inode already exists.

PATCH In review Chen Li 3 participants 5 messages Jun 16, 2021 – Jun 17, 2021 VFS

lore
Share & tools
lore

Chen Li

author
#0 lore raw

PATCH 1/1 ramfs: skip mknod if inode already exists.

It's possible we try to mknod a dentry, which have already bound to an inode, just skip it.

---
 fs/ramfs/inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/ramfs/inode.c +2 -0
index 9ebd17d7befb..6cb1de521142 100644
@@ -106,6 +106,8 @@ ramfs_mknod(struct user_namespace *mnt_userns, struct inode *dir,
 {
 	struct inode * inode = ramfs_get_inode(dir->i_sb, dir, mode, dev);
 	int error = -ENOSPC;
+	if (dentry->d_inode)
+		return -EEXIST;
 
 	if (inode) {
 		d_instantiate(dentry, inode);
Signature · 1 line
2.32.0
#1 lore raw
Quoted 3 lines · Chen Li

It's possible we try to mknod a dentry, which have already bound to an inode, just skip it.

How do you think this could happen?

author
#2 lore raw

Re: [PATCH] ramfs: skip mknod if inode already exists.【请注意,邮件由batv+ae8989e1668f84a74d37+6506+infradead.org+hch@casper.srs.infradead.org代发】

Quoted 9 lines · Christoph Hellwig
Quoted 3 lines · Chen Li

It's possible we try to mknod a dentry, which have already bound to an inode, just skip it.

How do you think this could happen?

Sorry, that's my bad. I noticed unionfs used to do this check in 9c5b4452998c6e670cfde0928b277e9c50d9a676, but not sure is it a must.

maintainer
#3 lore raw
In reply to Chen Li
Quoted 3 lines · Chen Li

It's possible we try to mknod a dentry, which have already bound to an inode, just skip it.

Caller should have checked may_create(), which includes EEXIST handling.

Incidentally, if it ever had been called that way, your variant would leak inode. Not the main problem, though...

author
#4 lore raw

Re: [PATCH] ramfs: skip mknod if inode already exists.【请注意,邮件由[email protected]代发】

Quoted 8 lines · Al Viro
Quoted 3 lines · Chen Li

It's possible we try to mknod a dentry, which have already bound to an inode, just skip it.

Caller should have checked may_create(), which includes EEXIST handling.

Don't know may_create before, thanks!

Quoted 5 lines

Incidentally, if it ever had been called that way, your variant would leak inode. Not the main problem, though...