Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3390949pxb; Mon, 17 Jan 2022 19:25:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwgT6JUqV5MHxDH+tO/7KyWl7GCqXMmcHivl05zAcgkC36Dm6y+S1tp0TlB/wc9Y3NNYZxa X-Received: by 2002:a17:903:18d:b0:14a:9cfe:b49d with SMTP id z13-20020a170903018d00b0014a9cfeb49dmr14257766plg.130.1642476247383; Mon, 17 Jan 2022 19:24:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642476247; cv=none; d=google.com; s=arc-20160816; b=Qy1C1PzkD3QK2QSp0Ugm+D6xK9fcMPygGy8XwlzqggaJQ/2ZzrBd7sk2aDO7Lvv8+V 4sn96ehckwLdof6ivHWtz0Er7jRQxBvmFXNnpfbYETCyJzAtCbPplqU4BjDU83EYLgIi 2Q3K01QBFWUpOhlHnFpEwSWYXCrZ9hE6PRR4dXEDLzxHDitiH18oo0rgM/AargH/B/o4 SQT1wEP2R5fokVdMuI2ZVcowq+cD3PRJfRra6H3bJCSWmXARaCLA3E1T0WPWhK1c0UYi hDTCJ9eWLv8DGzCbdJrRAUMBrbPlXOKqEJllh0SUoR15EQL/hPZkPis/dlFYEEKg91d2 aRLA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3kddQR/0CQP2T8iu8N9PSdXgp+yf5InBgwb4OTy+MSs=; b=GWK5LP/MsBL8ZkZTfWLhUU0bKQAMlPs4oq9NyzYuYFmBw+RgOjj72HVUJHto8LWXJI 328/oCCwUT+UA0PMfDVXY9t/9/MBstwiYqvIC+lVBjh5m4EmavXGgwCCzkO6di95syZe nygup1IJdkHVkarTo2+Sxqwa/0/DX5cJZjdYKhvaY7Sy7gwvK5LN8slOx9z/SKKETnlV QZw3bConUMD6VRJ0MXClCC/TRIvrRTdPokJKjy4J0Ft60i/v1b5QXKqnT0B5EO2JaFd0 3SsClG29gorqXZp4DwTU2lAtR6jBoAMTB9B5pdkpZ0sWhVgTz9ndil5BBAl5q1yqTOTG OETg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qn90vsLW; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u15si15941471pgh.731.2022.01.17.19.23.55; Mon, 17 Jan 2022 19:24:07 -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=@kernel.org header.s=k20201202 header.b=Qn90vsLW; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346169AbiARCf3 (ORCPT + 99 others); Mon, 17 Jan 2022 21:35:29 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:46296 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244864AbiARC3D (ORCPT ); Mon, 17 Jan 2022 21:29:03 -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 64E9A604EF; Tue, 18 Jan 2022 02:29:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1C54C36AE3; Tue, 18 Jan 2022 02:29:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642472942; bh=PpXlT6/YLztJB8/hQ39X2TcYRGZB0gx3+6C/udNnkDk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qn90vsLWYBUxzyclpHUEONTI1AZGTJLY4w0hGqChasSEf3fz36vOyoHJ3tdvXcR+d j4ZrswD2xarRpXxKMFOhyIPmH2IAdVnDn+NLBhn95SqG8r5ahROTJD44Kxbyl/7tCm axc7fyzdvJbs2SwQRe9m+5xGi68Ef+JcdllaTVjexBhzN/O9QqVZul4plHluCFkNx2 ZkM2AnpehhViCDU+ZVfTiiUcznl+wPcJGtjfbFvR1+BkJcGY3jLYjPFjeZM/1HsMgu +S4YbVjfhtONsywllJY+4ybvYS4z5mKXD+Z8Zux3z8A90bBg7/bI6/x2XrZeSw4hQy JcdTC5Evxwogg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tetsuo Handa , wangyangbo , Tetsuo Handa , Christoph Hellwig , Jens Axboe , Sasha Levin , linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 5.16 170/217] block: check minor range in device_add_disk() Date: Mon, 17 Jan 2022 21:18:53 -0500 Message-Id: <20220118021940.1942199-170-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220118021940.1942199-1-sashal@kernel.org> References: <20220118021940.1942199-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 30362aeacac4b..b0847f7a90c50 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