Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3588766imm; Sun, 29 Jul 2018 23:11:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgpclcyd51JCaggr5blysHr6AH3AEauY4l7CVzu34o/e1TqvHPxWN2SKIhRFALp70MYNTMfrz X-Received: by 2002:a62:3703:: with SMTP id e3-v6mr16712893pfa.117.1532931101678; Sun, 29 Jul 2018 23:11:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532931101; cv=none; d=google.com; s=arc-20160816; b=CQSZk9Vw4c/jsRqcV6x92FIlQ8ksyIGtNF4/3iRRyXjyA/aEmGSznd0gu3cgyoSbzN QXEVXF4fqryz0C5LxkKc/Yy6mmW+P2GqeyboKhB0Ljd5gPjN7acYqMAK5ITUpOsJoo1N Qv0GubjFpeNljVlaqV1yWI3gbCHZxiBJMajR8ndKBNgBKrjZqB6dT7UojDXVrjfBVlnX fFn2UcvnA5UiZtaGPecxjB6sCsJXaYked97mKFV00lPQz9yh9appwULJ6KwRcJo4y0PG rqaHW5ZzneVMtBmTCdPX29Jkvrad2kNt9TVydxAErBntKr2tZUibPi5KpN6AeLCCT7nV 4S6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=NAoTe7Qmm1+drMy1NWUrZVbxDhYghB1PFDSMwBuHygQ=; b=bYxJTiJ7ZgM24RM3ESRIfMhQbNnbzA73/vepJGa77ZACKw7z7p2cMH4KIi883IwNsa D48JwdcmbzlmPCCmqAVacOpGivoNTlJOinYKVCqamktxDn48z7CUAqWyWpYg9IOibr3X qGJDG43nVB3JpxX0herDIPdy4v+A1idIJDUTQDDBMKt8YkArBQBQ2Uo0tsglFU/yH14/ HF1QCDVIxM6XMVcMGQHNpJ0OjyOOGwyfIirkfw4527uBDRJXbR73PLx3UuXSMYNTf64K o3LspV6eQY+eubtMaW5PVhsy/k5R3UEXFQrT61/L44HO5acxQtmVAtgObXlK0Zv8XoGx Vr2w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u134-v6si11434676pfc.244.2018.07.29.23.11.27; Sun, 29 Jul 2018 23:11:41 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726596AbeG3HnL (ORCPT + 99 others); Mon, 30 Jul 2018 03:43:11 -0400 Received: from mga11.intel.com ([192.55.52.93]:43563 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726087AbeG3HnL (ORCPT ); Mon, 30 Jul 2018 03:43:11 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2018 23:09:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,421,1526367600"; d="scan'208";a="77080095" Received: from unknown (HELO xiaojin.sh.intel.com) ([10.239.154.226]) by orsmga001.jf.intel.com with ESMTP; 29 Jul 2018 23:09:46 -0700 From: xiao jin To: axboe@kernel.dk, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tom.leiming@gmail.com, bart.vanassche@wdc.com, stable@vger.kernel.org, yanmin.zhang@intel.com, jin.xiao@intel.com, Ming Lei Subject: [PATCH] block: blk_init_allocated_queue() set q->fq as NULL in the fail case Date: Mon, 30 Jul 2018 14:11:12 +0800 Message-Id: <1532931072-5190-1-git-send-email-jin.xiao@intel.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") Signed-off-by: xiao jin Cc: Ming Lei Cc: Bart Van Assche Cc: --- 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