Re: [PATCH v4 3/5] blktrace: fix debugfs use after free

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux