Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9403840pxu; Mon, 28 Dec 2020 15:21:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwtxO0fLF9LQRRF5mX7XuI+fmmJIwHx9qAquEACohvij4rGQ3H94PyGvSgxQvA3YXR/eD1I X-Received: by 2002:aa7:da03:: with SMTP id r3mr43525731eds.155.1609197706280; Mon, 28 Dec 2020 15:21:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609197706; cv=none; d=google.com; s=arc-20160816; b=sNHvJ62NzyTBdpzVpdu5poj5omfKBAanzfAzyJ7YzlD8os1fVzpTiDW0pmxz8uJA1t HAjsbquZbtRR46ov6SXU/vMdX5oBPnEX7eeDtP292uhGjB4sbF1XEX07Ns4zntK3RAGW dJYX8TmdYhHoABtZnw7JynJs4rB89Zv8kb1Ndp2dIGK/Gl9TmqZ8W0u4Iy30kelWhNn4 trIlmv41hvALUF8FS9wWvoOua16vFJEoKhxlAT7B8zWs4G0vGzO1zGini70YrhozXhCo Aey28JD3AALsBrzzEhocH91T9HRnyFcs7lyRDwMY0y3E6cdP1MBvJur4egeTZQ+hS4+c fvzA== 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=f/JkTVd8TibTaP7HAGe+WHESzS11jgE2mGgpr+NYrnw=; b=QL6s1YOMaSJAx4EVL/fbU6eYC5qOcj3KJ4UuQzEzlbkxifSiaTeZ0z1czplZWerXdo G3uibxZw64K6gmb0uS4SVAT1PweASqbI4MiOZ1WVs8iak4NlTW4LdwrMahzYNFQqQX8K 6fcIxSNn8gqkai/YqJqhlAexuyCf8LWWPnoCIfSF6/IZonlBuRybkKzBlHGZiS1wq2JK RGlVdQ1yQKopqPX6Bmv5hSo2zmuSMA5BuqoblTXPyv45G286yPDtRmgcsk4tR3FqRaOi V+KgVSnrCzCF92oTa/OPS4CG9Y5GKnYa1I2ehkBFYGe37TsoQkVvxUDnQ9XxoUxMvhNe 4Esg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PQpXbrL1; 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 w2si18704286edx.591.2020.12.28.15.21.24; Mon, 28 Dec 2020 15:21:46 -0800 (PST) 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=PQpXbrL1; 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 S2438035AbgL1OVn (ORCPT + 99 others); Mon, 28 Dec 2020 09:21:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:56518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502484AbgL1OVT (ORCPT ); Mon, 28 Dec 2020 09:21:19 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id EE33720791; Mon, 28 Dec 2020 14:21:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165263; bh=gB0sMBbjvHsllEBpp7DjNbg4rzoH6g7olzor5aVjVhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PQpXbrL1cbG7K4mSPiS0Y1aQ1uLKePCCakXSvQZ736cZhI2UlwypT+3XYGfhkd4Xx 5gjeZeFFKJMORgjBiC/sqCRhsBOvgzuQArkeWtcZi1K52z1EgXQxkxemO2XsCXwezw /cpSbeWWs0LBboKISXPE5efdou3S1i2Syo+wLhZM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jack Wang , Md Haris Iqbal , Jens Axboe , Sasha Levin Subject: [PATCH 5.10 470/717] block/rnbd-clt: Fix possible memleak Date: Mon, 28 Dec 2020 13:47:48 +0100 Message-Id: <20201228125043.489451327@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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: Jack Wang [ Upstream commit 46067844efdb8275ade705923120fc5391543b53 ] In error case, we do not free the memory for blk_symlink_name. Do it by free the memory in error case, and set to NULL afterwards. Also fix the condition in rnbd_clt_remove_dev_symlink. Fixes: 64e8a6ece1a5 ("block/rnbd-clt: Dynamically alloc buffer for pathname & blk_symlink_name") Signed-off-by: Jack Wang Reviewed-by: Md Haris Iqbal Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/rnbd/rnbd-clt-sysfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c index d854f057056bb..d9dd138ca9c64 100644 --- a/drivers/block/rnbd/rnbd-clt-sysfs.c +++ b/drivers/block/rnbd/rnbd-clt-sysfs.c @@ -433,7 +433,7 @@ void rnbd_clt_remove_dev_symlink(struct rnbd_clt_dev *dev) * i.e. rnbd_clt_unmap_dev_store() leading to a sysfs warning because * of sysfs link already was removed already. */ - if (strlen(dev->blk_symlink_name) && try_module_get(THIS_MODULE)) { + if (dev->blk_symlink_name && try_module_get(THIS_MODULE)) { sysfs_remove_link(rnbd_devs_kobj, dev->blk_symlink_name); kfree(dev->blk_symlink_name); module_put(THIS_MODULE); @@ -516,7 +516,8 @@ static int rnbd_clt_add_dev_symlink(struct rnbd_clt_dev *dev) return 0; out_err: - dev->blk_symlink_name[0] = '\0'; + kfree(dev->blk_symlink_name); + dev->blk_symlink_name = NULL ; return ret; } -- 2.27.0