Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6555940ybh; Thu, 8 Aug 2019 02:02:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNAXRgINJUEMZxoddhci5MhesI9wupQ6uNNXTt0SQTYO/zKCuwJdtUNYGDrVkm4Fku6O2e X-Received: by 2002:aa7:9591:: with SMTP id z17mr14471491pfj.215.1565254924473; Thu, 08 Aug 2019 02:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565254924; cv=none; d=google.com; s=arc-20160816; b=vBCyi5ZUArX/wFRyeDMBk1XxucdmV2x2zHoxmfyxliHRNs8iKfkn/E+w5pxfwr+221 YUS8R9E1dihxYieq0nObGtTqozRLI+8x3S3N52qlFo4xu1tzEz7XILDj7VpchhmpxY5x 2UPz++m1rYMmSTDIAXBssnTp2jzKHsVPYKe3ZnSI75xFTrI8kgzrs0hMmL6SLk/UTk+J hztC4T2SeqCLtFF/b9Q2epQ1xBH1HwtzesC+JdmP0Nvhg/PYJ3/u+cdm3MZ9fypS5gWA KFixnp5A81EjXofXYhOXZxI8+drLN6ZYMlRUnhIin11RkTIHUaVS42hNdIkqPC7n2axa AIWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=RQeNGK7O23t7caYjP/BL6Emh8rCULjuGXxa5tAlaPq4=; b=Oj2wVRAW9irwb1nr+9+BRKzr9ZLk2f9ytaKQQX1X30D0KJy68jgtykDpyjDWnd+3PQ 4vvuUlQQtuBA2I7ov+Xph9P1wp7iiXsbDDwj6I5LmGI1HdJhuSEV3AfiU95XSKMyRGVE bgi1ZrtJYkYhlzIr69/6lxy33R+O7b9mQMR505QnBpaCF9HJJZ0vjuh/h9BVEQBUpy1x cEEz4PPp9SWCCbdWUoFJq7J9vwRnVbmFHx6Qw0IQbXcB5HmyU38BJMYwYWc1NZnNBm6I iS4cjZur6oeJI+KojPyNxX+uXGrpNqTK1AFUXrluFBpUjL+iQgjIE2JQB9ZfVFNcoFe+ eoMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aRMBZdNl; 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 h12si1507221pjt.4.2019.08.08.02.01.47; Thu, 08 Aug 2019 02:02:04 -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=aRMBZdNl; 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 S1731779AbfHHJAx (ORCPT + 99 others); Thu, 8 Aug 2019 05:00:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:56676 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731031AbfHHJAw (ORCPT ); Thu, 8 Aug 2019 05:00:52 -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 D009F2173E; Thu, 8 Aug 2019 09:00:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565254852; bh=LWy4gsiJ5ZweJScVxi16KwqfP/e1w1Xari3HQ0g8eUg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aRMBZdNlC3OarhMdbUvZyH9rpcMZ0NIOzNZNxpAYxT3agvRxGW5ALR8sv+kjtw/KA 2jtJPhNDqF0DG+4RXDgyTcFSQq4/d/XwSTB/vg4wX/PSL1pHBemABxrYgOgQ5G479t Yi7a4rf5hwaF+YtT4Z7gWrqNi4InQOL60F9lzdPg= Date: Thu, 8 Aug 2019 11:00:49 +0200 From: Greg KH To: Alessio Balsini Cc: stable@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, xiao jin , Ming Lei , Bart Van Assche , Jens Axboe Subject: Re: [PATCH 3.18.y 4.4.y 4.9.y] block: blk_init_allocated_queue() set q->fq as NULL in the fail case Message-ID: <20190808090049.GC1265@kroah.com> References: <20190808022819.108337-1-balsini@android.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190808022819.108337-1-balsini@android.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 08, 2019 at 03:28:19AM +0100, Alessio Balsini wrote: > 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 > Signed-off-by: Alessio Balsini > --- > block/blk-core.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/block/blk-core.c b/block/blk-core.c > index 50d77c90070d..7662f97dded6 100644 > --- a/block/blk-core.c > +++ b/block/blk-core.c > @@ -870,6 +870,7 @@ blk_init_allocated_queue(struct request_queue *q, request_fn_proc *rfn, > > fail: > blk_free_flush_queue(q->fq); > + q->fq = NULL; > return NULL; > } > EXPORT_SYMBOL(blk_init_allocated_queue); > -- > 2.22.0.770.g0f2c4a37fd-goog > Guenter sent this backport a day before you did, so I took his version and added your s-o-b to it. thanks, greg k-h