From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.linuxfoundation.org ([140.211.169.12]:47225 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757619AbbKFTWg (ORCPT ); Fri, 6 Nov 2015 14:22:36 -0500 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Junichi Nomura , Keith Busch , Jeff Moyer , Jens Axboe Subject: [PATCH 4.2 100/110] blk-mq: fix use-after-free in blk_mq_free_tag_set() Date: Fri, 6 Nov 2015 11:19:47 -0800 Message-Id: <20151106191709.195586157@linuxfoundation.org> In-Reply-To: <20151106191703.247930828@linuxfoundation.org> References: <20151106191703.247930828@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Sender: stable-owner@vger.kernel.org List-ID: 4.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Junichi Nomura commit f42d79ab67322e51b92dd7aa965e310c71352a64 upstream. tags is freed in blk_mq_free_rq_map() and should not be used after that. The problem doesn't manifest if CONFIG_CPUMASK_OFFSTACK is false because free_cpumask_var() is nop. tags->cpumask is allocated in blk_mq_init_tags() so it's natural to free cpumask in its counter part, blk_mq_free_tags(). Fixes: f26cdc8536ad ("blk-mq: Shared tag enhancements") Signed-off-by: Jun'ichi Nomura Cc: Keith Busch Reviewed-by: Jeff Moyer Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-mq-tag.c | 1 + block/blk-mq.c | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) --- a/block/blk-mq-tag.c +++ b/block/blk-mq-tag.c @@ -628,6 +628,7 @@ void blk_mq_free_tags(struct blk_mq_tags { bt_free(&tags->bitmap_tags); bt_free(&tags->breserved_tags); + free_cpumask_var(tags->cpumask); kfree(tags); } --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2263,10 +2263,8 @@ void blk_mq_free_tag_set(struct blk_mq_t int i; for (i = 0; i < set->nr_hw_queues; i++) { - if (set->tags[i]) { + if (set->tags[i]) blk_mq_free_rq_map(set, set->tags[i], i); - free_cpumask_var(set->tags[i]->cpumask); - } } kfree(set->tags);