Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4617530pxj; Wed, 12 May 2021 09:20:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywa3tIEsXt9DzEzbrIkRYhuWvN95EPWquEuE5WlmTvnqbYYfcMAlF/EQsGSINSphZ7nj0J X-Received: by 2002:a05:6512:3e14:: with SMTP id i20mr24687177lfv.142.1620836406189; Wed, 12 May 2021 09:20:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836406; cv=none; d=google.com; s=arc-20160816; b=0P3vILhE9LqULFrOjFoCep6UeQTGM8MBp3qbVcyMui8IzfKxFK1DC+UD7hrAwH1Jrw hl3rusurcG6GG0rhRAMRC6Xti4B3RwQJ25D+q6wzZpfLMYxtjcjj83jBJbA79+nL8R83 IKpw9RKH0d2GEsrgO9wQ+JuBZIlQQ0iGKHWV9T5+ek7iv9qca6Ti8dJkDXT9UxS/MBo9 6+ffmrqpkMH8G3uxAQi/ihksrkpYGD+s0tmzJl9LwmcUM/7O0o/5aumrI5O/zWj2q+Jd IoZQxZfhmnLHZOdQyQwlYM495Yq+uqEfoe6D0NQM0pZfB4oBOsiTRUg9z8lw5j2dOr34 jd1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6Gxh9WuWjCDfziDrm7OEFNCcoIFtymaxXTacSe7ThhY=; b=fO3fRQQyrXyeTBMcsaEfHup4A31nrJsx00g3M0RspBXzd9wLCEuSE1QwCG0GFa6hKY 9Eo48e25/UBm4X28RiEhiVLw64nxwNCvtaSawwYbiIp+mDXlRYAFfFPqBj3nBFUFFE1y eKzxZJl52AHnUESvO9UoZ3/WVT2qUcBpffhObEj+PNdOB1C0ghlEwWaAs3fKvwOuBJhf Sm21pmWjJt7YLjZvBpnd7KpbFwOQe2bLJI6SBVZ2BFbG7BCbD7TzJpFh1JroHXSbOOpD TPdwefg9lvQCVoxcfpuoV+YDstRsCPujfF22rqbLly95SVtF7jidNM2i2v0pY7sp4t5N y6og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J6JJkjQl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g8si483511lfh.85.2021.05.12.09.19.35; Wed, 12 May 2021 09:20:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J6JJkjQl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239764AbhELQPz (ORCPT + 99 others); Wed, 12 May 2021 12:15:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:50220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234025AbhELPcB (ORCPT ); Wed, 12 May 2021 11:32:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 06466611BF; Wed, 12 May 2021 15:16:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832598; bh=vFX9eZvi+lb0MeCVc1y8kW+YWK9lE5PF9Yxev8r9MK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J6JJkjQlKUdmDrm7I5EzL3aN3oe0rcKSB43sRr3i4jB0TNWYdwSzS3+M/uwEdPaLp EOkq/9S84ft7QUlJIhH2Sp+mYE6Ta97UbsjyRD896/PGZ1cOeeA9SJQQ5plB4a1GNo xqsu/HwptGHiJoSOZoWfKEV9LdfJJeEqvu44JCzM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lv Yunlong , Jens Axboe , Sasha Levin Subject: [PATCH 5.10 346/530] drivers/block/null_blk/main: Fix a double free in null_init. Date: Wed, 12 May 2021 16:47:36 +0200 Message-Id: <20210512144831.161671623@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lv Yunlong [ Upstream commit 72ce11ddfa4e9e1879103581a60b7e34547eaa0a ] In null_init, null_add_dev(dev) is called. In null_add_dev, it calls null_free_zoned_dev(dev) to free dev->zones via kvfree(dev->zones) in out_cleanup_zone branch and returns err. Then null_init accept the err code and then calls null_free_dev(dev). But in null_free_dev(dev), dev->zones is freed again by null_free_zoned_dev(). My patch set dev->zones to NULL in null_free_zoned_dev() after kvfree(dev->zones) is called, to avoid the double free. Fixes: 2984c8684f962 ("nullb: factor disk parameters") Signed-off-by: Lv Yunlong Link: https://lore.kernel.org/r/20210426143229.7374-1-lyl2019@mail.ustc.edu.cn Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/null_blk_zoned.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c index 172f720b8d63..f5df82c26c16 100644 --- a/drivers/block/null_blk_zoned.c +++ b/drivers/block/null_blk_zoned.c @@ -149,6 +149,7 @@ void null_free_zoned_dev(struct nullb_device *dev) { bitmap_free(dev->zone_locks); kvfree(dev->zones); + dev->zones = NULL; } static inline void null_lock_zone(struct nullb_device *dev, unsigned int zno) -- 2.30.2