Skip to contentSkip to conversation

ipc/mqueue: fix dentry refcount imbalance in prepare_open()

PATCH In review Deepanshu Kartikey 4 participants 6 messages Nov 30, 2025 – Dec 1, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipc/mqueue: fix dentry refcount imbalance in prepare_open()

When opening an existing message queue, prepare_open() does not increment the dentry refcount, but end_creating() always calls dput(). This causes a refcount imbalance that triggers a WARN_ON_ONCE in fast_dput() when the file is later closed.

The creation path via vfs_mkobj() correctly increments the refcount, but the "already exists" path was missing the corresponding dget().

Add the missing dget() call when opening an existing queue to balance the dput() in end_creating().

---
 ipc/mqueue.c | 1 +
 1 file changed, 1 insertion(+)
ipc/mqueue.c +1 -0
index 328bcc3ee3ad..63ff2c322549 100644
@@ -883,6 +883,7 @@ static int prepare_open(struct dentry *dentry, int oflag, int ro,
 	if ((oflag & O_ACCMODE) == (O_RDWR | O_WRONLY))
 		return -EINVAL;
 	acc = oflag2acc[oflag & O_ACCMODE];
+	dget(dentry);
 	return inode_permission(&nop_mnt_idmap, d_inode(dentry), acc);
 }
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 11 lines · Deepanshu Kartikey

When opening an existing message queue, prepare_open() does not increment the dentry refcount, but end_creating() always calls dput(). This causes a refcount imbalance that triggers a WARN_ON_ONCE in fast_dput() when the file is later closed.

The creation path via vfs_mkobj() correctly increments the refcount, but the "already exists" path was missing the corresponding dget().

Add the missing dget() call when opening an existing queue to balance the dput() in end_creating().

Sorry but this analysis looks wrong.

AFAIS, the bug was that end_creating() should have been before the out_putfd label just as path_put() was before the commit.

Quoted 3 lines

Fix should have

Fixes c9ba789dad15b ("VFS: introduce start_creating_noperm() and

start_removing_noperm()")

But I see this is already fixed by the FD_ADD() work and mqueue_file_open() helper by Christian.

Specifically, the bug was fixed by the merge conflict resolution d6ea5537c1a66 Merge tag 'vfs-6.19-rc1.fd_prepare' of gitolite.kernel.org:pub/scm/linux/kernel/git/vfs/vfs into vfs.all

Which should be in linux-next from yesterday.

Christian,

Do you think we need a fix mid-way before the merge of FD_ADD()?

Thanks,
Amir.

#2 lore raw
Quoted 8 lines · Amir Goldstein
Quoted 6 lines · Deepanshu Kartikey

When opening an existing message queue, prepare_open() does not increment the dentry refcount, but end_creating() always calls dput(). This causes a refcount imbalance that triggers a WARN_ON_ONCE in fast_dput() when the file is later closed.

Quoted 7 lines
Quoted 5 lines

The creation path via vfs_mkobj() correctly increments the refcount, but the "already exists" path was missing the corresponding dget().

Add the missing dget() call when opening an existing queue to balance the dput() in end_creating().

Sorry but this analysis looks wrong.

Agreed. vfs_mkobj() takes a ref (via mqueue_create_attr) on a newly created dentry to keep it in dcache. The open-existing path doesn't need to do that.

Quoted 3 lines

AFAIS, the bug was that end_creating() should have been before the out_putfd label just as path_put() was before the commit.

Disagree. Moving end_creating() earlier to before out_putfd: would only affect code paths that "goto out_putfd". The only code that does that in when path.dentry is an IS_ERR() so there is nothing to dput.

I don't think there is a bug here. The dput() issue in the syzkaller report below has already been addressed by an overlayfs fix in ovl_lock_rename_workdir().

Thanks,
NeilBrown

Quoted 25 lines
Quoted 4 lines

Fix should have

Fixes c9ba789dad15b ("VFS: introduce start_creating_noperm() and

start_removing_noperm()")

But I see this is already fixed by the FD_ADD() work and mqueue_file_open() helper by Christian.

Specifically, the bug was fixed by the merge conflict resolution d6ea5537c1a66 Merge tag 'vfs-6.19-rc1.fd_prepare' of gitolite.kernel.org:pub/scm/linux/kernel/git/vfs/vfs into vfs.all

Which should be in linux-next from yesterday.

Christian,

Do you think we need a fix mid-way before the merge of FD_ADD()?

Thanks,
Amir.

#3 lore raw
Quoted 26 lines · NeilBrown
Quoted 8 lines · Amir Goldstein
Quoted 6 lines · Deepanshu Kartikey

When opening an existing message queue, prepare_open() does not increment the dentry refcount, but end_creating() always calls dput(). This causes a refcount imbalance that triggers a WARN_ON_ONCE in fast_dput() when the file is later closed.

Quoted 7 lines
Quoted 5 lines

The creation path via vfs_mkobj() correctly increments the refcount, but the "already exists" path was missing the corresponding dget().

Add the missing dget() call when opening an existing queue to balance the dput() in end_creating().

Sorry but this analysis looks wrong.

Agreed. vfs_mkobj() takes a ref (via mqueue_create_attr) on a newly created dentry to keep it in dcache. The open-existing path doesn't need to do that.

Quoted 3 lines

AFAIS, the bug was that end_creating() should have been before the out_putfd label just as path_put() was before the commit.

Quoted 8 lines

Disagree. Moving end_creating() earlier to before out_putfd: would only affect code paths that "goto out_putfd". The only code that does that in when path.dentry is an IS_ERR() so there is nothing to dput.

I don't think there is a bug here. The dput() issue in the syzkaller report below has already been addressed by an overlayfs fix in ovl_lock_rename_workdir().

Maybe so, but the syzbot repro has nothing to do with overlayfs I have absolutely no idea why the bot tagged this report as [overlayfs] but I will ask it to retest on upstream.

Thanks,
Amir.

#4 lore raw
Quoted 36 lines · Amir Goldstein
Quoted 26 lines · NeilBrown
Quoted 8 lines · Amir Goldstein
Quoted 6 lines · Deepanshu Kartikey

When opening an existing message queue, prepare_open() does not increment the dentry refcount, but end_creating() always calls dput(). This causes a refcount imbalance that triggers a WARN_ON_ONCE in fast_dput() when the file is later closed.

Quoted 7 lines
Quoted 5 lines

The creation path via vfs_mkobj() correctly increments the refcount, but the "already exists" path was missing the corresponding dget().

Add the missing dget() call when opening an existing queue to balance the dput() in end_creating().

Sorry but this analysis looks wrong.

Agreed. vfs_mkobj() takes a ref (via mqueue_create_attr) on a newly created dentry to keep it in dcache. The open-existing path doesn't need to do that.

Quoted 3 lines

AFAIS, the bug was that end_creating() should have been before the out_putfd label just as path_put() was before the commit.

Quoted 8 lines

Disagree. Moving end_creating() earlier to before out_putfd: would only affect code paths that "goto out_putfd". The only code that does that in when path.dentry is an IS_ERR() so there is nothing to dput.

I don't think there is a bug here. The dput() issue in the syzkaller report below has already been addressed by an overlayfs fix in ovl_lock_rename_workdir().

Quoted 7 lines

Maybe so, but the syzbot repro has nothing to do with overlayfs I have absolutely no idea why the bot tagged this report as [overlayfs] but I will ask it to retest on upstream.

Thanks,
Amir.

The patch we are replying to contained

That page says
Subsystems: overlayfs
and

Status: upstream: reported C repro on 2025/11/29 13:05 which is a link to
https://groups.google.com/g/syzkaller-bugs/c/rcOfN4hdoHw/m/pw0jTqSiCAAJ

which I misread as mentioning my recent ovl patch as a fix, but it doesn't.

Al says it was a mismerge in -next, which has been resolved.

https://lore.kernel.org/all/20251130084612.GT3538@ZenIV

Sorry for blaming ovl :-)

NeilBrown

#5 lore raw
Quoted 1 line · NeilBrown

Al says it was a mismerge in -next, which has been resolved.

In vfs-common/vfs.all, actually, and it had been resolved there, too late for the last -next of the week...