Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3645542pxb; Mon, 24 Jan 2022 14:18:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzraZZJxKGfKuKPFPm9DV1pgV1DFFkIEnwzNkVFOZPcNCFaLTgKs+1C7Mq/Rb5NDxNsdHZf X-Received: by 2002:a17:902:e882:b0:14b:588d:e0ee with SMTP id w2-20020a170902e88200b0014b588de0eemr5166104plg.122.1643062691305; Mon, 24 Jan 2022 14:18:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643062691; cv=none; d=google.com; s=arc-20160816; b=NqQhDtCbOaRgA0vrD6F69gkpAqubmoy6lCkBGc4/MqQuhib7mOjDmvRvm42IYghx/9 aDHCGrFSnEkhQ+4nFO2xgGr2CrmTQIHOJK8QneBQISxSMW6qrb1sDsGg3UPF6QLT8dDg NMLlThAW0nrzwgxlSxGRKG0JdWEbOPRuuHmUulf5dgV9AjxEcJw+Kn8eg06+VHSIYTs8 G+zE9oPSxocemjzyn9aLso7XRp788/4xqRvoqdhcybwHjq0l4VrUFjw44iM5KdIJtvbs KTmLPTWqcMdi1gSlEAeC1gl6v4DEVTnoV79PfT/Cpys0T8VMgnWDDIimlHg6PCK969zh lHSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ySS4TDds8tfBsecJEBf+xoCnmudn3EK89vo7cju7O+0=; b=0TMJymqTrp4kucUWQkVyHaVZXc63uMdakS8nP14BdCpFq+wSc4otzpPKwgv/s37yCA XHoJ8QwFDT/vMxwuBe8MG91PzEgUD3FTubci5MUr2UH9eojXX0fQdo6VT+4rXPngJJ/K gaa1vG44shnlG3MoWilOd4AfCULllZtrR9V10evSCngDS1S0M1AHH+1m8FY8SMwt53iK nyJxEjddUeGW6jG6zcQzyx9hOHp0x57O2nkIGTRucLyYWft5Je2QY9yub1pIXtXDO7Uj 7UmdNNf7pgWPeMAIsorKQybAu9jhNQbdUNjJps49OTcDtD4cJUpO8L4e3xNosXFeenre vT0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=N4X6EQXZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v14si13278029pgk.382.2022.01.24.14.17.52; Mon, 24 Jan 2022 14:18:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=N4X6EQXZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1581700AbiAXWML (ORCPT + 99 others); Mon, 24 Jan 2022 17:12:11 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:47554 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1452996AbiAXV1f (ORCPT ); Mon, 24 Jan 2022 16:27:35 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C1F60614C9; Mon, 24 Jan 2022 21:27:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4271C340E4; Mon, 24 Jan 2022 21:27:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059654; bh=UND6nXt7n9+NZjYujgAg5y31VQ9oBzFhCxZj4nu5wWI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N4X6EQXZ0QFlxeNo3KxFYdrpLTVICAO7xlufT3AQ0lqIWKlit9/5Zu6yytPWiTGUO 0BOrz7lG6b6en7S7WzqQACHmZG4CIL0iIWfvplZKfsz2znRFf2jANvhdRpV7jFFQB/ KBLZmuY3IUMQU9p8jWoLw3BIJR8WYJo9c10Q1k78= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, wangyangbo , Tetsuo Handa , Christoph Hellwig , Jens Axboe , Sasha Levin Subject: [PATCH 5.16 0687/1039] block: check minor range in device_add_disk() Date: Mon, 24 Jan 2022 19:41:16 +0100 Message-Id: <20220124184148.446317970@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tetsuo Handa [ Upstream commit e338924bd05d6e71574bc13e310c89e10e49a8a5 ] ioctl(fd, LOOP_CTL_ADD, 1048576) causes sysfs: cannot create duplicate filename '/dev/block/7:0' message because such request is treated as if ioctl(fd, LOOP_CTL_ADD, 0) due to MINORMASK == 1048575. Verify that all minor numbers for that device fit in the minor range. Reported-by: wangyangbo Signed-off-by: Tetsuo Handa Reviewed-by: Christoph Hellwig Link: https://lore.kernel.org/r/b1b19379-23ee-5379-0eb5-94bf5f79f1b4@i-love.sakura.ne.jp Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/genhd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index 596e43764846b..5308e0920fa6f 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -425,6 +425,8 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, DISK_MAX_PARTS); disk->minors = DISK_MAX_PARTS; } + if (disk->first_minor + disk->minors > MINORMASK + 1) + return -EINVAL; } else { if (WARN_ON(disk->minors)) return -EINVAL; -- 2.34.1