Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp395469ybl; Fri, 9 Aug 2019 07:37:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxztTbv8+1TPjSMv0lypo0Ua6nt96SoPR/86MaXEdCCYJcuqMAUa9JnYRY8q9x4mvOya49F X-Received: by 2002:a17:90a:be15:: with SMTP id a21mr2694817pjs.74.1565361425265; Fri, 09 Aug 2019 07:37:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565361425; cv=none; d=google.com; s=arc-20160816; b=klo9Z3jPZ1Vyr1idNUmD0beNEsbhSsbYZm5DjzG4CehGpFXeQh5dYkr5PLRYdrpPsq +0UYcPe5+5OWAHcJR/XoaNwMEhWfeqPGcX+9wqWtM8sqQg6smChJGZR9z4OY6Qmj8XuO g2BJ33OV98bItg6pP4DlzGdL9ewlxOl+4MDdubn3NBipPyEmwR6U5qxAM5J7TrufCFoh j3waeBjsPF2ZW5u2LgGVdVtWBvRAI+sW2bpVBw+NmxkwFDzNKZsx5TM9MtV9klrZDbzU mn2RtsJkEWIzkNYS002H9RwAfCPHu3YU6E5oRSHdtFfe+lPRpdhA57wO6RtfbKZVOAxK mmpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ym1+MKHgckiT8xMyTqzXLp6Xn9knw6Jb4khFtolPJ7I=; b=WleHg12OGUpcVTZZhuEsVwUCHBQfzxa8r/sum42gMj/2gx/4F9bkHRlxGEMHJEbvba LYHHs5V1IwWeLY330DElLV7058exPztzViV5WGsyzn/Rv/kthN9j2l7aOL4PzX7xig1x WJSfQs1b9AzNAPADfvfYQxuKMrtepKfLOr/uNeZ7vtb3XGWv/Ix3tjrP2fySZk31unq0 RmsTZksjAvfmDowYz2abKAvIOiuBMHJyYIF+p/hLbPCezOilo3Li3KDAVDZ0YXKrVm4t 2rUEMoChK7u1UgmQKJiK338f9pE0D5kkgA7F4C1uBdAbpfOD9MVwLnvyI4IZWJwXzuai 2jmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uJF+Svxa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f15si3884178pfn.41.2019.08.09.07.36.49; Fri, 09 Aug 2019 07:37:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uJF+Svxa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406787AbfHINrd (ORCPT + 99 others); Fri, 9 Aug 2019 09:47:33 -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);