All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luis Chamberlain <mcgrof@kernel.org>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: axboe@kernel.dk, viro@zeniv.linux.org.uk, bvanassche@acm.org,
	rostedt@goodmis.org, mingo@redhat.com, jack@suse.cz,
	ming.lei@redhat.com, nstange@suse.de, akpm@linux-foundation.org,
	mhocko@suse.com, yukuai3@huawei.com, linux-block@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, Omar Sandoval <osandov@fb.com>,
	Hannes Reinecke <hare@suse.com>, Michal Hocko <mhocko@kernel.org>,
	Christof Schmitt <christof.schmitt@de.ibm.com>,
	syzbot+603294af2d01acfdd6da@syzkaller.appspotmail.com
Subject: Re: [PATCH v4 3/5] blktrace: fix debugfs use after free
Date: Mon, 11 May 2020 14:03:27 +0000	[thread overview]
Message-ID: <20200511140327.GO11244@42.do-not-panic.com> (raw)
In-Reply-To: <20200510062636.GA3400311@kroah.com>

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

  reply	other threads:[~2020-05-11 14:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-09  3:10 [PATCH v4 0/5] block: fix blktrace debugfs use after free Luis Chamberlain
2020-05-09  3:10 ` [PATCH v4 1/5] block: revert back to synchronous request_queue removal Luis Chamberlain
2020-05-10  0:36   ` Bart Van Assche
2020-05-10  6:20   ` Greg KH
2020-05-11 13:41     ` Luis Chamberlain
2020-05-09  3:10 ` [PATCH v4 2/5] block: move main block debugfs initialization to its own file Luis Chamberlain
2020-05-09  3:10 ` [PATCH v4 3/5] blktrace: fix debugfs use after free Luis Chamberlain
2020-05-09  7:46   ` kbuild test robot
2020-05-09  8:01   ` kbuild test robot
2020-05-10  0:58   ` Bart Van Assche
2020-05-11 13:44     ` Luis Chamberlain
2020-05-10  6:26   ` Greg KH
2020-05-11 14:03     ` Luis Chamberlain [this message]
2020-05-09  3:10 ` [PATCH v4 4/5] blktrace: break out of blktrace setup on concurrent calls Luis Chamberlain
2020-05-10  1:09   ` Bart Van Assche
2020-05-11 13:39     ` Luis Chamberlain
2020-05-16  1:39       ` Luis Chamberlain
2020-05-16  1:39         ` Luis Chamberlain
2020-05-09  3:10 ` [PATCH v4 5/5] loop: be paranoid on exit and prevent new additions / removals Luis Chamberlain

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=20200511140327.GO11244@42.do-not-panic.com \
    --to=mcgrof@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=christof.schmitt@de.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hare@suse.com \
    --cc=jack@suse.cz \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=mhocko@suse.com \
    --cc=ming.lei@redhat.com \
    --cc=mingo@redhat.com \
    --cc=nstange@suse.de \
    --cc=osandov@fb.com \
    --cc=rostedt@goodmis.org \
    --cc=syzbot+603294af2d01acfdd6da@syzkaller.appspotmail.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yukuai3@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.