From: Al Viro <viro@zeniv.linux.org.uk>
To: syzbot <syzbot+b74150fd2ef40e716ca2@syzkaller.appspotmail.com>
Cc: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com,
Christian Brauner <christian@brauner.io>,
Stephen Rothwell <sfr@canb.auug.org.au>
Subject: Re: Forwarded: [PATCH] ipc/mqueue: fix dentry refcount imbalance in prepare_open()
Date: Sun, 30 Nov 2025 08:46:12 +0000 [thread overview]
Message-ID: <20251130084612.GT3538@ZenIV> (raw)
In-Reply-To: <20251130073017.GS3538@ZenIV>
On Sun, Nov 30, 2025 at 07:30:17AM +0000, Al Viro wrote:
> 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?
Mismerge in -next, actually.
static struct file *mqueue_file_open(struct filename *name,
struct vfsmount *mnt, int oflag, bool ro,
umode_t mode, struct mq_attr *attr)
{
struct path path __free(path_put) = {};
struct dentry *dentry;
struct file *file;
int ret;
dentry = start_creating_noperm(mnt->mnt_root, &QSTR(name->name));
if (IS_ERR(dentry))
return ERR_CAST(dentry);
path.dentry = dentry;
path.mnt = mntget(mnt);
ret = prepare_open(path.dentry, oflag, ro, mode, name, attr);
if (ret)
return ERR_PTR(ret);
This leaves with parent still locked
file = dentry_open(&path, oflag, current_cred());
end_creating(dentry);
return file;
... and this does double-dput, somewhat masked by the fact that in
"new file" case dentry had its refcount bumped to pin it down.
Folks, RAII is a dangerous thing, especially around source manipulations,
merging very much included...
next prev parent reply other threads:[~2025-11-30 8:46 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-29 13:05 [syzbot] [overlayfs?] WARNING in fast_dput syzbot
2025-11-29 21:58 ` Hillf Danton
2025-11-29 22:18 ` syzbot
2025-11-30 7:11 ` Forwarded: [PATCH] ipc/mqueue: fix dentry refcount imbalance in prepare_open() syzbot
2025-11-30 7:30 ` Al Viro
2025-11-30 8:46 ` Al Viro [this message]
2025-11-30 9:10 ` Al Viro
2025-11-30 10:52 ` [syzbot] [overlayfs?] WARNING in fast_dput Hillf Danton
2025-11-30 11:41 ` syzbot
2025-12-01 8:58 ` Amir Goldstein
2025-12-01 9:06 ` Al Viro
2025-12-01 9:07 ` Aleksandr Nogikh
2025-12-01 11:05 ` Amir Goldstein
2025-12-01 11:07 ` Aleksandr Nogikh
2025-12-01 12:11 ` Amir Goldstein
2025-12-01 10:18 ` syzbot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251130084612.GT3538@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=christian@brauner.io \
--cc=linux-kernel@vger.kernel.org \
--cc=sfr@canb.auug.org.au \
--cc=syzbot+b74150fd2ef40e716ca2@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox