Re: [RFC 0/3] block: address blktrace use-after-free

From: Luis Chamberlain
Date: Tue Apr 07 2020 - 15:00:12 EST


On Tue, Apr 07, 2020 at 10:47:01AM +0800, yukuai (C) wrote:
> On 2020/4/3 16:19, Ming Lei wrote:
>
> > BTW, Yu Kuai posted one patch for this issue, looks that approach
> > is simpler:
> >
> > https://lore.kernel.org/linux-block/20200324132315.22133-1-yukuai3@xxxxxxxxxx/
> >
> >
>
> I think the issue might not be fixed with the patch seires.
>
> At first, I think there are two key points for the issure:
> 1. The final release of queue is delayed in a workqueue
> 2. The creation of 'q->debugfs_dir' might failed(only if 1 exist)
> And if we can fix any of the above problem, the UAF issue will be fixed.
> (BTW, I did not come up with a good idea for problem 1, and my approach
> is for problem 2.)
>
> The third patch "block: avoid deferral of blk_release_queue() work" is
> not enough to fix problem 1:
> a. if CONFIG_DEBUG_KOBJECT_RELEASE is enable:
> static void kobject_release(struct kref *kref)
> {
> struct kobject *kobj = container_of(kref, struct kobject, kref);
> #ifdef CONFIG_DEBUG_KOBJECT_RELEASE
> unsigned long delay = HZ + HZ * (get_random_int() & 0x3);
> pr_info("kobject: '%s' (%p): %s, parent %p (delayed %ld)\n",
> âkobject_name(kobj), kobj, __func__, kobj->parent, delay);
> INIT_DELAYED_WORK(&kobj->release, kobject_delayed_cleanup);
>
> schedule_delayed_work(&kobj->release, delay);
> #else
> kobject_cleanup(kobj);
> #endif
> }
> b. when 'kobject_put' is called from blk_cleanup_queue, can we make sure
> it is the last reference?

You are right, I think I know the fix for this now. Will run some more
tests.

Luis