Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795050826; b=Eq+82dtOMO37Gd3v3RJVbOuKsT8KX5+uf3gl35rRhHEIKvAw4NzXZZB+60ZdbKX8ubXl LUx9NQzVSxiRXbZm0Q7F4GpRPfqhO1Whg0auDK6KD3ignLJZ+7tMW62QriKZMURCEgVKw LD+48TskH0lMtg7QIrvMXkS78rChYITwLwDbQ5sEqQmT0ImuOZ8hciRyoQ+PrEJtQxDOh Cvuh3mocGnWOpzirW5O3dF9iEEOy6w0HaSH2sVM3xb6uM6J+4yEks7uqTIdZxnzZphPx8 gEdWlpHn4RS1TY12vMydt+GPVfjva5UueF8Z7b5fLOu6vTq3a5VCUVxbvtkp/hM51qw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795050826; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=yt3nQ4eYlDdrzxSnvKNFq2NZagzeD9411Y9yWMbpL0c=; b=gOMaEdUtM1vnBXkOzoxO4a+1UE31QmUtOEzs+nrzH5g7lCUiAodT+KNgEkPObk7gx5MP p2UQQx86TkX0d3/lNhJLtf9x4Y0eHR4EQrvlL7F13kYrk4WqH+PzdGVmb8Py6cNyF1a1z 215jTer9ddj4VoZxCtRSN9seaoqNon9Ygi+MgD0xedxJiwgBfGQeclpmN9L+di2k76eUE PbaAKlc7OyvlZPxeGm/7ruZjySmZS/RC5fJLCO8y2dOj/oc672tLMMzE4VHD8V1D+XtPf 3vc7m4ETM6hjxl/mVNtjS7BvS9DAds/hDOweryIzFZ52zJBGvyegI5CJifmwUaHIlKg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=tSljG1Gu; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7769E606A32A; Thu, 19 Nov 2026 01:13:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=tSljG1Gu Received: by smtp.kernel.org (Postfix) with ESMTPSA id 864721F000C4; Thu, 19 Nov 2026 01:13:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795050826; bh=yt3nQ4eYlDdrzxSnvKNFq2NZagzeD9411Y9yWMbpL0c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tSljG1GuhQGl9Rzk/8MgX9lZURp/BhvsxITbEBZibI+N6Tvc1HJe1fFQ472BuaC69 xwzSY2CiKGixfaA1d1k2XR/qwbhuT3SBpgqiSXMQBJbe75PtRNsXTYCuqDoJQhKgzo HW+Kkv8ByqS8/Llvt1nk1IbKC9u8l6mewfmY0sws= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Md. Haris Iqbal" , Jack Wang , Josef Bacik , Jens Axboe , Sasha Levin Subject: [PATCH 6.1 2806/2857] block/rnbd-srv: dont free the device on a sysfs error Date: Wed, 18 Nov 2026 16:04:00 +0100 Message-ID: <20261118150342.631487508@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150201.293410965@linuxfoundation.org> References: <20261118150201.293410965@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik [ Upstream commit d9667ade40f986c565769a900ced6ee95edd33c6 ] rnbd_srv_create_dev_sysfs() drops the only kobject reference on its error paths, and the release function frees the rnbd_srv_dev. process_msg_open() keeps using it and ends in destroy_device() with a list_del() and a second kfree(). This doesn't need memory pressure: a client opening a device while its last mapping goes away gets -EEXIST from kobject_add() against the old directory. Only undo kobject_add() on failure and leave the reference to destroy_device(). Initialise the kobject once, the next open retries. Fixes: 8cee532f469b ("block/rnbd: server: sysfs interface functions") Fixes: d3a95ccaaf4d ("block/rnbd: call kobject_put in the failure path") Cc: "Md. Haris Iqbal" Cc: Jack Wang Signed-off-by: Josef Bacik Link: https://patch.msgid.link/20261028164415.1262013-17-axboe@kernel.dk Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/rnbd/rnbd-srv-sysfs.c | 16 ++++++++++------ drivers/block/rnbd/rnbd-srv.c | 3 +++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/block/rnbd/rnbd-srv-sysfs.c b/drivers/block/rnbd/rnbd-srv-sysfs.c index 297a6924ff4e2..d9d6a5fd7cf58 100644 --- a/drivers/block/rnbd/rnbd-srv-sysfs.c +++ b/drivers/block/rnbd/rnbd-srv-sysfs.c @@ -43,12 +43,17 @@ int rnbd_srv_create_dev_sysfs(struct rnbd_srv_dev *dev, struct kobject *bdev_kobj; int ret; - ret = kobject_init_and_add(&dev->dev_kobj, &dev_ktype, - rnbd_devs_kobj, "%pg", bdev); - if (ret) { - kobject_put(&dev->dev_kobj); + /* + * The release function frees the device, which the caller goes on + * using and which others may share: never drop the reference of the + * kobject here. That is for destroy_device(). + */ + if (!dev->dev_kobj.state_initialized) + kobject_init(&dev->dev_kobj, &dev_ktype); + + ret = kobject_add(&dev->dev_kobj, rnbd_devs_kobj, "%pg", bdev); + if (ret) return ret; - } dev->dev_sessions_kobj = kobject_create_and_add("sessions", &dev->dev_kobj); @@ -68,7 +73,6 @@ int rnbd_srv_create_dev_sysfs(struct rnbd_srv_dev *dev, kobject_put(dev->dev_sessions_kobj); free_dev_kobj: kobject_del(&dev->dev_kobj); - kobject_put(&dev->dev_kobj); return ret; } diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c index 549b6581b7fea..c47ad07972699 100644 --- a/drivers/block/rnbd/rnbd-srv.c +++ b/drivers/block/rnbd/rnbd-srv.c @@ -192,6 +192,9 @@ static void destroy_device(struct kref *kref) * Destroy kobj only if it was really created. */ rnbd_srv_destroy_dev_sysfs(dev); + else if (dev->dev_kobj.state_initialized) + /* The files could not be created. Frees the name, too. */ + kobject_put(&dev->dev_kobj); else kfree(dev); } -- 2.53.0