Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2091304ybl; Sun, 18 Aug 2019 18:17:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWG0JQ1SEQKelhtSNAqd7ujL9n3rqfzSFoORaWtRO6WHgj4A7d03rWKRR4+0G0r/LvxidE X-Received: by 2002:a17:90a:bf01:: with SMTP id c1mr17540343pjs.30.1566177456160; Sun, 18 Aug 2019 18:17:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566177456; cv=none; d=google.com; s=arc-20160816; b=fxQEp2ZsPifUvleUmOvBcT1IkVvP73YrDaSF5Tjr0aQq/i39NIXxMOFMXy+9qsUtz5 hWYI8W+f0cMfTKEvFBzvbA6eUkpC8pXuzSmvwD/+SiwIt0lgdkeGpFIrFB/ixR5ZMLgt s8lo02/GPmsmZG3pA9poUvfACaJtb1Drl2Rcy4LostVFgU0MwlJuoQnKytsRxl9NQU3R PDzQ8ZRjOz67dWzqRoZbi4tsyuoHm8AY9WqhtVP0MmBswo3xPacTWAOjwhM9q2OfApOQ VqpuMWN9rwpm/LjHUuz9cayh8SYmBf2ZI4wIth6tRNqS2t2in+iFwZE8aGXk+WbENjtt zGkA== 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 :dkim-signature; bh=/7j5TCVh3LyFbojbI4zNhdc3Dow0JvOr+GRNkDNVxl8=; b=Iuwv0RaV7qictCN3U1VPYiXyGBm/UIUnjejGeRlao1P33GdPtecrkgAXTvCqSMaCWm rDz3Vd70u4YnEuBerYYl0SfLVP8U78aojww5blhx22CBAdJBUsnbZjSqv1YJCu+JAc+9 e+AAocQI4SH3Au6903VLhOeW+Rf/EAUzyNoBsZ34Tz9hjKYPTZH7WxFoNSGPU8GGFKpZ Gnsg8lkK5HBg0ZKjsnPjUJBal09lUrS0vJMUEfKRjz3TAeEyAn56dxIUZEQhBo6Mii59 7kJUjxrpeIkj15cIEK6+BYW2s67gCCFxUkd0pTleK6w2hsJVcFF6UmUUONwyCEH6EdUb JM3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=kQznfR5Y; 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=NONE dis=NONE) header.from=163.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r5si7764688pjq.96.2019.08.18.18.17.21; Sun, 18 Aug 2019 18:17:36 -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=@163.com header.s=s110527 header.b=kQznfR5Y; 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=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726347AbfHSBPU (ORCPT + 99 others); Sun, 18 Aug 2019 21:15:20 -0400 Received: from mail-m975.mail.163.com ([123.126.97.5]:43174 "EHLO mail-m975.mail.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfHSBPT (ORCPT ); Sun, 18 Aug 2019 21:15:19 -0400 X-Greylist: delayed 908 seconds by postgrey-1.27 at vger.kernel.org; Sun, 18 Aug 2019 21:15:18 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=/7j5TCVh3LyFbojbI4 zNhdc3Dow0JvOr+GRNkDNVxl8=; b=kQznfR5YSJzolkAfLVeQQ1cW4idq5qSjkO fq9sNlZqNk2dTpYeS8RoTSXNMyAvTY7enb0Mjt0XZOkrKU0gH3XKCB+G9inbziIQ XNJSmMPaBKs/UbpSzmBL0Ryx7L9XpgZzgtqgVK3noBpiPws0xd9rgN1MfIMEVGbM xfxzAeZ+8= Received: from localhost.localdomain (unknown [202.112.113.212]) by smtp5 (Coremail) with SMTP id HdxpCgB3jbRn9FldfQ_WAg--.240S3; Mon, 19 Aug 2019 09:00:07 +0800 (CST) From: Pan Bian To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian , stable@vger.kernel.org Subject: [PATCH V2] block/bio-integrity: fix mismatched alloc free Date: Mon, 19 Aug 2019 08:59:13 +0800 Message-Id: <1566176353-20157-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: HdxpCgB3jbRn9FldfQ_WAg--.240S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrKr1UuFyUuw15CF1kZFyUGFg_yoWDZFc_Ka yv9r93ArnYvF4xCw12yFy7Ar4vvr4fXF1rXFyaqrWaqFyxAry3A3s7Xr95XFs7Wr97urnx uryvqwnFqw17KjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUb8wIPUUUUU== X-Originating-IP: [202.112.113.212] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBzwkWclaD4ImCBQABsY Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function kmalloc rather than mempool_alloc is called to allocate memory when the memory pool is unavailable. However, mempool_alloc is used to release the memory chunck in both cases when error occurs. This patch fixes the bug. Fixes: 9f060e2231c ("block: Convert integrity to bvec_alloc_bs()") Signed-off-by: Pan Bian Cc: stable@vger.kernel.org --- V2: add Fixes and CC tags --- block/bio-integrity.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index fb95dbb..011dfc8 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -75,7 +75,10 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio, return bip; err: - mempool_free(bip, &bs->bio_integrity_pool); + if (!bs || !mempool_initialized(&bs->bio_integrity_pool)) + kfree(bip); + else + mempool_free(bip, &bs->bio_integrity_pool); return ERR_PTR(-ENOMEM); } EXPORT_SYMBOL(bio_integrity_alloc); -- 2.7.4