From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1BCC149DE8; Wed, 5 Feb 2025 13:55:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738763731; cv=none; b=oN/Lk3XvzQBWHKLpn3NFDNCHmd+ukY3kuXE2VKpzL2081WSS1saCmIWToEt3t67mraJHLPr8qLnzj9+Fz1XiVV0Kerd9+5ZJBywlpe5uDomatiOfZkQ3bFMhpvnAJlgwL4/qkdv1U2h29NWLgCw0jNhDV2MbA/obhXLhaXYaeNc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738763731; c=relaxed/simple; bh=RzRV+MqLwuwEmu7ykTnW7McPtqrozOToc+BeBVmq15U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L9oyMWN7PpP8QkICmabzdLXC/TAaO2OMOnQ4FJU0JCSLlmCEZABzvzbjmI93piKoBZIieZIsTRSF1udgRVyG9Cj52q7HEhAMIfLifxpq+i2leVwVYkCFlzflkY2OAuoaRrFa39Jxl3qoGfQjia9bygqt11uGu2lgB72xkEHW03M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=a9b2IZgF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="a9b2IZgF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 668EFC4CED1; Wed, 5 Feb 2025 13:55:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1738763730; bh=RzRV+MqLwuwEmu7ykTnW7McPtqrozOToc+BeBVmq15U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a9b2IZgFh6e8nb5QjEELuTCppQ+qPa92PvMfd/8DjCLb293MWH2Lzylmhvmg5W6Lu RL0gfzsC+dRmjKM44yc2yoSPyie0FelO0VTruS5AlnBIqOJdzpCvqQ3pZ7HapW1l7m 1ZPJ+dUaEzWU4KN7UtL7h5PcyabjvcDELK6Ya12o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+6b0df248918b92c33e6a@syzkaller.appspotmail.com, Yu Kuai , Christoph Hellwig , Jens Axboe , Sasha Levin Subject: [PATCH 6.13 013/623] nbd: dont allow reconnect after disconnect Date: Wed, 5 Feb 2025 14:35:55 +0100 Message-ID: <20250205134456.737834080@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250205134456.221272033@linuxfoundation.org> References: <20250205134456.221272033@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.13-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yu Kuai [ Upstream commit 844b8cdc681612ff24df62cdefddeab5772fadf1 ] Following process can cause nbd_config UAF: 1) grab nbd_config temporarily; 2) nbd_genl_disconnect() flush all recv_work() and release the initial reference: nbd_genl_disconnect nbd_disconnect_and_put nbd_disconnect flush_workqueue(nbd->recv_workq) if (test_and_clear_bit(NBD_RT_HAS_CONFIG_REF, ...)) nbd_config_put -> due to step 1), reference is still not zero 3) nbd_genl_reconfigure() queue recv_work() again; nbd_genl_reconfigure config = nbd_get_config_unlocked(nbd) if (!config) -> succeed if (!test_bit(NBD_RT_BOUND, ...)) -> succeed nbd_reconnect_socket queue_work(nbd->recv_workq, &args->work) 4) step 1) release the reference; 5) Finially, recv_work() will trigger UAF: recv_work nbd_config_put(nbd) -> nbd_config is freed atomic_dec(&config->recv_threads) -> UAF Fix the problem by clearing NBD_RT_BOUND in nbd_genl_disconnect(), so that nbd_genl_reconfigure() will fail. Fixes: b7aa3d39385d ("nbd: add a reconfigure netlink command") Reported-by: syzbot+6b0df248918b92c33e6a@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/675bfb65.050a0220.1a2d0d.0006.GAE@google.com/ Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Link: https://lore.kernel.org/r/20250103092859.3574648-1-yukuai1@huaweicloud.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/nbd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index b852050d8a966..450458267e6e6 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -2180,6 +2180,7 @@ static void nbd_disconnect_and_put(struct nbd_device *nbd) flush_workqueue(nbd->recv_workq); nbd_clear_que(nbd); nbd->task_setup = NULL; + clear_bit(NBD_RT_BOUND, &nbd->config->runtime_flags); mutex_unlock(&nbd->config_lock); if (test_and_clear_bit(NBD_RT_HAS_CONFIG_REF, -- 2.39.5