Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5753172rwd; Sun, 18 Jun 2023 19:00:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6bE15KeNJbp5Mb6xjQ40nXmTKKxjyrQQrUGtItSrn9m0X0qCnV2QzOSMWzORaCwp31d8Ma X-Received: by 2002:a05:622a:652:b0:3fd:db38:fed with SMTP id a18-20020a05622a065200b003fddb380fedmr9403218qtb.19.1687140051976; Sun, 18 Jun 2023 19:00:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687140051; cv=none; d=google.com; s=arc-20160816; b=S4Dji4f5An22EtkplIg2gCmdD25NDySZrDrgz7Kc43oCQgbqabffpWlSzdI72OjaEC fQqfLZRquwWIb3kt8DbT4m3KCkoV6JdGz2UDfG9/rTJ9Yt5kyIfUrRw/3YajT7ZNQXR2 bWdhCizJEWbWkUpdj1X8n/Fey6cH+5SR24MFX64L90P08fCMDtL/n7PtwpU5eEMVqAtk nNHePYQsymrfwnJT9+LCxCpTbnJmqh/74qWw0GwCdhzeK+Drd2ar9TnCDOmnYTgrUhOG B/4n0hv7xwK+LBZAXSJpAsAWQCyfCzaRanq1l88FPpTcdXDsAzyfritDZquevgKefFWs EKNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature:dkim-filter; bh=OleBLvtikVcBHuH8IDNEgE039JVPKNisZ9aLSJ3hOFY=; b=XQkwz8FcTrhGvnZsBfdyfq326iS1LnmGdl25fhunra//w2nFe8azjusJZhaz4QxmQB W6OI7rBfJwvnlQ57EXi43TuYkB0d3c7wvxSFryK04y3BawpbdCMEDs6/4uPKSmzyBafA DN3IHLn5oKUCrmdOf5atzYm4m/xuz2cYFQHZ9+OhcHEl0eDprd3Qh37SE6qb7yFiBmKv qElFc0AsPCPyVTbJlyGGecKQUreMy1z1ABJDa0xE/MlKjjBdo+NOkHQwnDfBWg08No/t K6kMdO+jz3KYNsXvsphgHKjre3osR4PnX+ZRsojUN1ElxBp3dCW5VJIa/+sSr0Xd+jF6 djKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=uUWjEbNO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e9-20020a056a0000c900b0063b1fbbb8c5si19933022pfj.131.2023.06.18.19.00.37; Sun, 18 Jun 2023 19:00:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=uUWjEbNO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229603AbjFSBSJ (ORCPT + 99 others); Sun, 18 Jun 2023 21:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbjFSBSD (ORCPT ); Sun, 18 Jun 2023 21:18:03 -0400 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B44DE1B5 for ; Sun, 18 Jun 2023 18:18:00 -0700 (PDT) Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20230619011756epoutp0194712075fcfb883439fe6bef72ef477c~p6piqkVOZ0218602186epoutp01Q for ; Mon, 19 Jun 2023 01:17:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20230619011756epoutp0194712075fcfb883439fe6bef72ef477c~p6piqkVOZ0218602186epoutp01Q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1687137476; bh=OleBLvtikVcBHuH8IDNEgE039JVPKNisZ9aLSJ3hOFY=; h=From:To:Cc:Subject:Date:References:From; b=uUWjEbNOYrZBVsKR6SvsyRHr+Tzm+SKq6OcbDSQsPwOGN9VbOALLdOVioWInjHwuQ G9tjqiDh0CGLklFvYQs1rB+TKHWbLMTxd9lPbERwvoklQnOVqHx41kBXCIpu4atd8H vgCE+QJ8n3HslVaIpRV5UW/9vHGRWo/69f6HnDgM= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20230619011756epcas5p49e7808cd190e4707f5c73efab94995bb~p6ph6JEVs1902519025epcas5p4a; Mon, 19 Jun 2023 01:17:56 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.174]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4QksMQ2zqcz4x9Q0; Mon, 19 Jun 2023 01:17:54 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id D5.9D.58203.2CCAF846; Mon, 19 Jun 2023 10:17:54 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20230619011354epcas5p32c094e0c9bcd1ec2184c66a5f8be3268~p6mAmrEJA0421404214epcas5p3L; Mon, 19 Jun 2023 01:13:54 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230619011354epsmtrp22f0aa82bf7f77d011a0707e0336d55d1~p6mAl07Yn1345013450epsmtrp2d; Mon, 19 Jun 2023 01:13:54 +0000 (GMT) X-AuditID: b6c32a4b-c55fd7000001e35b-8e-648facc291aa Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id C8.81.64355.1DBAF846; Mon, 19 Jun 2023 10:13:54 +0900 (KST) Received: from ubuntu.. (unknown [109.105.118.54]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230619011352epsmtip1ec693ec61f4bed0d0c8c3f920ba79937~p6l-P13IR2286522865epsmtip1P; Mon, 19 Jun 2023 01:13:52 +0000 (GMT) From: Min Li To: axboe@kernel.dk, willy@infradead.org, hch@lst.de, dlemoal@kernel.org, gregkh@linuxfoundation.org, wsa@kernel.org, vkoul@kernel.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Min Li Subject: [PATCH v4] block: add capacity validation in bdev_add_partition() Date: Mon, 19 Jun 2023 09:12:14 +0000 Message-Id: <20230619091214.31615-1-min15.li@samsung.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFJsWRmVeSWpSXmKPExsWy7bCmhu6hNf0pBi8miVmsvtvPZvFgv71F 8+L1bBY3jr9jtpj7+hKLxcrVR5ks9t7Stri8aw6bxfJVHUwWZyd8YLXYeecEs8XvH0Cxu/vn MlrcWHeVxYHPY/MKLY/LZ0s9Nq3qZPPYP3cNu8fumw1sHn1bVjF6fN4kF8AelW2TkZqYklqk kJqXnJ+SmZduq+QdHO8cb2pmYKhraGlhrqSQl5ibaqvk4hOg65aZA3SvkkJZYk4pUCggsbhY Sd/Opii/tCRVISO/uMRWKbUgJafApECvODG3uDQvXS8vtcTK0MDAyBSoMCE748Wbj4wFT7kr bl/2b2DcxtnFyMkhIWAi8fd9L0sXIxeHkMB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cWHeVxYHPY/MKLY/LZ0s9Nq3qZPPYP3cNu8fumw1sHn1bVjF6fN4kF8AexWWTkpqTWZZa pG+XwJXx4s1HxoKn3BW3L/s3MG7j7GLk5JAQMJH4dGkmG4gtJLCdUeLw5xqIuITE+Xm/2CBs YYmV/56zdzFyAdU8ZZTY1bCVsYuRg4NNQFli21IfkLiIwCRGifsXXrOCNDALJEh0/DjEDmIL C3hJdO77AjaIRUBVYueyw8wgNq+ApcSvE3NYIBbIS+w/eBYqLihxcuYTFog58hLNW2czT2Dk m4UkNQtJagEj0ypG0dSC4tz03OQCQ73ixNzi0rx0veT83E2M4GDXCtrBuGz9X71DjEwcjIcY JTiYlUR4g/b2pQjxpiRWVqUW5ccXleakFh9ilOZgURLnVc7pTBESSE8sSc1OTS1ILYLJMnFw SjUwWamL8195qLNFyv/c4zu6ZnFhppPeWXbPDuGzYd2yetWB55mRJYWz/4iItGouEeVd23hO Y99/A584YeOkg6e0am89uf3qiojo3mUL1X3s3vOGH0phyWi1+H1+DWPP/wnH1rj2zivTm3qK 26TNPXfSys0BfusP+EYmvjnxSHvKXEtex8/B3clvp2fclZgmvrVY4re5sEO18sxfxddXr9J8 +P9TmMnEgn5rsb0HsreX2cckPDtup7jtaW2Suv0h174ct30WPu9n7i1v1P16yGBa/p1Cx2+3 7s9TiZBw8GEJuMX3K2va6l65zxaL1kelTwmetp49wVRP87Gs8wRBpRVFLOse1WXvszWQ9XM5 cmuGEktxRqKhFnNRcSIAMiTDTeUCAAA= X-CMS-MailID: 20230619011354epcas5p32c094e0c9bcd1ec2184c66a5f8be3268 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230619011354epcas5p32c094e0c9bcd1ec2184c66a5f8be3268 References: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the function bdev_add_partition(),there is no check that the start and end sectors exceed the size of the disk before calling add_partition. When we call the block's ioctl interface directly to add a partition, and the capacity of the disk is set to 0 by driver,the command will continue to execute. Signed-off-by: Min Li Reviewed-by: Christoph Hellwig --- Changes from v1: - Check for overflows of the start + length value - Place the capacity check at the beginning of the function. Changes from v2: - Place the assignment on the first line and merge the two lines into one Changes from v3: - Modify the singed name --- block/partitions/core.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/block/partitions/core.c b/block/partitions/core.c index 49e0496ff23c..b511f88bf558 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -436,10 +436,21 @@ static bool partition_overlaps(struct gendisk *disk, sector_t start, int bdev_add_partition(struct gendisk *disk, int partno, sector_t start, sector_t length) { + sector_t capacity = get_capacity(disk), end; struct block_device *part; int ret; mutex_lock(&disk->open_mutex); + if (check_add_overflow(start, length, &end)) { + ret = -EINVAL; + goto out; + } + + if (start >= capacity || end > capacity) { + ret = -EINVAL; + goto out; + } + if (!disk_live(disk)) { ret = -ENXIO; goto out; -- 2.34.1