Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3677210pxb; Mon, 24 Jan 2022 15:07:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMlQvmuMnofzN2MP7J655qSfAiLXamN3rUfqDA218vElSoCCyWFB0TvysKkCS03U6N6CZr X-Received: by 2002:a63:451b:: with SMTP id s27mr13360303pga.39.1643065626251; Mon, 24 Jan 2022 15:07:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643065626; cv=none; d=google.com; s=arc-20160816; b=WwJ6xEqBQ1pMrXJNMBc803G/rkmFmQuAP/igPYlQ7yyJ4//Nsv9qkD3NEbk1PEjQyS ljUYvdOFsRfQyyBKmhM4zoHptP4O/nYXOeIzsswbvUA98l40HwW9yr9Ut0ZVJ0T2VgVW aiHkLM6UKYA5ptS+4mLxVU+DNevEb5UhTD9ObVkM/BgNKKck4EF7JsKJiW26TY6RQq2I gzyY11S2j1YZc6RG/6MX0+1mrhBgP6WJ6ymKzPa4Q1IaaMiKuOOIqBsQRhBb6mwlRdBa gcg5NkDzWp7amg4EDx+AaKO4Llv3aUf2xOQD6BiX6/9ykpEfx/8IJr4cbFcK1ECA9dZL ALfA== 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=MIWtRUCxfSR2VFQbb1AbmMlLqe5PVS0hrfWLvz3bdQA=; b=Z5s/NdGJgbEPKMkCm9031SKur1Zc80XtpbcG1HGppR0Yhr8wWECy/8yH9ua2E74cg0 lzy0o4pbHLhAGG6Jdh8WE2DHh32wbqBdN0SU7nM8RJn1hAQK7yQlptrd1ibW8Ajl+u9V RcFshrtCkcoYbsuhLfkL9TlS8s9Dy23mRhfQ5xxuRouZtzwmVp3yyi/3f2fGk+OrzdE3 1sCBmgqB7D0yROKBH2hijDuqXTtGWTQlYAbLWo4EhZBNUeaTr2G4QU52pvVpKvfzFomv 1J9b5+x8JaH48Ie8Wo8/6d1QtDmWAfdYpsmbcR01OgWNE0Oyq40DYSWboj6v/buRS376 g/RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tE77bxeB; 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 e3si1412130plh.181.2022.01.24.15.06.54; Mon, 24 Jan 2022 15:07:06 -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=tE77bxeB; 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 S1842081AbiAXXAq (ORCPT + 99 others); Mon, 24 Jan 2022 18:00:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1577801AbiAXWBF (ORCPT ); Mon, 24 Jan 2022 17:01:05 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6B2AC02B841; Mon, 24 Jan 2022 12:40:28 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 7C418B80FA3; Mon, 24 Jan 2022 20:40:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 924E2C340E5; Mon, 24 Jan 2022 20:40:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056827; bh=DtB2ewSAb4R06N3RmFKmPjCaSnxLF0dCbGuY6M11Z6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tE77bxeB2eS73hgY8Lffp7RTY/+QVwSBF6h5r/c6eHFZVhD+SY3BzA8UIJ9W2z4tB boW7W8xKcw95VfNmFCRkOkiGanEDRcVV54OAK/Ko6me+pK0XZYvzjUZr/GmUY+H6c+ TgbXNB1VoKH8B6SxNa9FkJMubS/qBurZGpzF+TOY= 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.15 581/846] block: check minor range in device_add_disk() Date: Mon, 24 Jan 2022 19:41:38 +0100 Message-Id: <20220124184121.096162685@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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 22f899615801c..de789d1a1e3d2 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -420,6 +420,8 @@ int 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