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 3B9C3C001DF for ; Tue, 25 Jul 2023 11:49:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233183AbjGYLt1 (ORCPT ); Tue, 25 Jul 2023 07:49:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233287AbjGYLtR (ORCPT ); Tue, 25 Jul 2023 07:49:17 -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 2097F212A for ; Tue, 25 Jul 2023 04:49:04 -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 9FF7F616BE for ; Tue, 25 Jul 2023 11:49:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB8A9C433C9; Tue, 25 Jul 2023 11:49:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1690285743; bh=Jd9SviMyTJhfuFyAzDT+aOfbtj4KgUV9XUqZfotGHn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ERGKskpQYfKpS++7Jl21OAu+NMQgZZcODKcBT8BHUPJ/WV4/LXtvNQ3g8eYcM6pQw ZTMnuBcYT8EjBFFrBzE3Q7QSIZ3C46zOxI5pC8biG+bAI49y5bSLtreiLr2Maf9Ovw 6t6iuZO3JduMaPxnKycfltkJkwcvhhuOK8p8dAJ4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhong Jinghua , Christoph Hellwig , Jens Axboe , Sasha Levin Subject: [PATCH 5.4 285/313] nbd: Add the maximum limit of allocated index in nbd_dev_add Date: Tue, 25 Jul 2023 12:47:18 +0200 Message-ID: <20230725104533.406667873@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725104521.167250627@linuxfoundation.org> References: <20230725104521.167250627@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@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 218aa7e419700..37994a7a1b6f4 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1708,7 +1708,8 @@ static int nbd_dev_add(int index) 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