From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02F2CEB64D9 for ; Sun, 2 Jul 2023 19:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231889AbjGBTmw (ORCPT ); Sun, 2 Jul 2023 15:42:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231766AbjGBTmT (ORCPT ); Sun, 2 Jul 2023 15:42:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7DB11BE2; Sun, 2 Jul 2023 12:41:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 52D8B60C96; Sun, 2 Jul 2023 19:40:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA564C433C8; Sun, 2 Jul 2023 19:40:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688326838; bh=sB3H+3BFpVqM9IJlZFM+G0+XNhcWle9yWb7Z753Yb9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f0o2422Pg5y1c2Ph+AUVAU79jhzptSmugguPCq1xizjk3ebp9WYnmS2QpAAYUMYyH It1E4iZArsA9o2/DpKZ1yCn3DmvdrlUc0kjJmIYtGQXgmUXaueoO8sTZqpD3uyP+IM Svx7xuVHrzJskX8nbIIJFZOJtcLlWzIPW2hjlKkk3yF6ASOT22UMr8Ha9u+lT/3Slk Uh7KcIKVyt6OjECOXyFC6o4wg7CN8vi9zqgsxt3WTs9yStRvKZ6TVNPCKALVgAaUyZ IeRelJEjLjTh2LUusGvCoMPppZ2SLzF1Fo5W3ZAq8kdo099W5oTU56Jo95GP6Si/sy +StFaMbKB9N0w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhong Jinghua , Christoph Hellwig , Jens Axboe , Sasha Levin , josef@toxicpanda.com, linux-block@vger.kernel.org, nbd@other.debian.org Subject: [PATCH AUTOSEL 6.4 06/15] nbd: Add the maximum limit of allocated index in nbd_dev_add Date: Sun, 2 Jul 2023 15:40:11 -0400 Message-Id: <20230702194020.1776895-6-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230702194020.1776895-1-sashal@kernel.org> References: <20230702194020.1776895-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.4.1 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhong Jinghua [ Upstream commit f12bc113ce904777fd6ca003b473b427782b3dde ] If the index allocated by idr_alloc greater than MINORMASK >> part_shift, the device number will overflow, resulting in failure to create a block device. Fix it by imiting the size of the max allocation. Signed-off-by: Zhong Jinghua Reviewed-by: Christoph Hellwig Link: https://lore.kernel.org/r/20230605122159.2134384-1-zhongjinghua@huaweicloud.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/nbd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 65ecde3e2a5be..6457a094abcc1 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1776,7 +1776,8 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs) if (err == -ENOSPC) err = -EEXIST; } else { - err = idr_alloc(&nbd_index_idr, nbd, 0, 0, GFP_KERNEL); + err = idr_alloc(&nbd_index_idr, nbd, 0, + (MINORMASK >> part_shift) + 1, GFP_KERNEL); if (err >= 0) index = err; } -- 2.39.2