Re: Forwarded: [PATCH] ipc/mqueue: fix dentry refcount imbalance in prepare_open()

From: Al Viro

Date: Sun Nov 30 2025 - 02:30:08 EST


On Sat, Nov 29, 2025 at 11:11:24PM -0800, syzbot wrote:

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

That makes no sense.

> --- a/ipc/mqueue.c
> +++ b/ipc/mqueue.c
> @@ -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;

... we return an error without refcount increment.

> acc = oflag2acc[oflag & O_ACCMODE];
> + dget(dentry);
> return inode_permission(&nop_mnt_idmap, d_inode(dentry), acc);

... with possibly return an error *with* refcount increment.
How the caller is supposed to tell one from another?