Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp345088pxj; Thu, 20 May 2021 10:36:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHvvIf19cZWEkvmMhdfqjgGN2+3OOpUZez38TI4EuQei2UQacYHJRzTR758W8dwUb/Jwrh X-Received: by 2002:a05:6402:2298:: with SMTP id cw24mr6231831edb.156.1621532199857; Thu, 20 May 2021 10:36:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621532199; cv=none; d=google.com; s=arc-20160816; b=Jm6OFnrEfotrf1Sfhsiu1ZOA+kqB6Rgq2GJwwBXbY7nyo4TRRN9+q4Cw7wHlF+5kVq le8qRGk8obwwQMfFaM24g8EXBKVLnfkTmsZ96LQKzaOuiHGnPb/f2xFPMVWj7uNfwn7w wp/05xLJGtjmwiotGAg61uGPOrmPOcr1JpfUjGZqW49ZzB9VR/lY3W+ob1uwqeakRT1a XBfRHGrFoSZUHXTh4OBxKHAQNi8WtNnFwJ2I+TNnvtwumrhX+ZKUFcCf/p/zXI/VN1h7 KWQ7zRlpfiMc9oogmrEDjjJodCoVWJ5liXjyS0PW47cNcw6+4fhFKWYmU7ZBVrxRr+3W DFdg== 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=QYvpv0rVoyyHdMRZ7ozGAn8/2pvrzVOJozJeCpXT1dY=; b=sJljFxkovugO3ArYSrVe4ZPwkf2+ypaxPeVfVaKdfI3894k0VPSspz1r9by/uyXvdN 7sN3uBv7i7iSZ4NfISrchlMpmstwhT7rjaWqqq543gIAWBxm/KOpFI6Hjfr9gbAE1OoQ /37u6y1QFY29xenHmjg4ZjI75QmD4VN8mOs9261f/94TEKwfqNSyfcw+/vtFYQj9w9dY fRsB9QB1tto+binVvnxpl0jGCw2IisiVSRxTejoNLWfvEXPFKs4VHYaMYEPK747P9LXI 3VNcVVggeDb0dwQTv/SZ5kYL3uWWwKDiBLf7Q02tRVKToXJuN4+F8imt0lvnwB/zuXLC zRQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="a/pIYXxX"; 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 q19si1120726edv.397.2021.05.20.10.36.16; Thu, 20 May 2021 10:36:39 -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="a/pIYXxX"; 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 S234910AbhETKDj (ORCPT + 99 others); Thu, 20 May 2021 06:03:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:59520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232754AbhETJ6G (ORCPT ); Thu, 20 May 2021 05:58:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A342C6141D; Thu, 20 May 2021 09:38:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503498; bh=mn6rk5PFEi1IJN/e1MtilOrShk4Ts2LWoEIa5mbZdFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a/pIYXxX3ixRgbQCDeXw/Oyr9Zwnybf4OeB4CxL2aiNgkecSM4rLit05DEnGxuHvY Uu1jk6jvnzrSxPhvJIL1GnvqvnTZwlagJusLUNM4Z/I7rXTAKr1d7sqnMnCPIyRGaX JspX7R/3xeVKShrsU3YHQ5HsEevI2VDeQJXthvrI= 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 4.19 247/425] drivers/block/null_blk/main: Fix a double free in null_init. Date: Thu, 20 May 2021 11:20:16 +0200 Message-Id: <20210520092139.536803959@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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 079ed33fd806..ba018f1da512 100644 --- a/drivers/block/null_blk_zoned.c +++ b/drivers/block/null_blk_zoned.c @@ -56,6 +56,7 @@ int null_zone_init(struct nullb_device *dev) void null_zone_exit(struct nullb_device *dev) { kvfree(dev->zones); + dev->zones = NULL; } static void null_zone_fill_bio(struct nullb_device *dev, struct bio *bio, -- 2.30.2