Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2488004pxj; Mon, 10 May 2021 04:18:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5tz+9xnR/PGszOVn7OXEvp7jVqxLYtaH2aOsxOpWPUNd7SSi4ma7DPmMB4NDBXEaBIkEt X-Received: by 2002:a02:cd11:: with SMTP id g17mr13567783jaq.111.1620645498974; Mon, 10 May 2021 04:18:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645498; cv=none; d=google.com; s=arc-20160816; b=dxhznzFK9w5+8fQkidSZSPEWHgPzSnAqYMw9M7gN6ZUW6xm8na7k3FReCRZY/TY/ui isPZqiX6S2wCtkVIaDQP7eJ1MpY+6XJLcFy/cFbcRpxacnalzux8yThA7oLOulz8+Rw4 PshNIyQB0WiWATnlQ1QaO0WD8Z8iCaK9sTP44RU+QQO94QvEbyV27TWG2vJMGLGx3QIk XYqmakgK8Q7zAB+roAbp61nB+xd1lA05FZGSdgWXY/RqT3YltK7rJiKO8iryGromD54Y 0eYnH8NK8M8+j03PpAUdC/VKL0XwhW/M7egwge8G2jZA2OWF1F+Zi6WIFTPIjBCvNUsG ivPg== 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=EvDIkZ1oIy708yWktzmx6PS+CmUmlbsPbVUX2tdWCV0=; b=f7/KKgrUqyp83S/AzbkdUMl4me7fpN3oZwI036k2OD0QEU40P15K81s5uQ2R/f04St KhWqDpPIVZu9Xf6BSfwb8Sa0oYGSByGVncpVDso2AOtPTs6E3Gcb67MQkhT8MwZuByRV VFwa4cMlmSaVP9sPiHsQqDWPtbPKZJu+ovMFbx1jVneo2L7TtXOXeYECfLG/RNeTjUiG y39wW6nFDTJTkZSd+cYLG5W6VDkwTcgJnImjkdnwybQN49qJNA532PNRYDTlhN+b1M9U Bg23uu6viFh4uZCyXQay8orjGDgdMRSrZwKd15YutrZATvjfLOBsa6WTnJjNLieAL4hV BaqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WGY0dfyR; 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 z8si15877575ilh.46.2021.05.10.04.18.06; Mon, 10 May 2021 04:18:18 -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=WGY0dfyR; 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 S233804AbhEJLMS (ORCPT + 99 others); Mon, 10 May 2021 07:12:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:41711 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233538AbhEJKuM (ORCPT ); Mon, 10 May 2021 06:50:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1488B619F1; Mon, 10 May 2021 10:39:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643165; bh=K7MP6scl/OWuLlk6iKFJzWTsh7jEaPUuIVAJPFVdBtQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WGY0dfyR49fq6YdAWXhccUYgggPHpHYUCtvJTqS+UL3kGvvFPgvJcehkD5aSLKTxt xvrybnFvTRlJGaOt/g4OTT+IraSWUvWpBDIXQ64Q0Pc64frYiw90WaDKzAFJo8IHHL 017jD8xy4uX8cOUDJ0QvJ85JUTMAeaGIXAtNZWTY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gioh Kim , Jack Wang , Jens Axboe , Sasha Levin Subject: [PATCH 5.10 205/299] block/rnbd-clt: Fix missing a memory free when unloading the module Date: Mon, 10 May 2021 12:20:02 +0200 Message-Id: <20210510102011.717028766@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@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: Gioh Kim [ Upstream commit 12b06533104e802df73c1fbe159437c19933d6c0 ] When unloading the rnbd-clt module, it does not free a memory including the filename of the symbolic link to /sys/block/rnbdX. It is found by kmemleak as below. unreferenced object 0xffff9f1a83d3c740 (size 16): comm "bash", pid 736, jiffies 4295179665 (age 9841.310s) hex dump (first 16 bytes): 21 64 65 76 21 6e 75 6c 6c 62 30 40 62 6c 61 00 !dev!nullb0@bla. backtrace: [<0000000039f0c55e>] 0xffffffffc0456c24 [<000000001aab9513>] kernfs_fop_write+0xcf/0x1c0 [<00000000db5aa4b3>] vfs_write+0xdb/0x1d0 [<000000007a2e2207>] ksys_write+0x65/0xe0 [<00000000055e280a>] do_syscall_64+0x50/0x1b0 [<00000000c2b51831>] entry_SYSCALL_64_after_hwframe+0x49/0xbe Signed-off-by: Gioh Kim Signed-off-by: Jack Wang Link: https://lore.kernel.org/r/20210419073722.15351-13-gi-oh.kim@ionos.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/rnbd/rnbd-clt-sysfs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c index d9dd138ca9c6..5613cd45866b 100644 --- a/drivers/block/rnbd/rnbd-clt-sysfs.c +++ b/drivers/block/rnbd/rnbd-clt-sysfs.c @@ -433,10 +433,14 @@ 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 (dev->blk_symlink_name && try_module_get(THIS_MODULE)) { - sysfs_remove_link(rnbd_devs_kobj, dev->blk_symlink_name); + if (dev->blk_symlink_name) { + if (try_module_get(THIS_MODULE)) { + sysfs_remove_link(rnbd_devs_kobj, dev->blk_symlink_name); + module_put(THIS_MODULE); + } + /* It should be freed always. */ kfree(dev->blk_symlink_name); - module_put(THIS_MODULE); + dev->blk_symlink_name = NULL; } } -- 2.30.2