Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3502686imm; Sun, 29 Jul 2018 20:59:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeLUbPuplDzpy1icCr5IBKz69WOycofZCP02fmLEt9jCnBazTikNAgYwsmt0c207XdVhaGB X-Received: by 2002:a17:902:d906:: with SMTP id c6-v6mr620470plz.65.1532923177338; Sun, 29 Jul 2018 20:59:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532923177; cv=none; d=google.com; s=arc-20160816; b=ZlwFWKMnHM6M0sz4DZI7tiz/M0TyebWFwW8GNqrYT1mmkS0oDFqDE2Iu8x/9qPgcj+ +w196udrVVTMZp7gFqo2Zu//Y2OCvGPc0zeFS0y3k2zj1f9F8hBXiSGERNrj36HXgM1O iHWryobvzaQa/CEOuQ3zoEd1kyalQ7M+EOtECj0uZOupZK1RWITzIql6YZLpBupuk84u 6fBS4l+NeMuDc9a5BBMiMfY7tzODIWt8H7NXY9qiGOb/SK0lhHvrrNF4SF1Up189HfCe buO5A/lVfH/Uu+Wg8fU3KowF8aSAm09kQKwPmAwAAfojB800ki/tyMXeI/EBNBBowXTx etBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=3RGDLhHL6FO3NWMuetUeLEFUXim5SAj3qrzWtqMdzu8=; b=j2vv2ZF4n7tY0eFa3EhN42EV+KwtT3Q5rYB5evtxIZVLZ/g6Sw8udljK6Ub1DJIE5H wx6QHpP+4mLIfTyyU/Ek6gWiO6rsIH2ULVYB00ssq6/ihZbIbBwX0qI6eCUZg68vEPsT 7VrE/SZ4sOtsffFCrbSHJROG6ciDLGizl/OHSkpkzYx2dzbwGuqqsJdnRYkfEfMhEv6I 17b88j6ATPAaCZSHPWqfyiXKbvQyQVAkPFjRIWweK7u67z3hzHtw37Wbx03cmtgV1Mca QXe8kCQJeSeIVq1xPFimSXT+OnwRU1Xg7W7YqfrGp5yoKuuCyZLcKvmniDjdnKcbXkyV 9T/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i1pPlQD3; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g16-v6si10344871pgi.373.2018.07.29.20.59.22; Sun, 29 Jul 2018 20:59:37 -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=@gmail.com header.s=20161025 header.b=i1pPlQD3; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726480AbeG3Fau (ORCPT + 99 others); Mon, 30 Jul 2018 01:30:50 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:56303 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725911AbeG3Fau (ORCPT ); Mon, 30 Jul 2018 01:30:50 -0400 Received: by mail-wm0-f65.google.com with SMTP id f21-v6so11485683wmc.5; Sun, 29 Jul 2018 20:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=3RGDLhHL6FO3NWMuetUeLEFUXim5SAj3qrzWtqMdzu8=; b=i1pPlQD3LAbaEn9IW48ACde0HyxkHnMg/ES8RatxN0YBpWiWrzdbigDh0YLDFSdXfk 53dVXgVcg+OeVXVpftxCcaA/RG3B3aTcIblFVWJkyiCIqwRC/0Hq405pnhSOzYh227N4 vbYl2AGyKpO9peqjW6vg9pYcuEWzD4TZx0a3uFILHokk85sGe/BgZnCCgrCbm4lcOk/5 EKusKqGh96OCXMuBDmsnPb2Iqwaubn4gZeZhWbKwFNUDUL1vL+smmnDZzu/s6avd00q4 LA0tcHIvnXP/57qot6m5HN0Oers3WLwl/igXkVpm2CTXfwGzucCTu1b4vNreUGbHyLuZ bjNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=3RGDLhHL6FO3NWMuetUeLEFUXim5SAj3qrzWtqMdzu8=; b=Orz/Pgct9J/uwIPtBd1hdFlk+zzvf8n9NViUAyRuTjI0geFKi13qs48jBcz/Hq4oBA 4f4jpYHHmOhRzHBEe1g4HMEef0CKVGlc3S5ASO59cyHnxffp9RWcwfvwQGap9zq+cEKM zpWYiEJVu5rqpOvva1FUBiX6tFIlak0UAqQfOfcyp/L6RjTjIFcOPRPFDhnmjiTkgnir YCMeKWyKBUrnxrXi6MtZ4c73rkPVOpfSorAUxCeucWBswL5ut6JAZNyMsROJsfyXpX/3 lIs/iZHX9Npz3RTCYRJWr6y0IFOcTsiTB1TvtvjdqS/myqKhcPXkI8S1NlVBzqHu5Mgv Sn+A== X-Gm-Message-State: AOUpUlHA+2wdNcBQ8Rt0z6FZU9/CG+58KjUom9jxwZW1kx3aur1+D5vJ frJL59vWGTi98xiZEk8crXgUZBZnEzFWAUA3VQw= X-Received: by 2002:a1c:a103:: with SMTP id k3-v6mr13807250wme.161.1532923070497; Sun, 29 Jul 2018 20:57:50 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:9c8:0:0:0:0:0 with HTTP; Sun, 29 Jul 2018 20:57:49 -0700 (PDT) In-Reply-To: <1532916197-14950-1-git-send-email-jin.xiao@intel.com> References: <1532916197-14950-1-git-send-email-jin.xiao@intel.com> From: Ming Lei Date: Mon, 30 Jul 2018 11:57:49 +0800 Message-ID: Subject: Re: [PATCH] blk_init_allocated_queue() set q->fq as NULL in the fail case To: xiao jin Cc: Jens Axboe , linux-block , Linux Kernel Mailing List , "Zhang, Yanmin" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 30, 2018 at 10:03 AM, xiao jin wrote: > 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(). > > Signed-off-by: xiao jin > --- > block/blk-core.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/block/blk-core.c b/block/blk-core.c > index b888175..52635e2 100644 > --- a/block/blk-core.c > +++ b/block/blk-core.c > @@ -1072,6 +1072,7 @@ int blk_init_allocated_queue(struct request_queue *q) > q->exit_rq_fn(q, q->fq->flush_rq); > out_free_flush_queue: > blk_free_flush_queue(q->fq); > + q->fq = NULL; > return -ENOMEM; > } > EXPORT_SYMBOL(blk_init_allocated_queue); > -- > 1.7.9.5 > Reviewed-by: Ming Lei Thanks, Ming Lei