[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200511140327.GO11244@42.do-not-panic.com>
Date: Mon, 11 May 2020 14:03:27 +0000
From: Luis Chamberlain <mcgrof@...nel.org>
To: Greg KH <gregkh@...uxfoundation.org>
Cc: axboe@...nel.dk, viro@...iv.linux.org.uk, bvanassche@....org,
rostedt@...dmis.org, mingo@...hat.com, jack@...e.cz,
ming.lei@...hat.com, nstange@...e.de, akpm@...ux-foundation.org,
mhocko@...e.com, yukuai3@...wei.com, linux-block@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, Omar Sandoval <osandov@...com>,
Hannes Reinecke <hare@...e.com>,
Michal Hocko <mhocko@...nel.org>,
Christof Schmitt <christof.schmitt@...ibm.com>,
syzbot+603294af2d01acfdd6da@...kaller.appspotmail.com
Subject: Re: [PATCH v4 3/5] blktrace: fix debugfs use after free
On Sun, May 10, 2020 at 08:26:36AM +0200, Greg KH wrote:
> On Sat, May 09, 2020 at 03:10:56AM +0000, Luis Chamberlain wrote:
> > diff --git a/block/blk-debugfs.c b/block/blk-debugfs.c
> > index 19091e1effc0..d40f12aecf8a 100644
> > --- a/block/blk-debugfs.c
> > +++ b/block/blk-debugfs.c
> > +static struct dentry *queue_debugfs_symlink_type(struct request_queue *q,
> > + const char *src,
> > + const char *dst,
> > + enum blk_debugfs_dir_type type)
> > +{
> > + struct dentry *dentry = ERR_PTR(-EINVAL);
> > + char *dir_dst;
> > +
> > + dir_dst = kzalloc(PATH_MAX, GFP_KERNEL);
> > + if (!dir_dst)
> > + return dentry;
> > +
> > + switch (type) {
> > + case BLK_DBG_DIR_BASE:
> > + if (dst)
> > + snprintf(dir_dst, PATH_MAX, "%s", dst);
> > + else if (!IS_ERR_OR_NULL(q->debugfs_dir))
> > + snprintf(dir_dst, PATH_MAX, "%s",
> > + q->debugfs_dir->d_name.name);
>
> How can debugfs_dir be NULL/error here?
If someone were to move blk_queue_debugfs_symlink() to sg_add_device(),
this can happen as the sd_probe() will run asynchronously. The comment
in blk_queue_debugfs_symlink() suggest to be mindful of async probes.
I can do-away with this *iff* we add an probe_complete call to the
driver core class interface.
> And grabbing the name of a debugfs file is sketchy, just use the name
> that you think you already have, from the device, don't rely on debugfs
> working here.
>
> And why a symlink anyway?
As the commit log explains, and the comment to the calling functions
explains, we have a shared request_queue, and this has been the way,
the symlink makes that sharing explicit. The next patch explains why
using two blktraces on two separate devices would fail, the symlink
makes this sharing quite obvious.
It also simplifies the trace/kernel/blktrace.c code to just use the
debugfs_dir only.
> THat's a new addition, what is going to work
> with that in userspace?
This already works in userspace with blktrace. If you see a regression,
please let me know.
> > +#ifdef CONFIG_DEBUG_FS
> > + p->debugfs_sym = blk_queue_debugfs_symlink(disk->queue, dev_name(pdev),
> > + disk->disk_name);
> > +#endif
>
> No need to #ifdef this, right?
It is needed because of the p->debugfs_sym.
> I feel like this patch series keeps getting more complex and messier
> over time :(
I'm afraid that use of blktrace in scsi-generic is the culprit, the
technical debt of the complexities around how the request_queue is
shared and properly providing backward compatibilty by removing the
debufs_looksup() has caught up to us.
If we were to agree to remove scsi-generic support from blktrace first,
that would simplify things hugely.
Luis
Powered by blists - more mailing lists