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 452931DEFD9; Wed, 19 Feb 2025 09:05:49 +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=1739955949; cv=none; b=X4vFMi5RrHkv/oVtYXgnfBT+Cjsh+ivW+3ioBYvcFDsrreaPvjBHTwhUpicjAChLM1y0XWI5kl5cEpMHjB0dFvdf0oAKzoKP8LALXHLHL4YKiaF9gNAnma9KfZBVIp28H598E/clBbV3fzDnlQZf3OnIcRNhWLDcTVteZCKNYGU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739955949; c=relaxed/simple; bh=5ak8iTv6Z4Y+9VMvS/Ju24IXBhSe+IsytpTMtb9oPEM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UkTjY0VemBQTPKbC+IqFJhTWZTiqqTPZzji8UCUULrQ9owmP2zpSZQHHZHa4zxJ90Vs1nM/gsVMPLsxLtayBSuj+vcW0jJ5mfRH5Wyoad55dOthociCPi1EN2pxGBRVoYBm9D1VAFk+dz0mvHgZIFm1wPJx4xIwX1b7zUVFgups= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=j7GgVf3b; 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="j7GgVf3b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C577BC4CEE6; Wed, 19 Feb 2025 09:05:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739955949; bh=5ak8iTv6Z4Y+9VMvS/Ju24IXBhSe+IsytpTMtb9oPEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j7GgVf3bJ1W9LyzKp1rn1m/DIgsRo9xKYy/TR+jlftilkakJOLTqWafXoMdJ4Oy7V NE+dlvhhBxTh8idXs2n7IIUTr3LwLH178G9q9W18FYJ+0tOEgCD4HrcbwKnqpH3JXX +M5K/B3JXjVT8AA++/NQ4CRCOs/5r45+lx4MdUBM= 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.1 006/578] nbd: dont allow reconnect after disconnect Date: Wed, 19 Feb 2025 09:20:10 +0100 Message-ID: <20250219082653.149224285@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219082652.891560343@linuxfoundation.org> References: <20250219082652.891560343@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 1f3cd5de41172..7f6ef0a2b4a5c 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -2133,6 +2133,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