From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B009C433FF for ; Fri, 9 Aug 2019 13:47:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E0310217F4 for ; Fri, 9 Aug 2019 13:47:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565358456; bh=e2DIQVMMi3yR2vEVsSG5Vk16/gOOU9jsKQN4DNooXhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=AB6pW10xQ4iIKa9rkuiF9Iy8MYpLHXWkyC7aFHPToApvWwlcHhU5KFQQY3ez7/DVl v36wvw1dubx45NMMtTG4txujkMtp35cynLYlB9HERtYb7CL/h1LwAg+8wBlfXVhYbj 5/GscalFTej1MK/hYZweVHuF5x6Pq24gFoIBReno= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436612AbfHINre (ORCPT ); Fri, 9 Aug 2019 09:47:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:37410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406726AbfHINrY (ORCPT ); Fri, 9 Aug 2019 09:47:24 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DCB68218BE; Fri, 9 Aug 2019 13:47:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565358443; bh=e2DIQVMMi3yR2vEVsSG5Vk16/gOOU9jsKQN4DNooXhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uJF+SvxaisyqF05yMBVpcDEKNXaaolvVZBrLoILvetoqBiq9VF6XbB/swN6AL5X3A UWOXcX1A8RnA3oVaKXg8nKcd2z6N0RNpsJHqsV/3D4aW+CLeoPoi1prlLG10EMgUob mCy39thsx/cuJhAU/Ly+gXvGHF8idWEYk1K9Oa/0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ming Lei , Bart Van Assche , xiao jin , Jens Axboe , Guenter Roeck , Alessio Balsini Subject: [PATCH 4.9 26/32] block: blk_init_allocated_queue() set q->fq as NULL in the fail case Date: Fri, 9 Aug 2019 15:45:29 +0200 Message-Id: <20190809133923.771602436@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190809133922.945349906@linuxfoundation.org> References: <20190809133922.945349906@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: xiao jin commit 54648cf1ec2d7f4b6a71767799c45676a138ca24 upstream. We find the memory use-after-free issue in __blk_drain_queue() on the kernel 4.14. After read the latest kernel 4.18-rc6 we think it has the same problem. Memory is allocated for q->fq in the blk_init_allocated_queue(). If the elevator init function called with error return, it will run into the fail case to free the q->fq. Then the __blk_drain_queue() uses the same memory after the free of the q->fq, it will lead to the unpredictable event. The patch is to set q->fq as NULL in the fail case of blk_init_allocated_queue(). Fixes: commit 7c94e1c157a2 ("block: introduce blk_flush_queue to drive flush machinery") Cc: Reviewed-by: Ming Lei Reviewed-by: Bart Van Assche Signed-off-by: xiao jin Signed-off-by: Jens Axboe [groeck: backport to v4.4.y/v4.9.y (context change)] Signed-off-by: Guenter Roeck Signed-off-by: Alessio Balsini Signed-off-by: Greg Kroah-Hartman --- block/blk-core.c | 1 + 1 file changed, 1 insertion(+) --- a/block/blk-core.c +++ b/block/blk-core.c @@ -881,6 +881,7 @@ blk_init_allocated_queue(struct request_ fail: blk_free_flush_queue(q->fq); + q->fq = NULL; return NULL; } EXPORT_SYMBOL(blk_init_allocated_queue);